Skip to content

Commit 1158df2

Browse files
authored
Merge pull request #7 from researchnow/feature/get-lineitem-endpoint
Added get line item endpoint and test module.
2 parents cb81635 + 5685543 commit 1158df2

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

dynatademand/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,8 @@ def logout(self):
113113
def get_project(self, project_id):
114114
return self._api_get('/projects/{}'.format(project_id))
115115

116+
def get_lineitem(self, project_id, lineitem_id):
117+
return self._api_get('/projects/{}/lineItems/{}'.format(project_id, lineitem_id))
118+
116119
def get_feasibility(self, project_id):
117120
return self._api_get('/projects/{}/feasibility'.format(project_id))

tests/test_files/get_lineitem.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"extLineItemId": "lineItem002",
3+
"title": "US College",
4+
"countryISOCode": "US",
5+
"languageISOCode": "en",
6+
"surveyURL": "www.mysurvey.com/live/survey?pid=<#DubKnowledge[1500/Entity id]>&k2=<#Project[Secure Key 2]>&psid=<#IdParameter[Value]>",
7+
"surveyTestURL": "www.mysurvey.com/test/survey?pid=<#DubKnowledge[1500/Entity id]>&k2=<#Project[Secure Key 2]>&psid=<#IdParameter[Value]>",
8+
"indicativeIncidence": 20,
9+
"daysInField": 20,
10+
"lengthOfInterview": 10,
11+
"deliveryType": "BALANCED",
12+
"sources": [
13+
{
14+
"id": 100
15+
}
16+
],
17+
"targets": [
18+
{
19+
"count": 200,
20+
"dailyLimit": 0,
21+
"type": "COMPLETE"
22+
}
23+
],
24+
"quotaPlan": {
25+
"filters": [
26+
{
27+
"attributeId": "61961",
28+
"options": [
29+
"3",
30+
"4"
31+
],
32+
"operator": "include"
33+
}
34+
],
35+
"quotaGroups": [
36+
{
37+
"name": "Gender Distribution",
38+
"quotaCells": [
39+
{
40+
"quotaNodes": [
41+
{
42+
"attributeId": "11",
43+
"options": [
44+
"1"
45+
]
46+
}
47+
],
48+
"count": 130
49+
},
50+
{
51+
"quotaNodes": [
52+
{
53+
"attributeId": "11",
54+
"options": [
55+
"2"
56+
]
57+
}
58+
],
59+
"count": 70
60+
}
61+
]
62+
}
63+
]
64+
},
65+
"state": "PROVISIONED",
66+
"stateReason": "Created by Client",
67+
"stateLastUpdatedAt": "04/01/2018 00:00:00",
68+
"createdAt": "04/01/2018 00:00:00",
69+
"updatedAt": "04/01/2018 00:00:00",
70+
"launchedAt": null,
71+
"endLinks": {
72+
"complete": "https://api.researchnow.com/respondent/exit?rst=1&psid={psid}&med={calculatedSecurityCode}",
73+
"screenout": "https://api.researchnow.com/respondent/exit?rst=2&psid={psid}",
74+
"overquota": "https://api.researchnow.com/respondent/exit?rst=3&psid={psid}",
75+
"securityKey1": "35040",
76+
"securityLevel": "MEDIUM"
77+
}
78+
}

tests/test_lineitems.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 TestLineItemEndpoints(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_lineitem(self):
25+
with open('./tests/test_files/get_lineitem.json', 'r') as lineitem_file:
26+
lineitem_json = json.load(lineitem_file)
27+
responses.add(responses.GET, '{}/sample/v1/projects/1/lineItems/100'.format(BASE_HOST), json=lineitem_json, status=200)
28+
self.api.get_lineitem(1, 100)
29+
self.assertEqual(len(responses.calls), 1)
30+
self.assertEqual(responses.calls[0].response.json(), lineitem_json)

0 commit comments

Comments
 (0)