diff --git a/cernservicexml/publisher.py b/cernservicexml/publisher.py index 4e8a3b1..f2bc8e3 100644 --- a/cernservicexml/publisher.py +++ b/cernservicexml/publisher.py @@ -34,6 +34,7 @@ import requests +from ._compat import StringIO from .document import ServiceDocument @@ -45,4 +46,5 @@ class XSLSPublisher(object): def send(cls, document, api_url='http://xsls.cern.ch'): """Send service document to XSLS.""" assert isinstance(document, ServiceDocument) - return requests.post(api_url, data=document.to_xml()) + return requests.post(api_url, files=dict( + file=StringIO(document.to_xml()))) diff --git a/tests/test_publisher.py b/tests/test_publisher.py index f837a70..5edf9f0 100644 --- a/tests/test_publisher.py +++ b/tests/test_publisher.py @@ -13,6 +13,7 @@ from datetime import datetime +import cgi from cernservicexml import ServiceDocument, XSLSPublisher from cernservicexml._compat import import_httpretty @@ -31,7 +32,15 @@ def test_xslspublisher_send(): resp = XSLSPublisher.send(doc, api_url=EXAMPLE_URL) assert resp.status_code == 200 - assert httpretty.last_request().body.decode('utf-8') == \ + # Parse multipart/form-data (not supported by HTTPretty) + content_type = httpretty.last_request().headers['Content-Type'].split(';') + content_type = [x.strip() for x in content_type] + key, boundary = content_type[1].split("=") + data = cgi.parse_multipart(httpretty.last_request().rfile, + {'boundary': boundary.encode('utf-8')}) + + assert 'file' in data + assert data['file'][0].decode('utf-8') == \ '' \ 'myid100' \ '2015-01-01T00:00:00'