Skip to content

Commit 7bd93d9

Browse files
Merge pull request #13 from dynata/feature/launch-line-item
Added launch line item function and tests.
2 parents afa775b + ed79b44 commit 7bd93d9

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-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 launch_line_item(self, project_id, line_item_id):
246+
# Starts traffic to a line item.
247+
self.validator.validate_request(
248+
'launch_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/{}/launch'.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 pause_line_item(self, project_id, line_item_id):
246264
# Stops traffic to a line item.
247265
self.validator.validate_request(
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+
'launch_line_item': ['path', ],
2223
'pause_line_item': ['path', ],
2324
'update_line_item': ['path', 'body'],
2425

tests/test_line_items.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,33 @@ 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_launch_line_item(self):
56+
# Tests closing a project.
57+
responses.add(
58+
responses.POST,
59+
'{}/sample/v1/projects/24/lineItems/180/launch'.format(BASE_HOST),
60+
json={'status': {'message': 'success'}},
61+
status=200
62+
)
63+
64+
# Response with error status
65+
responses.add(
66+
responses.POST,
67+
'{}/sample/v1/projects/24/lineItems/180/launch'.format(BASE_HOST),
68+
json={'status': {'message': 'error'}},
69+
status=200
70+
)
71+
72+
# Test successful response
73+
self.api.launch_line_item(24, 180)
74+
self.assertEqual(len(responses.calls), 1)
75+
76+
# Test error response
77+
with self.assertRaises(DemandAPIError):
78+
self.api.launch_line_item(24, 180)
79+
self.assertEqual(len(responses.calls), 2)
80+
5481
@responses.activate
5582
def test_pause_line_item(self):
5683
# Tests pausing a line item.

0 commit comments

Comments
 (0)