Skip to content

Commit ce9b250

Browse files
committed
re-add organizationId... some refactoring
1 parent 6298af5 commit ce9b250

12 files changed

Lines changed: 101 additions & 124 deletions

identify/main/identify_sync_client.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def delete_attribute_from_schema(self, traffic_type_id, attribute_id):
9292
'''
9393
return Attribute.delete(self._client, attribute_id, traffic_type_id)
9494

95-
def add_identities(self, traffic_type_id, environment_id, identities):
95+
def add_identities(self, traffic_type_id, environment_id, identities,
96+
organization_id=None):
9697
'''
9798
Create Identities for a specific traffic type and environment.
9899
@@ -116,9 +117,11 @@ def add_identities(self, traffic_type_id, environment_id, identities):
116117
traffic_type_id,
117118
environment_id,
118119
identities,
120+
organization_id
119121
)
120122

121-
def add_identity(self, traffic_type_id, environment_id, key, values):
123+
def add_identity(self, traffic_type_id, environment_id, key, values,
124+
organization_id=None):
122125
'''
123126
Create a new Identity.
124127
@@ -137,10 +140,12 @@ def add_identity(self, traffic_type_id, environment_id, key, values):
137140
key,
138141
traffic_type_id,
139142
environment_id,
140-
values
143+
values,
144+
organization_id
141145
)
142146

143-
def update_identity(self, traffic_type_id, environment_id, key, values):
147+
def update_identity(self, traffic_type_id, environment_id, key, values,
148+
organization_id=None):
144149
'''
145150
Update an Identity.
146151
@@ -159,10 +164,12 @@ def update_identity(self, traffic_type_id, environment_id, key, values):
159164
key,
160165
traffic_type_id,
161166
environment_id,
162-
values
167+
values,
168+
organization_id
163169
)
164170

165-
def patch_identity(self, traffic_type_id, environment_id, key, values):
171+
def patch_identity(self, traffic_type_id, environment_id, key, values,
172+
organization_id=None):
166173
'''
167174
Patch an Identity.
168175
@@ -181,7 +188,8 @@ def patch_identity(self, traffic_type_id, environment_id, key, values):
181188
key,
182189
traffic_type_id,
183190
environment_id,
184-
values
191+
values,
192+
organization_id
185193
)
186194

187195
def delete_attributes_from_key(self, traffic_type_id, environment_id, key):

identify/resources/attribute.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ def is_searchable(self):
9090
return self._is_searchable
9191

9292
@classmethod
93-
def _build_single_from_collection_response(cls, client, response):
93+
def from_dict(cls, client, response):
9494
'''
9595
'''
9696
return Attribute(
9797
client,
98-
response['id'],
99-
response['trafficTypeId'],
100-
response['displayName'],
101-
response['description'],
102-
response['dataType'],
98+
response.get('id'),
99+
response.get('trafficTypeId'),
100+
response.get('displayName'),
101+
response.get('description'),
102+
response.get('dataType'),
103103
response.get('isSearchable')
104104
)
105105

@@ -123,15 +123,7 @@ def create(cls, client, id, traffic_type_id, display_name, description,
123123
trafficTypeId=traffic_type_id
124124
)
125125

126-
return Attribute(
127-
client,
128-
response['id'],
129-
response['trafficTypeId'],
130-
response['displayName'],
131-
response['description'],
132-
response['dataType'],
133-
response.get('isSearchable')
134-
)
126+
return Attribute.from_dict(client, response)
135127

136128
except HTTPResponseError as e:
137129
LOGGER.error('Call to Identify API failed. Attribute not created.')

identify/resources/base_resource.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,14 @@ def _process_all_response(cls, client, response):
4747
:rtype: list
4848
'''
4949
LOGGER.debug("Proccesing {n} items".format(n=len(response)))
50-
return [
51-
cls._build_single_from_collection_response(client, item)
52-
for item in response
53-
]
50+
return [cls.from_dict(client, item) for item in response]
5451

5552
@classabstract
56-
def _build_single_from_collection_response(cls, client, response):
53+
def from_dict(client, response):
5754
'''
58-
Abstract Class method to construct a resource instance from a single
59-
item extracted from a colleciton.
6055
'''
6156
pass
6257

