[PATCH 1/2] tests: Factor out a MailFromPatchTest base class

Damien Lespiau damien.lespiau at intel.com
Sat Oct 10 04:06:19 AEDT 2015


We're going to write a test that needs to craft a mail and
InitialPatchStateTest was already doing what we wanted.

Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
 patchwork/tests/test_patchparser.py | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py
index ab02759..8905396 100644
--- a/patchwork/tests/test_patchparser.py
+++ b/patchwork/tests/test_patchparser.py
@@ -529,11 +529,17 @@ class DelegateRequestTest(TestCase):
         self.p1.delete()
         self.user.delete()
 
-class InitialPatchStateTest(TestCase):
+class MailFromPatchTest(TestCase):
     fixtures = ['default_states']
     patch_filename = '0001-add-line.patch'
     msgid = '<1 at example.com>'
-    invalid_state_name = "Nonexistent Test State"
+
+    def get_email(self):
+        email = create_email(self.patch)
+        del email['List-ID']
+        email['List-ID'] = '<' + self.p1.listid + '>'
+        email['Message-Id'] = self.msgid
+        return email
 
     def setUp(self):
         self.patch = read_patch(self.patch_filename)
@@ -541,16 +547,19 @@ class InitialPatchStateTest(TestCase):
         self.p1 = Project(linkname = 'test-project-1', name = 'Project 1',
                 listid = '1.example.com', listemail='1 at example.com')
         self.p1.save()
+
+    def tearDown(self):
+        self.p1.delete()
+        self.user.delete()
+
+class InitialPatchStateTest(MailFromPatchTest):
+    invalid_state_name = "Nonexistent Test State"
+
+    def setUp(self):
+        super(InitialPatchStateTest, self).setUp()
         self.default_state = get_default_initial_patch_state()
         self.nondefault_state = State.objects.get(name="Accepted")
 
-    def get_email(self):
-        email = create_email(self.patch)
-        del email['List-ID']
-        email['List-ID'] = '<' + self.p1.listid + '>'
-        email['Message-Id'] = self.msgid
-        return email
-
     def _assertState(self, state):
         query = Patch.objects.filter(project=self.p1)
         self.assertEquals(query.count(), 1)
@@ -586,10 +595,6 @@ class InitialPatchStateTest(TestCase):
         parse_mail(email)
         self._assertState(self.default_state)
 
-    def tearDown(self):
-        self.p1.delete()
-        self.user.delete()
-
 class ParseInitialTagsTest(PatchTest):
     patch_filename = '0001-add-line.patch'
     test_comment = ('test comment\n\n' +
-- 
2.1.0



More information about the Patchwork mailing list