@@ -163,6 +163,19 @@ def add_extra_url_params(self, url, params):
163163
164164 return url
165165
166+ def get_survey_data_layouts (self , survey_id ):
167+ self .check_auth_headers ()
168+ data_layouts_url = '{}/surveys/{}/data-layouts' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
169+ data_layouts_response = requests .get (data_layouts_url , headers = self ._authentication_headers )
170+ if data_layouts_response .status_code != 200 :
171+ raise CmixError (
172+ 'CMIX returned a non-200 response code while getting data_layouts: {} and error {}' .format (
173+ data_layouts_response .status_code ,
174+ data_layouts_response .text
175+ )
176+ )
177+ return data_layouts_response .json ()
178+
166179 def get_survey_definition (self , survey_id ):
167180 self .check_auth_headers ()
168181 definition_url = '{}/surveys/{}/definition' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
@@ -255,25 +268,14 @@ def create_export_archive(self, survey_id, export_type):
255268 )
256269 archive_json = archive_response .json ()
257270
258- layout_url = '{}/surveys/{}/data-layouts/' .format (CMIX_SERVICES ['survey' ]["BASE_URL" ], survey_id )
259- layout_response = requests .get (layout_url , headers = self ._authentication_headers )
260- if layout_response .status_code != 200 :
261- raise CmixError (
262- 'CMIX returned a non-200 response code: {} and error {}' .format (
263- layout_response .status_code ,
264- layout_response .text
265- )
266- )
271+ layout_json = self .get_survey_data_layouts (survey_id )
267272 layout_id = None
268- for layout in layout_response . json () :
273+ for layout in layout_json :
269274 if layout .get ('name' ) == 'Default' :
270275 layout_id = layout .get ('id' )
271276 if layout_id is None :
272277 raise CmixError (
273- 'Layouts response did not contain a "Default" layout. Response Code: {}, Body {}' .format (
274- layout_response .status_code ,
275- layout_response .content
276- )
278+ 'Layouts response did not contain a "Default" layout.'
277279 )
278280
279281 archive_json ['dataLayoutId' ] = layout_id
@@ -348,3 +350,16 @@ def create_survey(self, xml_string):
348350 response_json = response .json ()
349351 self .update_project (response_json .get ('projectId' ), status = self .SURVEY_STATUS_DESIGN )
350352 return response_json
353+
354+ def get_survey_simulations (self , survey_id ):
355+ self .check_auth_headers ()
356+ simulations_url = '{}/surveys/{}/simulations' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
357+ simulations_response = requests .get (simulations_url , headers = self ._authentication_headers )
358+ if simulations_response .status_code != 200 :
359+ raise CmixError (
360+ 'CMIX returned a non-200 response code while getting simulations: {} and error {}' .format (
361+ simulations_response .status_code ,
362+ simulations_response .text
363+ )
364+ )
365+ return simulations_response .json ()
0 commit comments