63-
@classmethod
64-
def retrieve_single(cls, client, **kwargs):
65-
'''
66-
NOT USED. DECIDE IF NECESSARY
67-
'''
68-
try:
69-
response = client.get(cls._endpoint['single_item'], **kwargs)
70-
return response
71-
except:
72-
import traceback
73-
traceback.print_exc()
74-
7558
@classmethod
7659
def retrieve_all(cls, client, **kwargs):
7760
'''

identify/resources/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def name(self):
4242
return self._name
4343

4444
@classmethod
45-
def _build_single_from_collection_response(cls, client, response):
45+
def from_dict(cls, client, response):
4646
'''
4747
'''
4848
return Environment(

identify/resources/identity.py

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,19 @@ class Identity(BaseResource):
7777
'trafficTypeId': 'string',
7878
'environmentId': 'string',
7979
'values': 'object',
80+
'organizationId': 'string',
8081
}
8182

8283
def __init__(self, client, key, traffic_type_id, environment_id,
83-
values=None):
84+
values=None, organization_id=None):
8485
'''
8586
'''
8687
BaseResource.__init__(self, client, key)
8788
self._traffic_type_id = traffic_type_id
8889
self._key = key
8990
self._environment_id = environment_id
9091
self._values = values
92+
self._organization_id = organization_id
9193

9294
@property
9395
def key(self):
@@ -105,14 +107,25 @@ def environment_id(self):
105107
def values(self):
106108
return self._values
107109

110+
def organization_id(self):
111+
return self._organization_id
112+
108113
@classmethod
109-
def _build_single_from_collection_response(cls, client, response):
114+
def from_dict(cls, client, response):
110115
'''
111116
'''
112-
raise MethodNotApplicable()
117+
return Identity(
118+
client,
119+
response.get('key'),
120+
response.get('trafficTypeId'),
121+
response.get('environmentId'),
122+
response.get('values'),
123+
response.get('organizationId')
124+
)
113125

114126
@classmethod
115-
def create(cls, client, key, traffic_type_id, environment_id, values):
127+
def create(cls, client, key, traffic_type_id, environment_id, values,
128+
organization_id=None):
116129
'''
117130
'''
118131
try:
@@ -122,7 +135,8 @@ def create(cls, client, key, traffic_type_id, environment_id, values):
122135
'key': key,
123136
'trafficTypeId': traffic_type_id,
124137
'environmentId': environment_id,
125-
'values': values
138+
'values': values,
139+
'organizationId': organization_id
126140
},
127141
key=key,
128142
trafficTypeId=traffic_type_id,
@@ -135,16 +149,11 @@ def create(cls, client, key, traffic_type_id, environment_id, values):
135149
LOGGER.debug(e)
136150
raise UnknownIdentifyClientError()
137151

138-
return Identity(
139-
client,
140-
response['key'],
141-
response['trafficTypeId'],
142-
response['environmentId'],
143-
response['values'],
144-
)
152+
return Identity.from_dict(client, response)
145153

146154
@classmethod
147-
def create_many(cls, client, traffic_type_id, environment_id, identities):
155+
def create_many(cls, client, traffic_type_id, environment_id, identities,
156+
organization_id=None):
148157
'''
149158
entities: { key: { attr_id: value, ...} }
150159
'''
@@ -157,7 +166,8 @@ def create_many(cls, client, traffic_type_id, environment_id, identities):
157166
'key': key,
158167
'trafficTypeId': traffic_type_id,
159168
'environmentId': environment_id,
160-
'values': identities[key]
169+
'values': identities[key],
170+
'organizationId': organization_id,
161171
}
162172
for key in identities.keys()
163173
],
@@ -166,23 +176,14 @@ def create_many(cls, client, traffic_type_id, environment_id, identities):
166176
)
167177

168178
successful = [
169-
Identity(
170-
client, i['key'], i['trafficTypeId'],
171-
i['environmentId'], i['values']
172-
) for i in response['objects']
179+
Identity.from_dict(client, i) for i in response['objects']
173180
]
174181

175182
failed = [
176183
{
177-
'object': Identity(
178-
client,
179-
i['object']['key'],
180-
i['object']['trafficTypeId'],
181-
i['object']['environmentId'],
182-
i['object']['values'],
183-
),
184+
'object': Identity.from_dict(client, i['object']),
184185
'status': i['status'],
185-
'message': i['message']
186+
'message': i['message'],
186187
}
187188
for i in response['failed']
188189
]
@@ -197,7 +198,8 @@ def create_many(cls, client, traffic_type_id, environment_id, identities):
197198
raise UnknownIdentifyClientError()
198199

199200
@classmethod
200-
def update(cls, client, key, traffic_type_id, environment_id, values):
201+
def update(cls, client, key, traffic_type_id, environment_id, values,
202+
organization_id=None):
201203
'''
202204
'''
203205
try:
@@ -207,7 +209,8 @@ def update(cls, client, key, traffic_type_id, environment_id, values):
207209
'key': key,
208210
'trafficTypeId': traffic_type_id,
209211
'environmentId': environment_id,
210-
'values': values
212+
'values': values,
213+
'organizationId': organization_id,
211214
},
212215
key=key,
213216
trafficTypeId=traffic_type_id,
@@ -220,16 +223,11 @@ def update(cls, client, key, traffic_type_id, environment_id, values):
220223
LOGGER.debug(e)
221224
raise UnknownIdentifyClientError()
222225

223-
return Identity(
224-
client,
225-
response['key'],
226-
response['trafficTypeId'],
227-
response['environmentId'],
228-
response['values'],
229-
)
226+
return Identity.from_dict(client, response)
230227

231228
@classmethod
232-
def patch(cls, client, key, traffic_type_id, environment_id, values):
229+
def patch(cls, client, key, traffic_type_id, environment_id, values,
230+
organization_id=None):
233231
'''
234232
'''
235233
try:
@@ -239,7 +237,8 @@ def patch(cls, client, key, traffic_type_id, environment_id, values):
239237
'key': key,
240238
'trafficTypeId': traffic_type_id,
241239
'environmentId': environment_id,
242-
'values': values
240+
'values': values,
241+
'organizationId': organization_id,
243242
},
244243
key=key,
245244
trafficTypeId=traffic_type_id,
@@ -252,13 +251,7 @@ def patch(cls, client, key, traffic_type_id, environment_id, values):
252251
LOGGER.debug(e)
253252
raise UnknownIdentifyClientError()
254253

255-
return Identity(
256-
client,
257-
response['key'],
258-
response['trafficTypeId'],
259-
response['environmentId'],
260-
response['values'],
261-
)
254+
return Identity.from_dict(client, response)
262255

263256
@classmethod
264257
def delete_all_attributes(cls, client, traffic_type_id, environment_id,
@@ -284,7 +277,7 @@ def update_this(self, values):
284277
'''
285278
return Identity.update(
286279
self._client, self.key, self.traffic_type_id, self.environment_id,
287-
values
280+
values, self._organization_id
288281
)
289282

