22 unicode_literals
33
44from identify .resources import TrafficType
5+ from identify .resources import Identity
6+ from identify .resources import Attribute
57from identify .microclients import AttributeMicroClient
68from identify .microclients import IdentityMicroClient
79from identify .http_clients .sync_client import SyncHttpClient
@@ -127,6 +129,17 @@ def test_add_attribute(self, mocker):
127129 )
128130 assert attr .to_dict () == data
129131
132+ # Test adding an attribute instance
133+ atinstance = Attribute (data )
134+ http_client_mock .reset_mock ()
135+ attr = tt1 .add_attribute (atinstance )
136+ http_client_mock .make_request .assert_called_once_with (
137+ AttributeMicroClient ._endpoint ['create' ],
138+ data ,
139+ trafficTypeId = data ['trafficTypeId' ],
140+ )
141+ assert attr .to_dict () == atinstance .to_dict ()
142+
130143 tt2 = TrafficType ({
131144 'id' : '1' ,
132145 'displayAttributeId' : 'asd' ,
@@ -175,6 +188,20 @@ def test_add_identity(self, mocker):
175188 )
176189 assert attr .to_dict () == data
177190
191+ # Test by passing an instance instead of dict data
192+ http_client_mock .reset_mock ()
193+ idinstance = Identity (data )
194+ tt1 .add_identity (idinstance )
195+ http_client_mock .make_request .assert_called_once_with (
196+ IdentityMicroClient ._endpoint ['create' ],
197+ data ,
198+ trafficTypeId = idinstance .traffic_type_id ,
199+ environmentId = idinstance .environment_id ,
200+ key = idinstance .key
201+ )
202+ assert attr .to_dict () == data
203+
204+
178205 tt2 = TrafficType (
179206 {
180207 'id' : '1' ,
@@ -238,6 +265,19 @@ def test_add_identities(self, mocker):
238265 )
239266 assert [s .to_dict () for s in s1 ] == data
240267
268+ # Test by passing an instances as well as raw dict data
269+ http_client_mock .reset_mock ()
270+ idinstances = [Identity (data [0 ]), data [1 ]]
271+ ss , ff = tt1 .add_identities (idinstances )
272+ http_client_mock .make_request .assert_called_once_with (
273+ IdentityMicroClient ._endpoint ['create_many' ],
274+ data ,
275+ trafficTypeId = idinstances [0 ].traffic_type_id ,
276+ environmentId = idinstances [0 ].environment_id ,
277+ )
278+ assert [s .to_dict () for s in ss ] == data
279+
280+
241281 tt2 = TrafficType ({
242282 'id' : '1' ,
243283 'name' : 'tt1' ,
@@ -259,114 +299,3 @@ def test_add_identities(self, mocker):
259299 environmentId = data [0 ]['environmentId' ],
260300 )
261301 assert [s .to_dict () for s in s2 ] == data
262-
263- # def test_add_identity(self, mocker):
264- # '''
265- # '''
266- # data = {
267- # 'key': 'key1',
268- # 'trafficTypeId': '1',
269- # 'environmentId': '1',
270- # 'values': {'a1': 'v1'},
271- # 'organizationId': 'o1',
272- # }
273- # http_client_mock = mocker.Mock()
274- # http_client_mock.make_request.return_value = data
275- # tt1 = TrafficType(
276- # {
277- # 'id': '1',
278- # 'displayAttributeId': 'asd',
279- # 'name': 'n1',
280- # },
281- # http_client_mock
282- # )
283- #
284- # attr = tt1.add_identity(data)
285- #
286- # http_client_mock.make_request.assert_called_once_with(
287- # IdentityMicroClient._endpoint['create'],
288- # data,
289- # trafficTypeId=data['trafficTypeId'],
290- # environmentId=data['environmentId'],
291- # key=data['key']
292- # )
293- # assert attr.to_dict() == data
294- #
295- # http_client_mock.reset_mock()
296- # tt2 = TrafficType(
297- # {
298- # 'id': '1',
299- # 'displayAttributeId': 'asd',
300- # 'name': 'n1',
301- # },
302- # )
303- #
304- # attr = tt2.add_identity(data, IdentityMicroClient(http_client_mock))
305- # http_client_mock.make_request.assert_called_once_with(
306- # IdentityMicroClient._endpoint['create'],
307- # data,
308- # trafficTypeId=data['trafficTypeId'],
309- # environmentId=data['environmentId'],
310- # key=data['key']
311- # )
312- # assert attr.to_dict() == data
313- #
314- # def test_add_identities(self, mocker):
315- # '''
316- # '''
317- # data = [{
318- # 'key': 'key1',
319- # 'trafficTypeId': '1',
320- # 'environmentId': '1',
321- # 'values': {'a1': 'v1'},
322- # 'organizationId': 'o1',
323- # }, {
324- # 'key': 'key2',
325- # 'trafficTypeId': '1',
326- # 'environmentId': '1',
327- # 'values': {'a2': 'v2'},
328- # 'organizationId': 'o1',
329- # }]
330- #
331- # http_client_mock = mocker.Mock()
332- # http_client_mock.make_request.return_value = {
333- # 'objects': data,
334- # 'failed': [],
335- # 'metadata': {}
336- # }
337- # tt1 = TrafficType(
338- # {
339- # 'id': '1',
340- # 'displayAttributeId': 'asd',
341- # 'name': 'n1',
342- # },
343- # http_client_mock
344- # )
345- #
346- # s1, f1 = tt1.add_identities(data)
347- #
348- # http_client_mock.make_request.assert_called_once_with(
349- # IdentityMicroClient._endpoint['create_many'],
350- # data,
351- # trafficTypeId=data[0]['trafficTypeId'],
352- # environmentId=data[0]['environmentId'],
353- # )
354- # assert [s.to_dict() for s in s1] == data
355- #
356- # http_client_mock.reset_mock()
357- # tt2 = TrafficType(
358- # {
359- # 'id': '1',
360- # 'displayAttributeId': 'asd',
361- # 'name': 'n1',
362- # },
363- # )
364- #
365- # s2, f2 = tt2.add_identities(data, IdentityMicroClient(http_client_mock))
366- # http_client_mock.make_request.assert_called_once_with(
367- # IdentityMicroClient._endpoint['create_many'],
368- # data,
369- # trafficTypeId=data[0]['trafficTypeId'],
370- # environmentId=data[0]['environmentId'],
371- # )
372- # assert [s.to_dict() for s in s2] == data
0 commit comments