diff mbox series

Add regression tests for including all headers

Message ID 20180425144456.27484-1-vkabatov@redhat.com
State Accepted
Headers show
Series Add regression tests for including all headers | expand

Commit Message

Veronika Kabatova April 25, 2018, 2:44 p.m. UTC
From: Veronika Kabatova <vkabatov@redhat.com>

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

Comments

Stephen Finucane April 25, 2018, 8:07 p.m. UTC | #1
On Wed, 2018-04-25 at 16:44 +0200, vkabatov@redhat.com wrote:
> From: Veronika Kabatova <vkabatov@redhat.com>
> 
> Signed-off-by: Veronika Kabatova <vkabatov@redhat.com>

Squashed this into the previous one and applied. Thanks!

Reviewed-by: Stephen Finucane <stephen@that.guru>
diff mbox series

Patch

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@example.com>\n')
+            content='Reviewed-by: Test User <test@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']))