notify-api-412 use black to enforce python style standards

This commit is contained in:
Kenneth Kehl
2023-08-23 10:35:43 -07:00
parent a7898118d7
commit 026dc14021
586 changed files with 33990 additions and 23461 deletions

View File

@@ -9,16 +9,15 @@ class DocumentDownloadError(Exception):
@classmethod
def from_exception(cls, e):
message = e.response.json()['error']
message = e.response.json()["error"]
status_code = e.response.status_code
return cls(message, status_code)
class DocumentDownloadClient:
def init_app(self, app):
self.api_host = app.config['DOCUMENT_DOWNLOAD_API_HOST']
self.auth_token = app.config['DOCUMENT_DOWNLOAD_API_KEY']
self.api_host = app.config["DOCUMENT_DOWNLOAD_API_HOST"]
self.auth_token = app.config["DOCUMENT_DOWNLOAD_API_KEY"]
def get_upload_url(self, service_id):
return "{}/services/{}/documents".format(self.api_host, service_id)
@@ -28,12 +27,12 @@ class DocumentDownloadClient:
response = requests.post(
self.get_upload_url(service_id),
headers={
'Authorization': "Bearer {}".format(self.auth_token),
"Authorization": "Bearer {}".format(self.auth_token),
},
json={
'document': file_contents,
'is_csv': is_csv or False,
}
"document": file_contents,
"is_csv": is_csv or False,
},
)
response.raise_for_status()
@@ -42,14 +41,16 @@ class DocumentDownloadClient:
# we don't want to tell users about that, so anything that isn't a 400 (virus scan failed or file type
# unrecognised) should be raised as a 500 internal server error here.
if e.response is None:
raise Exception(f'Unhandled document download error: {repr(e)}')
raise Exception(f"Unhandled document download error: {repr(e)}")
elif e.response.status_code == 400:
error = DocumentDownloadError.from_exception(e)
current_app.logger.info(
'Document download request failed with error: {}'.format(error.message)
"Document download request failed with error: {}".format(
error.message
)
)
raise error
else:
raise Exception(f'Unhandled document download error: {e.response.text}')
raise Exception(f"Unhandled document download error: {e.response.text}")
return response.json()['document']['url']
return response.json()["document"]["url"]