1. Anthony Menasse
  2. django-current-user

Commits

Anthony Menasse  committed b6534f3

factor out common test setup

  • Participants
  • Parent commits e197b80
  • Branches default

Comments (0)

Files changed (1)

File current_user/tests/tests.py

View file
  • Ignore whitespace
 from django.http import HttpResponse
 from django.db.models import signals
 
-class TestCurrentUserMiddleware(TestCase):
+class TestSetup(object):
 
     def setUp(self):
 
         self.factory = RequestFactory()
         (self.user,created) = User.objects.get_or_create(username='davros')
+        signals.pre_save.receivers = []
 
-        signals.pre_save.receivers = []
+
+class TestCurrentUserMiddleware(TestSetup,TestCase):
 
 
     def test_middleware_adds_user_to_objects_current_user_field_on_create(self):
         self.assertNotEqual(receivers[0][1],receivers[1][1])
 
 
-
-class TestCreateUserMiddleware(TestCase):
-
-    def setUp(self):
-
-        self.factory = RequestFactory()
-        (self.user,created) = User.objects.get_or_create(username='davros')
-
-        signals.pre_save.receivers = []
+class TestCreateUserMiddleware(TestSetup,TestCase):
 
 
     def test_middleware_adds_user_to_objects_current_user_field_on_create(self):
         self.assertEquals(example.created_by,self.user)
 
 
-class  TestCombinedMiddleware(TestCase):
-
-    def setUp(self):
-
-        self.factory = RequestFactory()
-        (self.user,created) = User.objects.get_or_create(username='davros')
-
-        signals.pre_save.receivers = []
+class  TestCombinedMiddleware(TestSetup,TestCase):
 
 
     def test_middleware_combined(self):