From 1c20529dfd3b7c90cfcb5bf7d3be8eb4124ff854 Mon Sep 17 00:00:00 2001
From: Andreas Ellewsen <andreas@ellewsen.no>
Date: Tue, 13 Jul 2021 12:13:22 +0200
Subject: [PATCH] Return more info from post and put methods

Before this commit it was unclear whether a post request was successful
or not. We now return the content and status to make this clearer
---
 setra_client/client.py | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/setra_client/client.py b/setra_client/client.py
index 8b024c8..088300c 100644
--- a/setra_client/client.py
+++ b/setra_client/client.py
@@ -288,8 +288,10 @@ class SetraClient(object):
                              data=batchdata.json(),
                              headers=headers,
                              return_response=True)
-        if response.status_code in (409, 202):
-            return 'OK'
+        if response.status_code == 202:
+            return response.content, 'Accepted'
+        elif response.status_code == 409:
+            return response.content, "Conflict"
         else:
             response.raise_for_status()
             return response
@@ -298,19 +300,19 @@ class SetraClient(object):
         """
         PUT updates an existing batch with vouchers and transactions,
         if the batch exists in setra, and has status=created, or validation failed.
-        Returns 404 if no batch was found, 202 for successful update, or 409 if batch was found, but
-        did not meet the status criteria mentioned above.
+        Returns 404 if no batch was found, 204 for successful update, or 409 if batch
+        was found, but did not meet the status criteria mentioned above.
         """
         url = self.urls.put_update_batch()
         headers = {'Content-Type': 'application/json'}
         response = self.put(url,
-                             data=batchdata.json(),
-                             headers=headers,
-                             return_response=True)
-        if response.status_code in (204, 202):
-            return 'OK'
+                            data=batchdata.json(),
+                            headers=headers,
+                            return_response=True)
+        if response.status_code == 204:
+            return response.content, 'No Content'
         elif response.status_code == 409:
-            return 'batch_found_but_cannot_be_updated'
+            return response.content, 'batch_found_but_cannot_be_updated'
         else:
             response.raise_for_status()
         return response
-- 
GitLab