]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Remove 'default_states' fixture requirement
authorStephen Finucane <stephen.finucane@intel.com>
Thu, 30 Jun 2016 17:30:26 +0000 (18:30 +0100)
committerStephen Finucane <stephen.finucane@intel.com>
Tue, 12 Jul 2016 14:51:35 +0000 (15:51 +0100)
The 'default_states' fixture is used in many tests. However, the
'default_states' are merely suggestions for various States, and the
names themselves have no meaning from a patchwork perspective. In
addition, these fixtures significantly increase run time of the tests.

Resolve this by creating new State objects on demand, rather than
using versions provided by the fixture.

Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
15 files changed:
patchwork/tests/test_bundles.py
patchwork/tests/test_checks.py
patchwork/tests/test_detail.py
patchwork/tests/test_encodings.py
patchwork/tests/test_expiry.py
patchwork/tests/test_list.py
patchwork/tests/test_mboxviews.py
patchwork/tests/test_notifications.py
patchwork/tests/test_parser.py
patchwork/tests/test_rest_api.py
patchwork/tests/test_tags.py
patchwork/tests/test_updates.py
patchwork/tests/test_user.py
patchwork/tests/test_xmlrpc.py
patchwork/tests/utils.py

index 08fc885380bd35d771009749f9fb5d38d810e54c..c18511057f882a44980f3d76848d86e9313e83c3 100644 (file)
@@ -64,8 +64,6 @@ class BundleListTest(TestCase):
 
 class BundleTestBase(TestCase):
 
