File tree Expand file tree Collapse file tree 4 files changed +306
-0
lines changed
Expand file tree Collapse file tree 4 files changed +306
-0
lines changed Original file line number Diff line number Diff line change 77
88SCHEMAS = [
99 "project_new" ,
10+ "project_update" ,
1011 "lineitem_update" ,
1112]
1213
@@ -177,6 +178,17 @@ def get_project(self, project_id):
177178 def get_projects (self ):
178179 return self ._api_get ('/projects' )
179180
181+ def update_project (self , project_id , update_data ):
182+ self ._validate_object ("project_update" , update_data )
183+ response_data = self ._api_post ('/projects/{}' .format (project_id ), update_data )
184+ if response_data .get ('status' ).get ('message' ) != 'success' :
185+ raise DemandAPIError (
186+ "Could not update project. Demand API responded with: {}" .format (
187+ response_data
188+ )
189+ )
190+ return response_data
191+
180192 def get_project_detailed_report (self , project_id ):
181193 return self ._api_get ('/projects/{}/detailedReport' .format (project_id ))
182194
Original file line number Diff line number Diff line change 1+ {
2+ "type" : " object" ,
3+ "title" : " Update Project" ,
4+ "properties" : {
5+ "title" : {
6+ "type" : " string"
7+ },
8+ "notificationEmails" : {
9+ "type" : " array" ,
10+ "items" : {
11+ "type" : " string"
12+ }
13+ },
14+ "devices" : {
15+ "type" : " array" ,
16+ "items" : {
17+ "type" : " string"
18+ }
19+ },
20+ "category" : {
21+ "type" : " object" ,
22+ "properties" : {
23+ "surveyTopic" : {
24+ "type" : " array" ,
25+ "items" : {
26+ "type" : " string"
27+ }
28+ }
29+ }
30+ },
31+ "lineItems" : {
32+ "type" : " array" ,
33+ "items" : {
34+ "type" : " object" ,
35+ "required" : [
36+ " extLineItemId"
37+ ],
38+ "title" : " Update Line Item" ,
39+ "properties" : {
40+ "extLineItemId" : {
41+ "type" : " string"
42+ },
43+ "title" : {
44+ "type" : " string"
45+ },
46+ "countryISOCode" : {
47+ "type" : " string"
48+ },
49+ "languageISOCode" : {
50+ "type" : " string"
51+ },
52+ "surveyURL" : {
53+ "type" : " string"
54+ },
55+ "surveyTestURL" : {
56+ "type" : " string"
57+ },
58+ "indicativeIncidence" : {
59+ "type" : " integer"
60+ },
61+ "daysInField" : {
62+ "type" : " integer"
63+ },
64+ "lengthOfInterview" : {
65+ "type" : " integer"
66+ },
67+ "deliveryType" : {
68+ "type" : " string"
69+ },
70+ "sources" : {
71+ "type" : " array" ,
72+ "items" : {
73+ "type" : " object" ,
74+ "properties" : {
75+ "id" : {
76+ "type" : " integer"
77+ }
78+ }
79+ }
80+ },
81+ "targets" : {
82+ "type" : " object" ,
83+ "properties" : {
84+ "count" : {
85+ "type" : " integer"
86+ },
87+ "dailyLimit" : {
88+ "type" : " integer"
89+ },
90+ "type" : {
91+ "type" : " string" ,
92+ "enum" : [
93+ " COMPLETE"
94+ ]
95+ }
96+ }
97+ },
98+ "quotaPlan" : {
99+ "type" : " object" ,
100+ "properties" : {
101+ "filters" : {
102+ "type" : " array" ,
103+ "items" : {
104+ "type" : " object" ,
105+ "properties" : {
106+ "attributeId" : {
107+ "type" : " string"
108+ },
109+ "options" : {
110+ "type" : " array" ,
111+ "items" : {
112+ "type" : " string"
113+ }
114+ }
115+ }
116+ }
117+ },
118+ "quotaGroups" : {
119+ "type" : " array" ,
120+ "items" : {
121+ "type" : " object" ,
122+ "properties" : {
123+ "name" : {
124+ "type" : " string"
125+ },
126+ "quotaCells" : {
127+ "type" : " array" ,
128+ "items" : {
129+ "type" : " object" ,
130+ "properties" : {
131+ "quotaNodes" : {
132+ "type" : " array" ,
133+ "items" : {
134+ "type" : " object" ,
135+ "properties" : {
136+ "attributeId" : {
137+ "type" : " string"
138+ },
139+ "options" : {
140+ "type" : " array" ,
141+ "items" : {
142+ "type" : " string"
143+ }
144+ }
145+ }
146+ }
147+ },
148+ "count" : {
149+ "type" : " integer"
150+ }
151+ }
152+ }
153+ }
154+ }
155+ }
156+ }
157+ }
158+ }
159+ }
160+ }
161+ },
162+ "exclusions" : {
163+ "type" : " object" ,
164+ "properties" : {
165+ "type" : {
166+ "type" : " string"
167+ },
168+ "list" : {
169+ "type" : " array" ,
170+ "items" : {
171+ "type" : " object"
172+ }
173+ }
174+ }
175+ }
176+ }
177+ }
Original file line number Diff line number Diff line change 1+ {
2+ "title" : " Test Survey" ,
3+ "jobNumber" : " PO-1234" ,
4+ "notificationEmails" : [
5+ " api-test@dynata.com"
6+ ],
7+ "devices" : [
8+ " mobile" ,
9+ " desktop" ,
10+ " tablet"
11+ ],
12+ "category" : {
13+ "surveyTopic" : [
14+ " AUTOMOTIVE" ,
15+ " BUSINESS"
16+ ]
17+ },
18+ "lineItems" : [
19+ {
20+ "extLineItemId" : " lineItem001" ,
21+ "title" : " US College" ,
22+ "countryISOCode" : " US" ,
23+ "languageISOCode" : " en" ,
24+ "surveyURL" : " www.mysurvey.com/live/survey?pid=<#DubKnowledge[1500/Entity id]>&k2=<#Project[Secure Key 2]>&psid=<#IdParameter[Value]>" ,
25+ "surveyTestURL" : " www.mysurvey.com/test/survey?pid=<#DubKnowledge[1500/Entity id]>&k2=<#Project[Secure Key 2]>&psid=<#IdParameter[Value]>" ,
26+ "indicativeIncidence" : 20 ,
27+ "daysInField" : 20 ,
28+ "lengthOfInterview" : 10 ,
29+ "deliveryType" : " BALANCED" ,
30+ "sources" : [
31+ {
32+ "id" : 100
33+ }
34+ ],
35+ "targets" : [
36+ {
37+ "count" : 160 ,
38+ "dailyLimit" : 0 ,
39+ "type" : " COMPLETE"
40+ }
41+ ],
42+ "quotaPlan" : {
43+ "filters" : [
44+ {
45+ "attributeId" : " 61961" ,
46+ "options" : [
47+ " 3" ,
48+ " 4"
49+ ],
50+ "operator" : " include"
51+ }
52+ ],
53+ "quotaGroups" : [
54+ {
55+ "name" : " Gender Distribution" ,
56+ "quotaCells" : [
57+ {
58+ "quotaNodes" : [
59+ {
60+ "attributeId" : " 11" ,
61+ "options" : [
62+ " 1"
63+ ]
64+ }
65+ ],
66+ "count" : 100
67+ },
68+ {
69+ "quotaNodes" : [
70+ {
71+ "attributeId" : " 11" ,
72+ "options" : [
73+ " 2"
74+ ]
75+ }
76+ ],
77+ "count" : 60
78+ }
79+ ]
80+ }
81+ ]
82+ }
83+ }
84+ ],
85+ "exclusions" : {
86+ "type" : " PROJECT" ,
87+ "list" : []
88+ }
89+ }
Original file line number Diff line number Diff line change @@ -70,3 +70,31 @@ def test_close_project(self):
7070 with self .assertRaises (DemandAPIError ):
7171 self .api .close_project (24 )
7272 self .assertEqual (len (responses .calls ), 2 )
73+
74+ @responses .activate
75+ def test_update_project (self ):
76+ # Tests creating a project. This also tests validating the project data as part of `api.create_project`.
77+ with open ('./tests/test_files/examples/project_update.json' , 'r' ) as update_project_file :
78+ update_project_data = json .load (update_project_file )
79+
80+ # Success response
81+ responses .add (
82+ responses .POST ,
83+ '{}/sample/v1/projects/24' .format (BASE_HOST ),
84+ json = {'status' : {'message' : 'success' }},
85+ status = 200 )
86+ # Error message included
87+ responses .add (
88+ responses .POST ,
89+ '{}/sample/v1/projects/24' .format (BASE_HOST ),
90+ json = {'status' : {'message' : 'error' }},
91+ status = 200 )
92+
93+ # Test successful response.
94+ self .api .update_project (24 , update_project_data )
95+ self .assertEqual (len (responses .calls ), 1 )
96+
97+ # Test response with error included.
98+ with self .assertRaises (DemandAPIError ):
99+ self .api .update_project (24 , update_project_data )
100+ self .assertEqual (len (responses .calls ), 2 )
You can’t perform that action at this time.
0 commit comments