Skip to content

Commit e89a4ce

Browse files
authored
Merge branch 'dev' into POP-2285
2 parents 49d414e + cbbe188 commit e89a4ce

12 files changed

+155
-0
lines changed

dynatademand/api.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ def logout(self):
134134
))
135135
return logout_response.json()
136136

137+
def get_countries(self):
138+
return self._api_get('/countries')
139+
140+
def get_event(self, event_id):
141+
return self._api_get('/events/{}'.format(event_id))
142+
143+
def get_events(self):
144+
return self._api_get('/events')
145+
137146
def create_project(self, project_data):
138147
# Creates a new project. Uses the "new project" schema.
139148
self._validate_object("project_new", project_data)
@@ -152,14 +161,23 @@ def get_project(self, project_id):
152161
def get_projects(self):
153162
return self._api_get('/projects')
154163

164+
def get_project_detailed_report(self, project_id):
165+
return self._api_get('/projects/{}/detailedReport'.format(project_id))
166+
155167
def get_line_item(self, project_id, line_item_id):
156168
return self._api_get('/projects/{}/lineItems/{}'.format(project_id, line_item_id))
157169

158170
def get_line_items(self, project_id):
159171
return self._api_get('/projects/{}/lineItems'.format(project_id))
160172

173+
def get_line_item_detailed_report(self, project_id, line_item_id):
174+
return self._api_get('/projects/{}/lineItems/{}/detailedReport'.format(project_id, line_item_id))
175+
161176
def get_feasibility(self, project_id):
162177
return self._api_get('/projects/{}/feasibility'.format(project_id))
163178

179+
def get_survey_topics(self):
180+
return self._api_get('/categories/surveyTopics')
181+
164182
def get_sources(self):
165183
return self._api_get('/sources')

tests/test_categories.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# encoding: utf-8
2+
from __future__ import unicode_literals, print_function
3+
4+
import json
5+
import unittest
6+
import responses
7+
8+
try:
9+
from unittest.mock import patch
10+
except ImportError:
11+
from mock import patch
12+
13+
from dynatademand.api import DemandAPIClient
14+
15+
BASE_HOST = "http://test-url.example"
16+
17+
18+
class TestCategoryEndpoints(unittest.TestCase):
19+
def setUp(self):
20+
self.api = DemandAPIClient(client_id='test', username='testuser', password='testpass', base_host=BASE_HOST)
21+
self.api._access_token = 'Bearer testtoken'
22+
23+
@responses.activate
24+
def test_get_survey_topics(self):
25+
with open('./tests/test_files/get_survey_topics.json', 'r') as survey_topics_file:
26+
survey_topics_json = json.load(survey_topics_file)
27+
responses.add(responses.GET, '{}/sample/v1/categories/surveyTopics'.format(BASE_HOST), json=survey_topics_json, status=200)
28+
self.api.get_survey_topics()
29+
self.assertEqual(len(responses.calls), 1)
30+
self.assertEqual(responses.calls[0].response.json(), survey_topics_json)

tests/test_countries.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# encoding: utf-8
2+
from __future__ import unicode_literals, print_function
3+
4+
import json
5+
import unittest
6+
import responses
7+
8+
try:
9+
from unittest.mock import patch
10+
except ImportError:
11+
from mock import patch
12+
13+
from dynatademand.api import DemandAPIClient
14+
15+
BASE_HOST = "http://test-url.example"
16+
17+
18+
class TestProjectEndpoints(unittest.TestCase):
19+
def setUp(self):
20+
self.api = DemandAPIClient(client_id='test', username='testuser', password='testpass', base_host=BASE_HOST)
21+
self.api._access_token = 'Bearer testtoken'
22+
23+
@responses.activate
24+
def test_get_countries(self):
25+
with open('./tests/test_files/get_countries.json', 'r') as countries_file:
26+
countries_json = json.load(countries_file)
27+
responses.add(responses.GET, '{}/sample/v1/countries'.format(BASE_HOST), json=countries_json, status=200)
28+
self.api.get_countries()
29+
self.assertEqual(len(responses.calls), 1)
30+
self.assertEqual(responses.calls[0].response.json(), countries_json)

tests/test_events.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# encoding: utf-8
2+
from __future__ import unicode_literals, print_function
3+
4+
import json
5+
import unittest
6+
import responses
7+
8+
try:
9+
from unittest.mock import patch
10+
except ImportError:
11+
from mock import patch
12+
13+
from dynatademand.api import DemandAPIClient
14+
15+
BASE_HOST = "http://test-url.example"
16+
17+
18+
class TestEventEndpoints(unittest.TestCase):
19+
def setUp(self):
20+
self.api = DemandAPIClient(client_id='test', username='testuser', password='testpass', base_host=BASE_HOST)
21+
self.api._access_token = 'Bearer testtoken'
22+
23+
@responses.activate
24+
def test_get_event(self):
25+
with open('./tests/test_files/get_event.json', 'r') as event_file:
26+
event_json = json.load(event_file)
27+
responses.add(responses.GET, '{}/sample/v1/events/1337'.format(BASE_HOST), json=event_json, status=200)
28+
self.api.get_event(1337)
29+
self.assertEqual(len(responses.calls), 1)
30+
self.assertEqual(responses.calls[0].response.json(), event_json)
31+
32+
@responses.activate
33+
def test_get_events(self):
34+
with open('./tests/test_files/get_events.json', 'r') as event_file:
35+
event_json = json.load(event_file)
36+
responses.add(responses.GET, '{}/sample/v1/events'.format(BASE_HOST), json=event_json, status=200)
37+
self.api.get_events()
38+
self.assertEqual(len(responses.calls), 1)
39+
self.assertEqual(responses.calls[0].response.json(), event_json)

tests/test_files/get_countries.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"country": "Norge"
3+
}

tests/test_files/get_event.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"event": "Cow jumping over the moon"
3+
}

tests/test_files/get_events.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"event": "Me, me, me"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"report": "That's my story and I'm sticking to it!"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"report": "That's my story and I'm sticking to it!"
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"survey": {
3+
"topic": "milk"
4+
}
5+
}

0 commit comments

Comments
 (0)