Skip to content

Commit 75591c1

Browse files
authored
Merge pull request #58 from dynata/feat-quota-cell-status
updating for set quotacell status endpoint
2 parents 2f91c1f + a95856d commit 75591c1

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ Links to the Demand API documentation are included for each function.
7373
[Launch Line Item](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/post-lineitem-launch): launch_line_item(project_id, line_item_id)
7474
[Pause Line Item](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/post-lineitem-pause): pause_line_item(project_id, line_item_id)
7575
[Update Line Item](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/post-lineitem): update_line_item(project_id, line_item_id, line_item_data)
76-
[Get Line Item Detailed Report](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/get-detailed-line-item): get_line_item_detailed_report(project_id, line_item_id)
76+
[Get Line Item Detailed Report](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/get-detailed-line-item): get_line_item_detailed_report(project_id, line_item_id)
77+
[Launch Quota cell](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/post-quota-cell-launch): set_quotacell_status(project_id, line_item_id, quota_cell_id, launch)
78+
[Pause Quota cell](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/post-quota-cell-pause): set_quotacell_status(project_id, line_item_id, quota_cell_id, pause)
7779

7880
### Misc Functions
7981

dynatademand/api.py

+21
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,27 @@ def pause_line_item(self, project_id, line_item_id):
352352
)
353353
return response_data
354354

355+
def set_quotacell_status(self, project_id, line_item_id, quota_cell_id, action):
356+
# Stops traffic to a line item.
357+
self.validator.validate_request(
358+
'set_quotacell_status',
359+
path_data={
360+
'extProjectId': '{}'.format(project_id),
361+
'extLineItemId': '{}'.format(line_item_id),
362+
'quotaCellId': '{}'.format(quota_cell_id),
363+
'action': '{}'.format(action),
364+
},
365+
)
366+
response_data = self._api_post('/projects/{}/lineItems/{}/quotaCells/{}/{}'.format(
367+
project_id, line_item_id, quota_cell_id, action), {})
368+
if response_data.get('status').get('message') != 'success':
369+
raise DemandAPIError(
370+
"Could not {} quotacell. Demand API responded with: {}".format(
371+
action, response_data
372+
)
373+
)
374+
return response_data
375+
355376
def get_line_item(self, project_id, line_item_id):
356377
self.validator.validate_request(
357378
'get_line_item',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"extProjectId": {
5+
"type": "string",
6+
"required": true
7+
},
8+
"extLineItemId": {
9+
"type": "string",
10+
"required": true
11+
},
12+
"quotaCellId": {
13+
"type": "string",
14+
"required": true
15+
},
16+
"action": {
17+
"type": "string",
18+
"required": true
19+
}
20+
},
21+
"required": [
22+
"extProjectId",
23+
"extLineItemId",
24+
"quotaCellId",
25+
"action"
26+
]
27+
}

dynatademand/validator.py

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
'pause_line_item': ['path', ],
3333
'update_line_item': ['path', 'body'],
3434

35+
# quotaCells
36+
'set_quotacell_status': ['path', ],
37+
3538
# Events
3639
'get_events': ['query', ],
3740
'get_event': ['path', ],

tests/test_line_items.py

+49
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,55 @@ def test_pause_line_item(self):
159159
self.api.pause_line_item(24, 180)
160160
self.assertEqual(len(responses.calls), 2)
161161

162+
@responses.activate
163+
def test_set_quotacell_status(self):
164+
# Tests launching a quotacell.
165+
responses.add(
166+
responses.POST,
167+
'{}/sample/v1/projects/24/lineItems/180/quotaCells/1/launch'.format(BASE_HOST),
168+
json={'status': {'message': 'success'}},
169+
status=200
170+
)
171+
# Response with error launching a quotacell.
172+
responses.add(
173+
responses.POST,
174+
'{}/sample/v1/projects/24/lineItems/180/quotaCells/1/launch'.format(BASE_HOST),
175+
json={'status': {'message': 'error'}},
176+
status=200
177+
)
178+
# Tests pausing a quotacell.
179+
responses.add(
180+
responses.POST,
181+
'{}/sample/v1/projects/24/lineItems/180/quotaCells/1/pause'.format(BASE_HOST),
182+
json={'status': {'message': 'success'}},
183+
status=200
184+
)
185+
# Response with error for pausing a quotacell
186+
responses.add(
187+
responses.POST,
188+
'{}/sample/v1/projects/24/lineItems/180/quotaCells/1/pause'.format(BASE_HOST),
189+
json={'status': {'message': 'error'}},
190+
status=200
191+
)
192+
193+
# Test successful response for launch quotacell.
194+
self.api.set_quotacell_status(24, 180, 1, "launch")
195+
self.assertEqual(len(responses.calls), 1)
196+
197+
# Test error response for launch quotacell.
198+
with self.assertRaises(DemandAPIError):
199+
self.api.set_quotacell_status(24, 180, 1, "launch")
200+
self.assertEqual(len(responses.calls), 2)
201+
202+
# Test successful response for pause quotacell.
203+
self.api.set_quotacell_status(24, 180, 1, "pause")
204+
self.assertEqual(len(responses.calls), 3)
205+
206+
# Test error response for pause quotacell.
207+
with self.assertRaises(DemandAPIError):
208+
self.api.set_quotacell_status(24, 180, 1, "pause")
209+
self.assertEqual(len(responses.calls), 4)
210+
162211
@responses.activate
163212
def test_update_line_item(self):
164213
# Tests updating a line item.

0 commit comments

Comments
 (0)