Skip to content

Commit afa775b

Browse files
Merge pull request #14 from dynata/feature/pause-line-item
Added pause line item function.
2 parents 104d9bd + 97487f1 commit afa775b

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

dynatademand/api.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,24 @@ def get_project_detailed_report(self, project_id):
242242
)
243243
return self._api_get('/projects/{}/detailedReport'.format(project_id))
244244

245+
def pause_line_item(self, project_id, line_item_id):
246+
# Stops traffic to a line item.
247+
self.validator.validate_request(
248+
'pause_line_item',
249+
path_data={
250+
'extProjectId': '{}'.format(project_id),
251+
'extLineItemId': '{}'.format(line_item_id),
252+
},
253+
)
254+
response_data = self._api_post('/projects/{}/lineItems/{}/pause'.format(project_id, line_item_id), {})
255+
if response_data.get('status').get('message') != 'success':
256+
raise DemandAPIError(
257+
"Could not close project. Demand API responded with: {}".format(
258+
response_data
259+
)
260+
)
261+
return response_data
262+
245263
def get_line_item(self, project_id, line_item_id):
246264
self.validator.validate_request(
247265
'get_line_item',
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
},
13+
"required": [
14+
"extProjectId",
15+
"extLineItemId"
16+
]
17+
}

dynatademand/validator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'get_line_item': ['path', ],
2020
'get_line_items': ['path', 'query'],
2121
'get_line_item_detailed_report': ['path', ],
22+
'pause_line_item': ['path', ],
2223
'update_line_item': ['path', 'body'],
2324

2425
# Events

tests/test_line_items.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,32 @@ def test_get_line_item_detailed_report(self):
5151
self.assertEqual(len(responses.calls), 1)
5252
self.assertEqual(responses.calls[0].response.json(), line_item_detailed_report_json)
5353

54+
@responses.activate
55+
def test_pause_line_item(self):
56+
# Tests pausing a line item.
57+
responses.add(
58+
responses.POST,
59+
'{}/sample/v1/projects/24/lineItems/180/pause'.format(BASE_HOST),
60+
json={'status': {'message': 'success'}},
61+
status=200
62+
)
63+
# Response with error
64+
responses.add(
65+
responses.POST,
66+
'{}/sample/v1/projects/24/lineItems/180/pause'.format(BASE_HOST),
67+
json={'status': {'message': 'error'}},
68+
status=200
69+
)
70+
71+
# Test successful response
72+
self.api.pause_line_item(24, 180)
73+
self.assertEqual(len(responses.calls), 1)
74+
75+
# Test error response
76+
with self.assertRaises(DemandAPIError):
77+
self.api.pause_line_item(24, 180)
78+
self.assertEqual(len(responses.calls), 2)
79+
5480
@responses.activate
5581
def test_update_line_item(self):
5682
with open('./tests/test_files/update_line_item.json', 'r') as new_lineitem_file:

0 commit comments

Comments
 (0)