Skip to content

Commit bcee977

Browse files
committed
updating for set quotacell status endpoint
1 parent 2f91c1f commit bcee977

File tree

5 files changed

+105
-1
lines changed

5 files changed

+105
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ 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+
78+
### todo: will update this once it is published in developers.dynata.com
79+
[Set QuotaCell Status](): set_quotacell_status(project_id, line_item_id, quota_cell_id, pause)
7780

7881
### Misc Functions
7982

dynatademand/api.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,26 @@ 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(project_id, line_item_id, quota_cell_id, action), {})
367+
if response_data.get('status').get('message') != 'success':
368+
raise DemandAPIError(
369+
"Could not {} quotacell. Demand API responded with: {}".format(action,
370+
response_data
371+
)
372+
)
373+
return response_data
374+
355375
def get_line_item(self, project_id, line_item_id):
356376
self.validator.validate_request(
357377
'get_line_item',
Lines changed: 27 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,57 @@ 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+
179+
# Tests pausing a quotacell.
180+
responses.add(
181+
responses.POST,
182+
'{}/sample/v1/projects/24/lineItems/180/quotaCells/1/pause'.format(BASE_HOST),
183+
json={'status': {'message': 'success'}},
184+
status=200
185+
)
186+
# Response with error for pausing a quotacell
187+
responses.add(
188+
responses.POST,
189+
'{}/sample/v1/projects/24/lineItems/180/quotaCells/1/pause'.format(BASE_HOST),
190+
json={'status': {'message': 'error'}},
191+
status=200
192+
)
193+
194+
# Test successful response for launch quotacell.
195+
self.api.set_quotacell_status(24, 180, 1, "launch")
196+
self.assertEqual(len(responses.calls), 1)
197+
198+
199+
# Test error response for launch quotacell.
200+
with self.assertRaises(DemandAPIError):
201+
self.api.set_quotacell_status(24, 180, 1, "launch")
202+
self.assertEqual(len(responses.calls), 2)
203+
204+
# Test successful response for pause quotacell.
205+
self.api.set_quotacell_status(24, 180, 1, "pause")
206+
self.assertEqual(len(responses.calls), 3)
207+
208+
# Test error response for pause quotacell.
209+
with self.assertRaises(DemandAPIError):
210+
self.api.set_quotacell_status(24, 180, 1, "pause")
211+
self.assertEqual(len(responses.calls), 4)
212+
162213
@responses.activate
163214
def test_update_line_item(self):
164215
# Tests updating a line item.

0 commit comments

Comments
 (0)