import requests
from retry.api import retry_call

from config import config


def upload_document(service_id, file_contents):
    response = requests.post(
        "{}/services/{}/documents".format(config['document_download']['api_host'], service_id),
        headers={
            'Authorization': "Bearer {}".format(config['document_download']['api_key']),
        },
        files={
            'document': file_contents
        }
    )

    response.raise_for_status()

    return response.json()['document']['url']


def test_document_upload_and_download():
    document_url = retry_call(
        upload_document,
        fargs=[config['service']['id'], 'functional tests file'],
        tries=3,
        delay=10
    )

    downloaded_document = requests.get(document_url)

    assert downloaded_document.text == 'functional tests file'

@@ -433,24 +433,31 @@
 %7D%0A    )%0A%0A   
+ json =
  response.ra
@@ -458,25 +458,91 @@
 nse.
-raise_for_
+json()%0A    assert 'error' not in json, 'Status code %7B%7D'.format(response.
 status
-(
+_code
 )%0A%0A 
@@ -551,31 +551,20 @@
  return 
-response.
 json
-()
 %5B'docume
@@ -674,16 +674,92 @@
 cument,%0A
+        # add PDF header to trick doc download into thinking its a real pdf%0A
         
@@ -791,16 +791,25 @@
 'id'%5D, '
+%25PDF-1.4 
 function
@@ -960,16 +960,25 @@
 ext == '
+%25PDF-1.4 
 function

update doc download test to send a "real" pdf