Skip to content

Commit 54d2dfa

Browse files
committed
Added launch line item function and tests.
1 parent 87ea217 commit 54d2dfa

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

dynatademand/api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ def get_projects(self):
167167
def get_project_detailed_report(self, project_id):
168168
return self._api_get('/projects/{}/detailedReport'.format(project_id))
169169

170+
def launch_line_item(self, project_id, line_item_id):
171+
# Starts traffic to a line item.
172+
response_data = self._api_post('/projects/{}/lineItems/{}/launch'.format(project_id, line_item_id), {})
173+
if response_data.get('status').get('message') != 'success':
174+
raise DemandAPIError(
175+
"Could not close project. Demand API responded with: {}".format(
176+
response_data
177+
)
178+
)
179+
return response_data
180+
170181
def get_line_item(self, project_id, line_item_id):
171182
return self._api_get('/projects/{}/lineItems/{}'.format(project_id, line_item_id))
172183

tests/test_line_items.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from mock import patch
1212

1313
from dynatademand.api import DemandAPIClient
14+
from dynatademand.errors import DemandAPIError
1415

1516
BASE_HOST = "http://test-url.example"
1617

@@ -46,3 +47,14 @@ def test_get_line_item_detailed_report(self):
4647
self.api.get_line_item_detailed_report(1, 100)
4748
self.assertEqual(len(responses.calls), 1)
4849
self.assertEqual(responses.calls[0].response.json(), line_item_detailed_report_json)
50+
51+
@responses.activate
52+
def test_launch_lineitem(self):
53+
# Tests closing a project.
54+
responses.add(responses.POST, '{}/sample/v1/projects/24/lineItems/180/launch'.format(BASE_HOST), json={'status': {'message': 'success'}}, status=200)
55+
responses.add(responses.POST, '{}/sample/v1/projects/24/lineItems/180/launch'.format(BASE_HOST), json={'status': {'message': 'error'}}, status=200)
56+
self.api.launch_line_item(24, 180)
57+
self.assertEqual(len(responses.calls), 1)
58+
with self.assertRaises(DemandAPIError):
59+
self.api.launch_line_item(24, 180)
60+
self.assertEqual(len(responses.calls), 2)

0 commit comments

Comments
 (0)