Repository: EdinburghGenomics/EGCG-Core

Issue:
rest_communication: post data as form instead of json
`post_entry` should have an option to specify a post where the data is stored in the form instead of the query string.


Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 58a261b..6db3fe5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,10 +1,10 @@
 Changelog for EGCG-Core
 ===========================
 
-0.8 (unreleased)
+0.7.3 (unreleased)
 ----------------
 
-- Nothing changed yet.
+- Add new option to rest_communication.post_entry to submit payload without json
 
 
 0.7.2 (2017-08-03)
diff --git a/egcg_core/rest_communication.py b/egcg_core/rest_communication.py
index 949e97c..bc78e7d 100644
--- a/egcg_core/rest_communication.py
+++ b/egcg_core/rest_communication.py
@@ -165,9 +165,12 @@ class Communicator(AppLogger):
         else:
             self.warning('No document found in endpoint %s for %s', endpoint, query_args)
 
-    def post_entry(self, endpoint, payload):
+    def post_entry(self, endpoint, payload, use_data=False):
         files, payload = self._detect_files_in_json(payload)
-        return self._req('POST', self.api_url(endpoint), json=payload, files=files)
+        if use_data:
+            return self._req('POST', self.api_url(endpoint), data=payload, files=files)
+        else:
+            return self._req('POST', self.api_url(endpoint), json=payload, files=files)
 
     def put_entry(self, endpoint, element_id, payload):
         files, payload = self._detect_files_in_json(payload)
diff --git a/requirements.txt b/requirements.txt
index b55e6f8..b0f950e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,6 +1,7 @@
 pytest>=2.7.2
+requests==2.14.2
 PyYAML>=3.11
 pyclarity_lims>=0.4
 jinja2==2.8
-asana==0.6.2
+asana==0.6.5
 cached_property


Test patch:
diff --git a/tests/test_rest_communication.py b/tests/test_rest_communication.py
index 3f920be..fcc907f 100644
--- a/tests/test_rest_communication.py
+++ b/tests/test_rest_communication.py
@@ -180,6 +180,24 @@ class TestRestCommunication(TestEGCG):
             files={'f': (file_path, b'test content', 'text/plain')}
         )
 
+        self.comm.post_entry(test_endpoint, payload=test_flat_request_content, use_data=True)
+        mocked_response.assert_called_with(
+            'POST',
+            rest_url(test_endpoint),
+            auth=auth,
+            data=test_flat_request_content,
+            files=None
+        )
+
+        self.comm.post_entry(test_endpoint, payload=test_request_content_plus_files, use_data=True)
+        mocked_response.assert_called_with(
+            'POST',
+            rest_url(test_endpoint),
+            auth=auth,
+            data=test_flat_request_content,
+            files={'f': (file_path, b'test content', 'text/plain')}
+        )
+
     @patched_response
     def test_put_entry(self, mocked_response):
         self.comm.put_entry(test_endpoint, 'an_element_id', payload=test_nested_request_content)