Skip to content

Commit 15ec48f

Browse files
committed
Add tests
1 parent 82afcf7 commit 15ec48f

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
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_line_items.py

Lines changed: 20 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,22 @@ 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_update_line_item(self):
53+
with open('./tests/test_files/examples/lineitem_update.json', 'r') as new_lineitem_file:
54+
update_lineitem_data = json.load(new_lineitem_file)
55+
56+
# Success response
57+
responses.add(responses.POST, '{}/sample/v1/projects/1/lineItems/1'.format(BASE_HOST), json={'status': {'message': 'success'}}, status=200)
58+
# Response with error status
59+
responses.add(responses.POST, '{}/sample/v1/projects/1/lineItems/1'.format(BASE_HOST), json={'status': {'message': 'error'}}, status=200)
60+
61+
# Test success response
62+
self.api.update_line_item(1, 1, update_lineitem_data)
63+
self.assertEqual(len(responses.calls), 1)
64+
65+
# Test error response
66+
with self.assertRaises(DemandAPIError):
67+
self.api.update_line_item(1, 1, update_lineitem_data)
68+
self.assertEqual(len(responses.calls), 2)

0 commit comments

Comments
 (0)