Skip to content

Commit ae4b03c

Browse files
Allow datafiles which meet JSON schema validation (#43)
1 parent 3b99056 commit ae4b03c

File tree

9 files changed

+164
-410
lines changed

9 files changed

+164
-410
lines changed

optimizely/entities.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016, Optimizely
1+
# Copyright 2016-2017, Optimizely
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -19,15 +19,14 @@ def __eq__(self, other):
1919

2020
class Attribute(BaseEntity):
2121

22-
def __init__(self, id, key, segmentId=None):
22+
def __init__(self, id, key, **kwargs):
2323
self.id = id
2424
self.key = key
25-
self.segmentId = segmentId
2625

2726

2827
class Audience(BaseEntity):
2928

30-
def __init__(self, id, name, conditions, conditionStructure=None, conditionList=None):
29+
def __init__(self, id, name, conditions, conditionStructure=None, conditionList=None, **kwargs):
3130
self.id = id
3231
self.name = name
3332
self.conditions = conditions
@@ -37,7 +36,7 @@ def __init__(self, id, name, conditions, conditionStructure=None, conditionList=
3736

3837
class Event(BaseEntity):
3938

40-
def __init__(self, id, key, experimentIds):
39+
def __init__(self, id, key, experimentIds, **kwargs):
4140
self.id = id
4241
self.key = key
4342
self.experimentIds = experimentIds
@@ -46,7 +45,7 @@ def __init__(self, id, key, experimentIds):
4645
class Experiment(BaseEntity):
4746

4847
def __init__(self, id, key, status, audienceIds, variations, forcedVariations,
49-
trafficAllocation, layerId=None, groupId=None, groupPolicy=None, percentageIncluded=None):
48+
trafficAllocation, layerId, groupId=None, groupPolicy=None, **kwargs):
5049
self.id = id
5150
self.key = key
5251
self.status = status
@@ -57,12 +56,11 @@ def __init__(self, id, key, status, audienceIds, variations, forcedVariations,
5756
self.layerId = layerId
5857
self.groupId = groupId
5958
self.groupPolicy = groupPolicy
60-
self.percentageIncluded = percentageIncluded
6159

6260

6361
class Group(BaseEntity):
6462

65-
def __init__(self, id, policy, experiments, trafficAllocation):
63+
def __init__(self, id, policy, experiments, trafficAllocation, **kwargs):
6664
self.id = id
6765
self.policy = policy
6866
self.experiments = experiments
@@ -71,6 +69,6 @@ def __init__(self, id, policy, experiments, trafficAllocation):
7169

7270
class Variation(BaseEntity):
7371

74-
def __init__(self, id, key):
72+
def __init__(self, id, key, **kwargs):
7573
self.id = id
7674
self.key = key

optimizely/event_builder.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
from abc import abstractmethod
1616
from abc import abstractproperty
1717

18-
from . import exceptions
19-
from . import project_config
2018
from . import version
21-
from .helpers import enums
2219
from .helpers import event_tag_utils
2320

2421

@@ -281,24 +278,3 @@ def create_conversion_event(self, event_key, user_id, attributes, event_tags, va
281278
self.params,
282279
http_verb=self.HTTP_VERB,
283280
headers=self.HTTP_HEADERS)
284-
285-
286-
def get_event_builder(config, bucketer):
287-
""" Helper method to get appropriate EventBuilder class based on the version of the datafile.
288-
289-
Args:
290-
config: Object representing the project's configuration.
291-
bucketer: Object representing the bucketer.
292-
293-
Returns:
294-
Event builder based on the version of the datafile.
295-
296-
Raises:
297-
Exception if provided datafile has unsupported version.
298-
"""
299-
300-
config_version = config.get_version()
301-
if config_version == project_config.V2_CONFIG_VERSION:
302-
return EventBuilder(config, bucketer)
303-
304-
raise exceptions.InvalidInputException(enums.Errors.UNSUPPORTED_DATAFILE_VERSION)

optimizely/helpers/constants.py

Lines changed: 2 additions & 281 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016, Optimizely
1+
# Copyright 2016-2017, Optimizely
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -11,286 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
JSON_SCHEMA_V1 = {
15-
"$schema": "http://json-schema.org/draft-04/schema#",
16-
"type": "object",
17-
"properties": {
18-
"projectId": {
19-
"type": "string"
20-
},
21-
"accountId": {
22-
"type": "string"
23-
},
24-
"groups": {
25-
"type": "array",
26-
"items": {
27-
"type": "object",
28-
"properties": {
29-
"id": {
30-
"type": "string"
31-
},
32-
"policy": {
33-
"type": "string"
34-
},
35-
"trafficAllocation": {
36-
"type": "array",
37-
"items": {
38-
"type": "object",
39-
"properties": {
40-
"entityId": {
41-
"type": "string"
42-
},
43-
"endOfRange": {
44-
"type": "integer"
45-
}
46-
},
47-
"required": [
48-
"entityId",
49-
"endOfRange"
50-
]
51-
}
52-
},
53-
"experiments": {
54-
"type": "array",
55-
"items": {
56-
"type": "object",
57-
"properties": {
58-
"id": {
59-
"type": "string"
60-
},
61-
"key": {
62-
"type": "string"
63-
},
64-
"status": {
65-
"type": "string"
66-
},
67-
"variations": {
68-
"type": "array",
69-
"items": {
70-
"type": "object",
71-
"properties": {
72-
"id": {
73-
"type": "string"
74-
},
75-
"key": {
76-
"type": "string"
77-
}
78-
},
79-
"required": [
80-
"id",
81-
"key"
82-
]
83-
}
84-
},
85-
"trafficAllocation": {
86-
"type": "array",
87-
"items": {
88-
"type": "object",
89-
"properties": {
90-
"entityId": {
91-
"type": "string"
92-
},
93-
"endOfRange": {
94-
"type": "integer"
95-
}
96-
},
97-
"required": [
98-
"entityId",
99-
"endOfRange"
100-
]
101-
}
102-
},
103-
"audienceIds": {
104-
"type": "array",
105-
"items": {
106-
"type": "string"
107-
}
108-
},
109-
"forcedVariations": {
110-
"type": "object"
111-
}
112-
},
113-
"required": [
114-
"id",
115-
"key",
116-
"status",
117-
"variations",
118-
"trafficAllocation",
119-
"audienceIds",
120-
"forcedVariations"
121-
]
122-
}
123-
}
124-
},
125-
"required": [
126-
"id",
127-
"policy",
128-
"trafficAllocation",
129-
"experiments"
130-
]
131-
},
132-
},
133-
"experiments": {
134-
"type": "array",
135-
"items": {
136-
"type": "object",
137-
"properties": {
138-
"id": {
139-
"type": "string"
140-
},
141-
"key": {
142-
"type": "string"
143-
},
144-
"status": {
145-
"type": "string"
146-
},
147-
"variations": {
148-
"type": "array",
149-
"items": {
150-
"type": "object",
151-
"properties": {
152-
"id": {
153-
"type": "string"
154-
},
155-
"key": {
156-
"type": "string"
157-
}
158-
},
159-
"required": [
160-
"id",
161-
"key"
162-
]
163-
}
164-
},
165-
"trafficAllocation": {
166-
"type": "array",
167-
"items": {
168-
"type": "object",
169-
"properties": {
170-
"entityId": {
171-
"type": "string"
172-
},
173-
"endOfRange": {
174-
"type": "integer"
175-
}
176-
},
177-
"required": [
178-
"entityId",
179-
"endOfRange"
180-
]
181-
}
182-
},
183-
"audienceIds": {
184-
"type": "array",
185-
"items": {
186-
"type": "string"
187-
}
188-
},
189-
"forcedVariations": {
190-
"type": "object"
191-
}
192-
},
193-
"required": [
194-
"id",
195-
"key",
196-
"status",
197-
"variations",
198-
"trafficAllocation",
199-
"audienceIds",
200-
"forcedVariations"
201-
]
202-
}
203-
},
204-
"events": {
205-
"type": "array",
206-
"items": {
207-
"type": "object",
208-
"properties": {
209-
"key": {
210-
"type": "string"
211-
},
212-
"experimentIds": {
213-
"type": "array",
214-
"items": {
215-
"type": "string"
216-
}
217-
},
218-
"id": {
219-
"type": "string"
220-
}
221-
},
222-
"required": [
223-
"key",
224-
"experimentIds",
225-
"id"
226-
]
227-
}
228-
},
229-
"audiences": {
230-
"type": "array",
231-
"items": {
232-
"type": "object",
233-
"properties": {
234-
"id": {
235-
"type": "string"
236-
},
237-
"name": {
238-
"type": "string"
239-
},
240-
"conditions": {
241-
"type": "string"
242-
}
243-
},
244-
"required": [
245-
"id",
246-
"name",
247-
"conditions"
248-
]
249-
}
250-
},
251-
"dimensions": {
252-
"type": "array",
253-
"items": {
254-
"type": "object",
255-
"properties": {
256-
"id": {
257-
"type": "string"
258-
},
259-
"key": {
260-
"type": "string"
261-
},
262-
"segmentId": {
263-
"type": "string"
264-
}
265-
},
266-
"required": [
267-
"id",
268-
"key",
269-
"segmentId",
270-
]
271-
}
272-
},
273-
"version": {
274-
"type": "string"
275-
},
276-
"revision": {
277-
"type": "string"
278-
},
279-
},
280-
"required": [
281-
"projectId",
282-
"accountId",
283-
"groups",
284-
"experiments",
285-
"events",
286-
"audiences",
287-
"dimensions",
288-
"version",
289-
"revision",
290-
]
291-
}
292-
293-
JSON_SCHEMA_V2 = {
14+
JSON_SCHEMA = {
29415
"$schema": "http://json-schema.org/draft-04/schema#",
29516
"type": "object",
29617
"properties": {

0 commit comments

Comments
 (0)