[PATCH] Add regression tests for including all headers

vkabatov at redhat.com vkabatov at redhat.com
Thu Apr 26 00:44:56 AEST 2018


From: Veronika Kabatova <vkabatov at redhat.com>

Signed-off-by: Veronika Kabatova <vkabatov at redhat.com>
---
 patchwork/tests/api/test_cover.py | 12 +++++++++++-
 patchwork/tests/api/test_patch.py | 13 +++++++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/patchwork/tests/api/test_cover.py b/patchwork/tests/api/test_cover.py
index 3135b7e..4c0c528 100644
--- a/patchwork/tests/api/test_cover.py
+++ b/patchwork/tests/api/test_cover.py
@@ -17,6 +17,7 @@
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+import email.parser
 import unittest
 
 from django.conf import settings
@@ -109,12 +110,21 @@ class TestCoverLetterAPI(APITestCase):
 
     def test_detail(self):
         """Validate we can get a specific cover letter."""
-        cover_obj = create_cover()
+        cover_obj = create_cover(
+            headers='Received: from somewhere\nReceived: from another place'
+        )
 
         resp = self.client.get(self.api_url(cover_obj.id))
         self.assertEqual(status.HTTP_200_OK, resp.status_code)
         self.assertSerialized(cover_obj, resp.data)
 
+        # Make sure we don't regress and all headers with the same key are
+        # included in the response
+        parsed_headers = email.parser.Parser().parsestr(cover_obj.headers,
+                                                        True)
+        for key, value in parsed_headers.items():
+            self.assertIn(value, resp.data['headers'][key])
+
     def test_create_update_delete(self):
         user = create_maintainer()
         user.is_superuser = True
diff --git a/patchwork/tests/api/test_patch.py b/patchwork/tests/api/test_patch.py
index 909c1eb..40ca777 100644
--- a/patchwork/tests/api/test_patch.py
+++ b/patchwork/tests/api/test_patch.py
@@ -17,6 +17,7 @@
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+import email.parser
 from email.utils import make_msgid
 import unittest
 
@@ -120,12 +121,20 @@ class TestPatchAPI(APITestCase):
     def test_detail(self):
         """Validate we can get a specific patch."""
         patch = create_patch(
-            content='Reviewed-by: Test User <test at example.com>\n')
+            content='Reviewed-by: Test User <test at example.com>\n',
+            headers='Received: from somewhere\nReceived: from another place'
+        )
 
         resp = self.client.get(self.api_url(patch.id))
         self.assertEqual(status.HTTP_200_OK, resp.status_code)
         self.assertSerialized(patch, resp.data)
-        self.assertEqual(patch.headers, resp.data['headers'] or '')
+
+        # Make sure we don't regress and all headers with the same key are
+        # included in the response
+        parsed_headers = email.parser.Parser().parsestr(patch.headers, True)
+        for key, value in parsed_headers.items():
+            self.assertIn(value, resp.data['headers'][key])
+
         self.assertEqual(patch.content, resp.data['content'])
         self.assertEqual(patch.diff, resp.data['diff'])
         self.assertEqual(0, len(resp.data['tags']))
-- 
2.13.6



More information about the Patchwork mailing list