290283
def patch_this(self, values):

identify/resources/traffic_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def add_attribute(self, id, display_attribute_id, description, data_type):
6767
)
6868

6969
@classmethod
70-
def _build_single_from_collection_response(cls, client, response):
70+
def from_dict(cls, client, response):
7171
'''
7272
'''
7373
return TrafficType(

identify/tests/e2e/e2etests.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ def test_identity_endpoints(self):
127127
'key': i1.key,
128128
'environmentId': i1.environment_id,
129129
'trafficTypeId': i1.traffic_type_id,
130-
'values': i1.values
130+
'values': i1.values,
131+
'organizationId': i1.organization_id,
131132
} == i1.to_dict()
132133

133134
i2 = c.update_identity('1', '1', 'keycita', {'a1': 'qwe2'})
@@ -136,7 +137,8 @@ def test_identity_endpoints(self):
136137
'key': i2.key,
137138
'environmentId': i2.environment_id,
138139
'trafficTypeId': i2.traffic_type_id,
139-
'values': i2.values
140+
'values': i2.values,
141+
'organizationId': i2.organization_id,
140142
} == i2.to_dict()
141143

142144
i3 = c.patch_identity('1', '1', 'keycita', {'a1': 'qwe3'})
@@ -145,7 +147,8 @@ def test_identity_endpoints(self):
145147
'key': i3.key,
146148
'environmentId': i3.environment_id,
147149
'trafficTypeId': i3.traffic_type_id,
148-
'values': i3.values
150+
'values': i3.values,
151+
'organizationId': i3.organization_id,
149152
} == i3.to_dict()
150153

151154
res_add_identities = c.add_identities(
@@ -154,7 +157,8 @@ def test_identity_endpoints(self):
154157
{
155158
'key1': {'a1': 'a', 'a2': 'b'},
156159
'key2': {'b1': 'c', 'c2': 'c'},
157-
}
160+
},
161+
'oo1'
158162
)
159163
assert isinstance(res_add_identities, tuple)
160164
objs, failed = res_add_identities
@@ -166,6 +170,7 @@ def test_identity_endpoints(self):
166170
'trafficTypeId': i.traffic_type_id,
167171
'environmentId': i.environment_id,
168172
'values': i.values,
173+
'organizationId': i.organization_id,
169174
} == i.to_dict()
170175
for i in objs
171176
)

0 commit comments

Comments
 (0)