Skip to content

Commit 33295a5

Browse files
committed
Added validation to launch_line_item, fixed up tests.
1 parent e3f0212 commit 33295a5

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

dynatademand/api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ def get_project_detailed_report(self, project_id):
228228

229229
def launch_line_item(self, project_id, line_item_id):
230230
# Starts traffic to a line item.
231+
self.validator.validate_request(
232+
'launch_line_item',
233+
path_data={
234+
'extProjectId': '{}'.format(project_id),
235+
'extLineItemId': '{}'.format(line_item_id),
236+
},
237+
)
231238
response_data = self._api_post('/projects/{}/lineItems/{}/launch'.format(project_id, line_item_id), {})
232239
if response_data.get('status').get('message') != 'success':
233240
raise DemandAPIError(
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
@@ -18,6 +18,7 @@
1818
'get_line_item': ['path', ],
1919
'get_line_items': ['path', 'query'],
2020
'get_line_item_detailed_report': ['path', ],
21+
'launch_line_item': ['path', ],
2122
'update_line_item': ['path', 'body'],
2223

2324
# Events

tests/test_line_items.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,26 @@ def test_get_line_item_detailed_report(self):
5454
@responses.activate
5555
def test_launch_lineitem(self):
5656
# Tests closing a project.
57-
responses.add(responses.POST, '{}/sample/v1/projects/24/lineItems/180/launch'.format(BASE_HOST), json={'status': {'message': 'success'}}, status=200)
58-
responses.add(responses.POST, '{}/sample/v1/projects/24/lineItems/180/launch'.format(BASE_HOST), json={'status': {'message': 'error'}}, status=200)
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
5973
self.api.launch_line_item(24, 180)
6074
self.assertEqual(len(responses.calls), 1)
75+
76+
# Test error response
6177
with self.assertRaises(DemandAPIError):
6278
self.api.launch_line_item(24, 180)
6379
self.assertEqual(len(responses.calls), 2)

0 commit comments

Comments
 (0)