Add a document download client

Allows uploading documents to the Document Download API.
The client is configured with an API host and auth token. There's
no need for a flag to disable the client in the test environments
at the moment since the upload is only triggered by a specific
payload which would only be sent with an explicit goal of using
document download.
This commit is contained in:
Alexey Bezhan
2018-04-04 17:31:02 +01:00
parent a0c6f6a22e
commit 204aaf172d
4 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import requests
import requests_mock
import pytest
from app.clients.document_download import DocumentDownloadClient
@pytest.fixture(scope='function')
def document_download(client, mocker):
client = DocumentDownloadClient()
current_app = mocker.Mock(config={
'DOCUMENT_DOWNLOAD_API_HOST': 'https://document-download',
'DOCUMENT_DOWNLOAD_API_KEY': 'test-key'
})
client.init_app(current_app)
return client
def test_get_upload_url(document_download):
assert document_download.get_upload_url('service-id') == 'https://document-download/services/service-id/documents'
def test_upload_document(document_download):
with requests_mock.Mocker() as request_mock:
request_mock.post('https://document-download/services/service-id/documents', json={
'document': {'url': 'https://document-download/services/service-id/documents/uploaded-url'}
}, status_code=201)
resp = document_download.upload_document('service-id', 'abababab')
assert resp == 'https://document-download/services/service-id/documents/uploaded-url'
def test_should_raise_for_status(document_download):
with pytest.raises(requests.HTTPError), requests_mock.Mocker() as request_mock:
request_mock.post('https://document-download/services/service-id/documents', json={}, status_code=403)
document_download.upload_document('service-id', 'abababab')