Skip to content

Commit cb81635

Browse files
authored
Merge pull request #8 from researchnow/feature/get-feasibility-endpoint
Added feasibility endpoint & tests.
2 parents f357567 + 1fde90f commit cb81635

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

dynatademand/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,6 @@ def logout(self):
112112

113113
def get_project(self, project_id):
114114
return self._api_get('/projects/{}'.format(project_id))
115+
116+
def get_feasibility(self, project_id):
117+
return self._api_get('/projects/{}/feasibility'.format(project_id))

tests/test_feasibility_pricing.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 TestFeasibilityEndpoints(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_feasibility(self):
25+
with open('./tests/test_files/get_feasibility.json', 'r') as project_file:
26+
project_json = json.load(project_file)
27+
responses.add(responses.GET, '{}/sample/v1/projects/1/feasibility'.format(BASE_HOST), json=project_json, status=200)
28+
self.api.get_feasibility(1)
29+
self.assertEqual(len(responses.calls), 1)
30+
self.assertEqual(responses.calls[0].response.json(), project_json)

tests/test_files/get_feasibility.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"data": [
3+
{
4+
"extLineItemId": "lineItem001",
5+
"feasibility": {
6+
"status": "READY",
7+
"costPerInterview": 3.14,
8+
"expiry": "05/01/2018 00:00:00",
9+
"currency": "USD",
10+
"feasible": true,
11+
"totalCount": 50343,
12+
"valueCounts": [
13+
{
14+
"quotaCells": [
15+
{
16+
"quotaNodes": [
17+
{
18+
"attributeId": "11",
19+
"options": [
20+
"1"
21+
]
22+
}
23+
],
24+
"feasibilityCount": 1000
25+
},
26+
{
27+
"quotaNodes": [
28+
{
29+
"attributeId": "11",
30+
"options": [
31+
"2"
32+
]
33+
}
34+
],
35+
"feasibilityCount": 1200
36+
}
37+
]
38+
}
39+
]
40+
},
41+
"quote": {
42+
"costPerUnit": 3.14,
43+
"currency": "USD",
44+
"detailedQuote": [
45+
{
46+
"costPerUnit": 2.14,
47+
"estimatedCost": 2140,
48+
"title": "Completes",
49+
"type": "BASE",
50+
"units": 1000
51+
},
52+
{
53+
"costPerUnit": 1,
54+
"estimatedCost": 1000,
55+
"title": "Completes",
56+
"type": "PREMIUM",
57+
"units": 1000
58+
}
59+
],
60+
"estimatedCost": 3140
61+
}
62+
},
63+
{
64+
"extLineItemId": "lineItem002",
65+
"feasibility": {
66+
"status": "PROCESSING",
67+
"costPerInterview": null,
68+
"expiry": null,
69+
"currency": null,
70+
"feasible": null,
71+
"totalCount": null,
72+
"valueCounts": []
73+
}
74+
}
75+
]
76+
}

0 commit comments

Comments
 (0)