Skip to content

Commit e40e160

Browse files
committed
Added close project function and tests.
1 parent 87ea217 commit e40e160

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

dynatademand/api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ def create_project(self, project_data):
158158
)
159159
return response_data
160160

161+
def close_project(self, project_id):
162+
# Closes the requested project. Once a project is closed, all traffic
163+
# is stopped, and the project is automatically sent for invoicing.
164+
response_data = self._api_post('/projects/{}/close'.format(project_id), {})
165+
if response_data.get('status').get('message') != 'success':
166+
raise DemandAPIError(
167+
"Could not close project. Demand API responded with: {}".format(
168+
response_data
169+
)
170+
)
171+
return response_data
172+
161173
def get_project(self, project_id):
162174
return self._api_get('/projects/{}'.format(project_id))
163175

tests/test_projects.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

@@ -55,3 +56,14 @@ def test_create_project(self):
5556
responses.add(responses.POST, '{}/sample/v1/projects'.format(BASE_HOST), json={'status': {'message': 'success'}}, status=200)
5657
self.api.create_project(new_project_data)
5758
self.assertEqual(len(responses.calls), 1)
59+
60+
@responses.activate
61+
def test_close_project(self):
62+
# Tests closing a project.
63+
responses.add(responses.POST, '{}/sample/v1/projects/24/close'.format(BASE_HOST), json={'status': {'message': 'success'}}, status=200)
64+
responses.add(responses.POST, '{}/sample/v1/projects/24/close'.format(BASE_HOST), json={'status': {'message': 'error'}}, status=200)
65+
self.api.close_project(24)
66+
self.assertEqual(len(responses.calls), 1)
67+
with self.assertRaises(DemandAPIError):
68+
self.api.close_project(24)
69+
self.assertEqual(len(responses.calls), 2)

0 commit comments

Comments
 (0)