Skip to content

Commit 1905a82

Browse files
committed
remaining tests
1 parent 4f6a334 commit 1905a82

2 files changed

Lines changed: 74 additions & 119 deletions

File tree

identify/tests/resources/test_environment.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
unicode_literals
33

44
from identify.resources import Environment
5+
from identify.resources import Identity
56
from identify.microclients import IdentityMicroClient
67
from identify.http_clients.sync_client import SyncHttpClient
78
from identify.main import get_client
@@ -52,15 +53,15 @@ def test_add_identity(self, mocker):
5253
}
5354
http_client_mock = mocker.Mock()
5455
http_client_mock.make_request.return_value = data
55-
tt1 = Environment(
56+
env1 = Environment(
5657
{
5758
'id': '1',
5859
'name': 'e1',
5960
},
6061
http_client_mock
6162
)
6263

63-
attr = tt1.add_identity(data)
64+
attr = env1.add_identity(data)
6465

6566
http_client_mock.make_request.assert_called_once_with(
6667
IdentityMicroClient._endpoint['create'],
@@ -71,7 +72,20 @@ def test_add_identity(self, mocker):
7172
)
7273
assert attr.to_dict() == data
7374

74-
tt2 = Environment(
75+
# Test by passing an instance instead of dict data
76+
http_client_mock.reset_mock()
77+
idinstance = Identity(data)
78+
env1.add_identity(idinstance)
79+
http_client_mock.make_request.assert_called_once_with(
80+
IdentityMicroClient._endpoint['create'],
81+
idinstance.to_dict(),
82+
trafficTypeId=idinstance.traffic_type_id,
83+
environmentId=idinstance.environment_id,
84+
key=idinstance.key
85+
)
86+
assert attr.to_dict() == data
87+
88+
env2 = Environment(
7589
{
7690
'id': '1',
7791
'name': 'e2',
@@ -81,7 +95,7 @@ def test_add_identity(self, mocker):
8195
mocker.patch('identify.http_clients.sync_client.SyncHttpClient.make_request')
8296
SyncHttpClient.make_request.return_value = data
8397
ic = get_client({'base_url': 'http://test', 'apikey': '123'})
84-
attr = tt2.add_identity(data, ic)
98+
attr = env2.add_identity(data, ic)
8599
http_client_mock.make_request.assert_called_once_with(
86100
IdentityMicroClient._endpoint['create'],
87101
data,
@@ -114,15 +128,15 @@ def test_add_identities(self, mocker):
114128
'failed': [],
115129
'metadata': {}
116130
}
117-
tt1 = Environment(
131+
env1 = Environment(
118132
{
119133
'id': '1',
120134
'name': 'e1',
121135
},
122136
http_client_mock
123137
)
124138

125-
s1, f1 = tt1.add_identities(data)
139+
s1, f1 = env1.add_identities(data)
126140

127141
http_client_mock.make_request.assert_called_once_with(
128142
IdentityMicroClient._endpoint['create_many'],
@@ -132,7 +146,19 @@ def test_add_identities(self, mocker):
132146
)
133147
assert [s.to_dict() for s in s1] == data
134148

135-
tt2 = Environment(
149+
# Test by passing an instances as well as raw dict data
150+
http_client_mock.reset_mock()
151+
idinstances = [Identity(data[0]), data[1]]
152+
ss, ff = env1.add_identities(idinstances)
153+
http_client_mock.make_request.assert_called_once_with(
154+
IdentityMicroClient._endpoint['create_many'],
155+
data,
156+
trafficTypeId=idinstances[0].traffic_type_id,
157+
environmentId=idinstances[0].environment_id,
158+
)
159+
assert [s.to_dict() for s in ss] == data
160+
161+
env2 = Environment(
136162
{
137163
'id': '1',
138164
'name': 'e2',
@@ -146,7 +172,7 @@ def test_add_identities(self, mocker):
146172
'metadata': {}
147173
}
148174
ic = get_client({'base_url': 'http://test', 'apikey': '123'})
149-
s2, f2 = tt2.add_identities(data, ic)
175+
s2, f2 = env2.add_identities(data, ic)
150176
http_client_mock.make_request.assert_called_once_with(
151177
IdentityMicroClient._endpoint['create_many'],
152178
data,

identify/tests/resources/test_traffic_type.py

Lines changed: 40 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
unicode_literals
33

44
from identify.resources import TrafficType
5+
from identify.resources import Identity
6+
from identify.resources import Attribute
57
from identify.microclients import AttributeMicroClient
68
from identify.microclients import IdentityMicroClient
79
from 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

Comments
 (0)