Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit 2f7196a

Browse files
list project opportunities test and some other updates
1 parent 8fb28f8 commit 2f7196a

File tree

4 files changed

+170
-17
lines changed

4 files changed

+170
-17
lines changed

dynata_rex/opportunity_registry.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ def ack_opportunities(self, opportunities: List[int]) -> None:
119119
res = self.make_request.post(endpoint, opportunities)
120120
return res
121121

122-
def download_collection(self, collection_id: int) -> list:
122+
def download_collection(self, collection_id: str) -> list:
123123
"""Download targeting from a collection cell"""
124124
endpoint = f"{self.base_url}/download-collection"
125-
data = {"id": collection_id}
126-
return self.make_request.post(endpoint, data)
125+
data = {"id": str(collection_id)}
126+
res = self.make_request.post(endpoint, data)
127+
return str(res).split('\n')
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
10110
2+
10120
3+
10150
4+
10350
5+
10430
6+
10640
7+
11520
8+
11530
9+
11610
10+
11640
11+
11730
12+
11840
13+
12310
14+
12430
15+
12530
16+
12560
17+
12710
18+
12730
19+
12750
20+
12850
21+
12870
22+
12930
23+
12950
24+
13330
25+
13430
26+
13470
27+
13560
28+
13640
29+
13770
30+
13850
31+
14240
32+
14250
33+
14350
34+
14430
35+
15122
36+
15144
37+
15148
38+
15220
39+
15227
40+
15310
41+
15314
42+
15325
43+
15345
44+
15412
45+
15418
46+
15710
47+
15810
48+
16122
49+
16128
50+
16340
51+
16411
52+
16423
53+
16435
54+
16451
55+
16454
56+
16514
57+
16720
58+
16968
59+
17114
60+
17132
61+
17134
62+
17143
63+
17148
64+
17413
65+
17415
66+
17423
67+
17435
68+
17510
69+
20123
70+
20133
71+
20212
72+
20236
73+
30114
74+
30164
75+
35116
76+
35132
77+
40117
78+
40131
79+
40135
80+
40173
81+
40233
82+
40255
83+
40263
84+
40265
85+
40286
86+
41361
87+
42118
88+
43111
89+
45123
90+
46121
91+
46125
92+
50242
93+
50246
94+
50249
95+
50263
96+
52411
97+
55221
98+
55224
99+
55271
100+
55284
101+
57151
102+
57552
103+
60225
104+
60227
105+
60238
106+
60265
107+
60271
108+
60285
109+
60293
110+
61121
111+
61122
112+
61253
113+
61254
114+
61256
115+
64129
116+
65112
117+
65144
118+
76113
119+
80114
120+
80118
121+
80119
122+
80221
123+
80228
124+
80231
125+
80361
126+
83122
127+
90113
128+
90222
129+
90223
130+
95111
131+
15811

tests/shared.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ def load_test_data():
3232
"""Load data out of /data folder so we can use it in our tests"""
3333
out = {}
3434
for fn in os.listdir(f"{os.getcwd()}/data"):
35-
if fn.endswith('.json'): # ignore non-json
35+
key = fn.split('.')[0]
36+
if fn.endswith('.json'):
3637
with open(f'{os.getcwd()}/data/{fn}') as f:
37-
key = fn.split('.')[0]
3838
out[key] = json.load(f)
39+
if fn.endswith('.txt'):
40+
with open(f'{os.getcwd()}/data/{fn}') as f:
41+
out[key] = f.read()
3942
return out
4043

4144

tests/test_opportunity_registry.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ def test_list_opportunities_assert_ack_for_invalid_opportunity(session_post,
132132
@patch.object(dynata_rex.OpportunityRegistry, "ack_opportunities")
133133
@patch.object(requests.Session, "post")
134134
def test_ack_opportunity(session_post, ack_method):
135-
"""list opportunities should 'ack' an opportunity returned
136-
that it cannot convert into an Opportunity object"""
137-
138135
data = TEST_DATA['test_list_opportunities'][0]
139136

140137
session_post.return_value = ResponseMock._response_mock(
@@ -144,34 +141,55 @@ def test_ack_opportunity(session_post, ack_method):
144141

145142
assert ack_method.call_count == 1
146143

144+
# Make sure we called parent `ack_opportunities` method with
145+
# [ data['id'] ]
146+
assert ack_method.call_args == (([data['id']],),)
147+
147148

148-
@patch.object(dynata_rex.OpportunityRegistry, "ack_opportunities")
149149
@patch.object(requests.Session, "post")
150-
def test_ack_opportunities(session_post, ack_method):
150+
def test_ack_opportunities(session_post):
151151
"""list opportunities should 'ack' an opportunity returned
152152
that it cannot convert into an Opportunity object"""
153153

154-
data = TEST_DATA['test_list_opportunities']
154+
data = [x['id'] for x in TEST_DATA['test_list_opportunities']]
155155

156156
session_post.return_value = ResponseMock._response_mock(
157-
200, content_type="application/json"
157+
204, content_type="application/json"
158158
)
159159

160160
REGISTRY.ack_opportunities(data)
161161

162-
assert ack_method.call_count == 1
162+
assert session_post.call_count == 1
163+
assert session_post.call_args[1]['data'] == json.dumps(data)
164+
165+
166+
@patch.object(requests.Session, "post")
167+
def test_list_project_opportunities(session_post):
168+
data = [17039, 17344, 17038, 17040, 17041, 17042]
169+
170+
session_post.return_value = ResponseMock._response_mock(
171+
200, content=json.dumps(data), content_type="application/json"
172+
)
173+
res = REGISTRY.list_project_opportunities(99999)
174+
175+
assert session_post.call_args[1]['data'] == json.dumps({
176+
'project_id': 99999,
177+
})
178+
assert res == data
163179

164180

165181
@patch.object(requests.Session, "post")
166182
def test_download_collection(session_post):
167183
"""list opportunities should 'ack' an opportunity returned
168184
that it cannot convert into an Opportunity object"""
169185

170-
data = TEST_DATA['test_list_opportunities'][0]
186+
data = TEST_DATA['test_download_collection']
171187

172188
session_post.return_value = ResponseMock._response_mock(
173-
200, content=json.dumps(data), content_type="application/json"
189+
200, content=data, content_type="text/csv"
174190
)
175191

176-
r = REGISTRY.download_collection(data['id'])
177-
assert isinstance(r, dict)
192+
r = REGISTRY.download_collection('1234567')
193+
194+
assert isinstance(r, list)
195+

0 commit comments

Comments
 (0)