-    fixtures = ['default_states']
-
     def setUp(self, count=3):
         self.user = create_user()
         self.client.login(username=self.user.username,
index ea347bc28438df2c8fdb537a5e7bf87c825899c1..cb3dfcc712147a4adcf04e38961fb0ab25b25576 100644 (file)
@@ -29,7 +29,6 @@ from patchwork.tests.utils import create_user
 
 
 class PatchChecksTest(TransactionTestCase):
-    fixtures = ['default_tags', 'default_states']
 
     def setUp(self):
         self.patch = create_patches()[0]
index e7412eed4e9c97982963e7f16aa4b1b49e20e3e7..0890c7c027bde2a28b51861eccd335988527e33c 100644 (file)
@@ -27,7 +27,6 @@ from patchwork.tests.utils import create_patches
 
 
 class CoverLetterViewTest(TestCase):
-    fixtures = ['default_states']
 
     def test_redirect(self):
         patches = create_patches()
@@ -41,7 +40,6 @@ class CoverLetterViewTest(TestCase):
 
 
 class PatchViewTest(TestCase):
-    fixtures = ['default_states']
 
     def test_redirect(self):
         covers = create_covers()
index a7961d6940d45ffe5b77f9ede91e0d832bc7a1d0..fd49578f9a86886edeeb596d621d5d010d1bbb08 100644 (file)
@@ -26,8 +26,6 @@ from patchwork.tests.utils import read_patch
 
 class UTF8PatchViewTest(TestCase):
 
-    fixtures = ['default_states']
-
     def setUp(self):
         patch_content = read_patch('0002-utf-8.patch', encoding='utf-8')
         self.patch = create_patch(diff=patch_content)
@@ -50,8 +48,6 @@ class UTF8PatchViewTest(TestCase):
 
 class UTF8HeaderPatchViewTest(UTF8PatchViewTest):
 
-    fixtures = ['default_states']
-
     def setUp(self):
         author = create_person(name=u'P\xe4tch Author')
         patch_content = read_patch('0002-utf-8.patch', encoding='utf-8')
index fd62c404dd261bbcd165edea3e2bb9162f508643..76224649b9271d8475ecc70833ec959556a24a60 100644 (file)
@@ -32,8 +32,6 @@ from patchwork.utils import do_expiry
 
 class TestRegistrationExpiry(TestCase):
 
-    fixtures = ['default_states']
-
     def register(self, date):
         user = create_user()
         user.is_active = False
index 54eefd1c2484c9afd396f9cc96288754807ba6b0..73b2b78f995d90439c891052651c797c7aadd817 100644 (file)
@@ -44,8 +44,6 @@ class EmptyPatchListTest(TestCase):
 
 class PatchOrderTest(TestCase):
 
-    fixtures = ['default_states']
-
     d = datetime.datetime
     patchmeta = [
         ('AlCMyjOsx', 'AlxMyjOsx@nRbqkQV.wBw',
index a772c348ce2e87240fc85248a8e5f86079270365..164de3a7f87986b3cf82df09fa61a9bd287cbb78 100644 (file)
@@ -38,8 +38,6 @@ class MboxPatchResponseTest(TestCase):
 
     """Test that the mbox view appends the Acked-by from a patch comment."""
 
-    fixtures = ['default_states']
-
     def setUp(self):
         project = create_project()
         self.person = create_person()
@@ -62,8 +60,6 @@ class MboxPatchSplitResponseTest(TestCase):
     """Test that the mbox view appends the Acked-by from a patch comment,
        and places it before an '---' update line."""
 
-    fixtures = ['default_states']
-
     def setUp(self):
         project = create_project()
         self.person = create_person()
@@ -86,8 +82,6 @@ class MboxHeaderTest(TestCase):
 
     """Test the passthrough and generation of various headers."""
 
-    fixtures = ['default_states']
-
     def test_header_passthrough_cc(self):
         """Validate passthrough of 'Cc' header."""
         header = 'Cc: CC Person <cc@example.com>'
@@ -164,8 +158,6 @@ class MboxHeaderTest(TestCase):
 
 class MboxCommentPostcriptUnchangedTest(TestCase):
 
-    fixtures = ['default_states']
-
     def test_comment_unchanged(self):
         """Validate postscript part of mail is unchanged.
 
index 6bd67552f9dc82df5b723d37139cefba615bd1f5..5c426fcee6d7c5a894d6431bbf18c6ccdfdaaffd 100644 (file)
@@ -25,10 +25,10 @@ from django.test import TestCase
 
 from patchwork.models import EmailOptout
 from patchwork.models import PatchChangeNotification
-from patchwork.models import State
 from patchwork.tests.utils import create_patch
 from patchwork.tests.utils import create_patches
 from patchwork.tests.utils import create_project
+from patchwork.tests.utils import create_state
 from patchwork.utils import send_notifications
 
 
@@ -36,8 +36,6 @@ class PatchNotificationModelTest(TestCase):
 
     """Tests for the creation and update of the PatchChangeNotifications."""
 
-    fixtures = ['default_states']
-
     def setUp(self):
         self.project = create_project(send_notifications=True)
 
@@ -59,7 +57,7 @@ class PatchNotificationModelTest(TestCase):
         """Ensure we get a notification for interesting patch changes"""
         patch = create_patch(project=self.project)
         oldstate = patch.state
-        state = State.objects.exclude(pk=oldstate.pk)[0]
+        state = create_state()
 
         patch.state = state
         patch.save()
@@ -73,7 +71,7 @@ class PatchNotificationModelTest(TestCase):
         """Ensure we cancel notifications that are no longer valid"""
         patch = create_patch(project=self.project)
         oldstate = patch.state
-        state = State.objects.exclude(pk=oldstate.pk)[0]
+        state = create_state()
 
         patch.state = state
         patch.save()
@@ -88,7 +86,7 @@ class PatchNotificationModelTest(TestCase):
            but keep the original patch details"""
         patch = create_patch(project=self.project)
         oldstate = patch.state
-        newstates = State.objects.exclude(pk=oldstate.pk)[:2]
+        newstates = [create_state(), create_state()]
 
         patch.state = newstates[0]
         patch.save()
@@ -109,8 +107,7 @@ class PatchNotificationModelTest(TestCase):
         """Ensure we don't see notifications created when a project is
            configured not to send them"""
         patch = create_patch()  # don't use self.project
-        oldstate = patch.state
-        state = State.objects.exclude(pk=oldstate.pk)[0]
+        state = create_state()
 
         patch.state = state
         patch.save()
@@ -119,8 +116,6 @@ class PatchNotificationModelTest(TestCase):
 
 class PatchNotificationEmailTest(TestCase):
 
-    fixtures = ['default_states']
-
     def setUp(self):
         self.project = create_project(send_notifications=True)
 
@@ -212,11 +207,14 @@ class PatchNotificationEmailTest(TestCase):
             patch.save()
             PatchChangeNotification(patch=patch, orig_state=patch.state).save()
 
+        state = create_state()
+
         self.assertEqual(PatchChangeNotification.objects.count(), len(patches))
         self._expire_notifications()
 
         # update one notification, to bring it out of the notification delay
-        patches[0].state = State.objects.exclude(pk=patches[0].state.pk)[0]
+
+        patches[0].state = state
         patches[0].save()
 
         # the updated notification should prevent the other from being sent
index ba0ba5a2aaf4f82ceb1439aae17f4257f26be513..eca05a0aa36e978bac5459a6b4481f2be373d15e 100644 (file)
@@ -31,15 +31,15 @@ from patchwork.bin.parsemail import find_author
 from patchwork.bin.parsemail import find_content
 from patchwork.bin.parsemail import find_project_by_header
 from patchwork.bin.parsemail import find_pull_request
-from patchwork.bin.parsemail import parse_mail
+from patchwork.bin.parsemail import parse_mail as _parse_mail
 from patchwork.bin.parsemail import parse_series_marker
 from patchwork.bin.parsemail import split_prefixes
 from patchwork.models import Comment
-from patchwork.models import get_default_initial_patch_state
 from patchwork.models import Patch
 from patchwork.models import Person
 from patchwork.models import State
 from patchwork.tests.utils import create_project
+from patchwork.tests.utils import create_state
 from patchwork.tests.utils import create_user
 from patchwork.tests.utils import read_patch
 from patchwork.tests.utils import SAMPLE_DIFF
@@ -74,9 +74,12 @@ def create_email(content, msgid=None, sender=None, listid=None):
     return _create_email(msg, msgid, sender, listid)
 
 
-class PatchTest(TestCase):
+def parse_mail(*args, **kwargs):
+    create_state()
+    return _parse_mail(*args, **kwargs)
+
 
-    fixtures = ['default_states']
+class PatchTest(TestCase):
 
     def setUp(self):
         self.project = create_project()
@@ -330,7 +333,6 @@ class MultipleProjectPatchTest(TestCase):
     """Test that patches sent to multiple patchwork projects are
        handled correctly."""
 
-    fixtures = ['default_states']
     orig_content = 'Test Comment'
     patch_filename = '0001-add-line.patch'
     msgid = '<1@example.com>'
@@ -510,7 +512,6 @@ class PatchParseTest(PatchTest):
 
 class DelegateRequestTest(TestCase):
 
-    fixtures = ['default_states']
     patch_filename = '0001-add-line.patch'
     msgid = '<1@example.com>'
     invalid_delegate_email = "nobody"
@@ -552,17 +553,17 @@ class DelegateRequestTest(TestCase):
 
 class InitialPatchStateTest(TestCase):
 
-    fixtures = ['default_states']
     patch_filename = '0001-add-line.patch'
     msgid = '<1@example.com>'
     invalid_state_name = "Nonexistent Test State"
 
     def setUp(self):
+        self.default_state = create_state()
+        self.nondefault_state = create_state()
+
         self.patch = read_patch(self.patch_filename)
         self.user = create_user()
         self.project = create_project()
-        self.default_state = get_default_initial_patch_state()
-        self.nondefault_state = State.objects.get(name="Accepted")
 
     def _get_email(self):
         email = create_email(
@@ -607,7 +608,7 @@ class InitialPatchStateTest(TestCase):
 
 class ParseInitialTagsTest(PatchTest):
 
-    fixtures = ['default_tags', 'default_states']
+    fixtures = ['default_tags']
     patch_filename = '0001-add-line.patch'
     orig_content = ('test comment\n\n' +
                     'Tested-by: Test User <test@example.com>\n' +
index 8ff34c3ba31316c7497634e684eee380374e2c22..7ae7f272a45e57303e8e7c1b85bd4cd0c98d1489 100644 (file)
@@ -38,7 +38,6 @@ from patchwork.tests.utils import create_user
 
 @unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API')
 class TestProjectAPI(APITestCase):
-    fixtures = ['default_states']
 
     @staticmethod
     def api_url(item=None):
@@ -148,7 +147,6 @@ class TestProjectAPI(APITestCase):
 
 @unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API')
 class TestPersonAPI(APITestCase):
-    fixtures = ['default_states']
 
     @staticmethod
     def api_url(item=None):
@@ -204,7 +202,6 @@ class TestPersonAPI(APITestCase):
 
 @unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API')
 class TestUserAPI(APITestCase):
-    fixtures = ['default_states']
 
     @staticmethod
     def api_url(item=None):
@@ -247,7 +244,7 @@ class TestUserAPI(APITestCase):
 
 @unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API')
 class TestPatchAPI(APITestCase):
-    fixtures = ['default_states', 'default_tags']
+    fixtures = ['default_tags']
 
     @staticmethod
     def api_url(item=None):
@@ -395,7 +392,7 @@ class TestPatchAPI(APITestCase):
 
 @unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API')
 class TestCheckAPI(APITestCase):
-    fixtures = ['default_states', 'default_tags']
+    fixtures = ['default_tags']
 
     def setUp(self):
         super(TestCheckAPI, self).setUp()
index e6de112bd2e17583d8dcb589479a5116491fc156..e7d7fadfc9c1fb330ac9f99c58145355cc294419 100644 (file)
@@ -30,7 +30,7 @@ from patchwork.tests.utils import create_patch
 
 class ExtractTagsTest(TestCase):
 
-    fixtures = ['default_tags', 'default_states']
+    fixtures = ['default_tags']
     email = 'test@example.com'
     name_email = 'test name <' + email + '>'
 
@@ -83,7 +83,7 @@ class ExtractTagsTest(TestCase):
 
 class PatchTagsTest(TransactionTestCase):
 
-    fixtures = ['default_tags', 'default_states']
+    fixtures = ['default_tags']
     ACK = 1
     REVIEW = 2
     TEST = 3
index 6e6f8a0f063f891d9c7ce82a6b9c47bebe062116..ec5816c3be7aea9fab785d50e2c2f03fc275f597 100644 (file)
@@ -24,12 +24,12 @@ from patchwork.models import Patch
 from patchwork.models import State
 from patchwork.tests.utils import create_patches
 from patchwork.tests.utils import create_project
+from patchwork.tests.utils import create_state
 from patchwork.tests.utils import create_maintainer
 
 
 class MultipleUpdateTest(TestCase):
 
-    fixtures = ['default_states']
     properties_form_id = 'patchform-properties'
 
     def setUp(self):
@@ -95,8 +95,7 @@ class MultipleUpdateTest(TestCase):
         return response
 
     def test_state_change_valid(self):
-        states = [patch.state.pk for patch in self.patches]
-        state = State.objects.exclude(pk__in=states)[0]
+        state = create_state()
 
         self._test_state_change(state.pk)
 
index a93d479523b7df7adf0d6e9a7086ff707520257d..b2cc82520bbe706825ee47c211c8fbc1728dfe5b 100644 (file)
@@ -146,8 +146,6 @@ class UserLoginRedirectTest(TestCase):
 
 class UserProfileTest(_UserTestCase):
 
-    fixtures = ['default_states']
-
     def test_user_profile(self):
         response = self.client.get(reverse('user-profile'))
         self.assertContains(response, 'Your Profile')
index e63e713646f911f64390528f40a3f6ab6a7a9e24..ec804ac668c3c2506469913c8fe28a52f183c538 100644 (file)
@@ -32,8 +32,6 @@ from patchwork.tests.utils import create_patches
                      'setting)')
 class XMLRPCTest(LiveServerTestCase):
 
-    fixtures = ['default_states']
-
     def setUp(self):
         self.url = self.live_server_url + reverse('xmlrpc')
         self.rpc = xmlrpc_client.Server(self.url)
index dc87679b370e21c792507ba74ac4180e618349bb..ba25b5471757ca9397a63bf161bbcc6339e1ce90 100644 (file)
@@ -31,6 +31,7 @@ from patchwork.models import CoverLetter
 from patchwork.models import Patch
 from patchwork.models import Person
 from patchwork.models import Project
+from patchwork.models import State
 
 SAMPLE_DIFF = """--- /dev/null 2011-01-01 00:00:00.000000000 +0800
 +++ a  2011-01-01 00:00:00.000000000 +0800
@@ -129,6 +130,23 @@ def create_maintainer(project=None, **kwargs):
     return user
 
 
+def create_state(**kwargs):
+    """Create 'State' object."""
+    num = State.objects.count()
+
+    values = {
+        'name': 'state_%d' % num,
+        'ordering': num,
+        'action_required': True,
+    }
+    values.update(kwargs)
+
+    state = State(**values)
+    state.save()
+
+    return state
+
+
 def create_bundle(**kwargs):
     """Create 'Bundle' object."""
     num = Bundle.objects.count()
@@ -155,6 +173,7 @@ def create_patch(**kwargs):
         'delegate': None,
         'project': create_project(),
         'msgid': make_msgid(),
+        'state': create_state(),
         'name': 'testpatch%d' % num,
         'headers': '',
         'content': '',
@@ -256,7 +275,10 @@ def create_patches(count=1, **kwargs):
         count (int): Number of patches to create
         kwargs (dict): Overrides for various patch fields
     """
-    return _create_submissions(create_patch, count, **kwargs)
+    values = {'state': create_state()}
+    values.update(kwargs)
+
+    return _create_submissions(create_patch, count, **values)
 
 
 def create_covers(count=1, **kwargs):