Skip to content

Commit 4b358aa

Browse files
committed
linting
1 parent bd82772 commit 4b358aa

File tree

2 files changed

+309
-88
lines changed

2 files changed

+309
-88
lines changed

src/api.py

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
3-
import json
43
import requests
54
import logging
65

76
from django.conf import settings
8-
from popresearch.models import SURVEY_TYPE_CUSTOM, SURVEY_TYPE_CREATIVE, \
9-
SURVEY_TYPE_COMPARISON, SURVEY_TYPE_FORCEDEXPOSURE, SURVEY_TYPE_TRACKING,\
10-
CmixDataArchive, CmixSurvey, CmixSurveyXml, Survey
7+
from popresearch.models import CmixDataArchive, CmixSurvey, CmixSurveyXml
118

129

1310
from .error import CmixError
@@ -67,7 +64,12 @@ def authenticate(self, *args, **kwargs):
6764
try:
6865
auth_response = requests.post(auth_url, json=auth_payload, headers={"Content-Type": "application/json"})
6966
if auth_response.status_code != 200:
70-
raise CmixError('CMIX returned a non-200 response code: {} and error {}'.format(auth_response.status_code, auth_response.text))
67+
raise CmixError(
68+
'CMIX returned a non-200 response code: {} and error {}'.format(
69+
auth_response.status_code,
70+
auth_response.text
71+
)
72+
)
7173
except Exception as e:
7274
raise CmixError('Could not request authorization from CMIX. Error: {}'.format(e))
7375
auth_json = auth_response.json()
@@ -78,7 +80,14 @@ def authenticate(self, *args, **kwargs):
7880

7981
def fetch_banner_filter(self, survey_id, question_a, question_b, response_id):
8082
self.check_auth_headers()
81-
log.debug('Requesting banner filter for CMIX survey {}, question A: {}, question B: {}, response ID: {}'.format(survey_id, question_a, question_b, response_id))
83+
log.debug(
84+
'Requesting banner filter for CMIX survey {}, question A: {}, question B: {}, response ID: {}'.format(
85+
survey_id,
86+
question_a,
87+
question_b,
88+
response_id
89+
)
90+
)
8291
base_url = settings.CMIX_SERVICES['reporting']['BASE_URL']
8392
url = '{}/surveys/{}/response-counts'.format(base_url, survey_id)
8493
payload = {
@@ -202,21 +211,41 @@ def create_export_archive(self, cmix_survey, export_type):
202211

203212
archive_response = requests.post(archive_url, json=payload, headers=headers)
204213
if archive_response.status_code != 200:
205-
raise CmixError('CMIX returned a non-200 response code: {} and error {}'.format(archive_response.status_code, archive_response.text))
214+
raise CmixError(
215+
'CMIX returned a non-200 response code: {} and error {}'.format(
216+
archive_response.status_code,
217+
archive_response.text
218+
)
219+
)
206220
if archive_response.json().get('error', None) is not None:
207-
raise CmixError('CMIX returned an error with status code {}: {}'.format(archive_response.status_code, archive_response.text))
221+
raise CmixError(
222+
'CMIX returned an error with status code {}: {}'.format(
223+
archive_response.status_code,
224+
archive_response.text
225+
)
226+
)
208227
archive_json = archive_response.json()
209228

210229
layout_url = '{}/surveys/{}/data-layouts/'.format(settings.CMIX_SERVICES['survey']["BASE_URL"], cmix_survey.cmix_id)
211230
layout_response = requests.get(layout_url, headers=self._authentication_headers)
212231
if layout_response.status_code != 200:
213-
raise CmixError('CMIX returned a non-200 response code: {} and error {}'.format(layout_response.status_code, layout_response.text))
232+
raise CmixError(
233+
'CMIX returned a non-200 response code: {} and error {}'.format(
234+
layout_response.status_code,
235+
layout_response.text
236+
)
237+
)
214238
layout_id = None
215239
for layout in layout_response.json():
216240
if layout.get('name') == 'Default':
217241
layout_id = layout.get('id')
218242
if layout_id is None:
219-
raise CmixError('Layouts response did not contain a "Default" layout. Response Code: {}, Body {}'.format(layout_response.status_code, layout_response.content))
243+
raise CmixError(
244+
'Layouts response did not contain a "Default" layout. Response Code: {}, Body {}'.format(
245+
layout_response.status_code,
246+
layout_response.content
247+
)
248+
)
220249

221250
archive_json['dataLayoutId'] = layout_id
222251
cda = CmixDataArchive.objects.create(
@@ -236,7 +265,9 @@ def update_archive_status(self, archive):
236265
if layout_id is None:
237266
raise CmixError('Error while updating archie status: layout ID is None. Archive ID: {}'.format(archive.id))
238267
if archive_id is None:
239-
raise CmixError('Error while updating archie status: CMIX archive ID is None. Pop Archive ID: {}'.format(archive.id))
268+
raise CmixError(
269+
'Error while updating archie status: CMIX archive ID is None. Pop Archive ID: {}'.format(archive.id)
270+
)
240271
archive_url = '{}/surveys/{}/data-layouts/{}/archives/{}'.format(
241272
settings.CMIX_SERVICES['survey']["BASE_URL"],
242273
archive.cmix_survey.cmix_id,
@@ -271,7 +302,12 @@ def update_project(self, projectId, status=None):
271302
url = '{}/projects/{}'.format(settings.CMIX_SERVICES['survey']['BASE_URL'], projectId)
272303
response = requests.patch(url, json=payload_json, headers=self._authentication_headers)
273304
if response.status_code > 299:
274-
raise CmixError('CMIX returned an invalid response code during project update: HTTP {} and error {}'.format(response.status_code, response.text))
305+
raise CmixError(
306+
'CMIX returned an invalid response code during project update: HTTP {} and error {}'.format(
307+
response.status_code,
308+
response.text
309+
)
310+
)
275311
return response
276312

277313
def create_survey(self, survey, wave_number=None):

0 commit comments

Comments
 (0)