[damned-lies] Transform TeamsAndRolesTests into TeamsAndRolesMixin



commit 44876305af304d5928bf9cf0c5f7a9e22e61e7c5
Author: Claude Paroz <claude 2xlibre net>
Date:   Mon Sep 17 13:15:17 2018 +0200

    Transform TeamsAndRolesTests into TeamsAndRolesMixin

 teams/tests.py          | 48 ++++++++++++++++++++++++------------------------
 vertimus/tests/tests.py |  5 +++--
 2 files changed, 27 insertions(+), 26 deletions(-)
---
diff --git a/teams/tests.py b/teams/tests.py
index af9a70c2..dae82479 100644
--- a/teams/tests.py
+++ b/teams/tests.py
@@ -11,47 +11,47 @@ from teams.models import Team, Role
 from languages.models import Language
 
 
-class TeamsAndRolesTests(TestCase):
-    def setUp(self):
-        self.pn = Person(first_name='John', last_name='Nothing',
+class TeamsAndRolesMixin:
+    @classmethod
+    def setUpTestData(cls):
+        super().setUpTestData()
+        cls.pn = Person(first_name='John', last_name='Nothing',
             email='jn devnull com', username= 'jn')
-        self.pn.set_password('password')
-        self.pn.save()
+        cls.pn.set_password('password')
+        cls.pn.save()
 
-        self.pt = Person.objects.create(first_name='John', last_name='Translator',
+        cls.pt = Person.objects.create(first_name='John', last_name='Translator',
             email='jt tf1 com', username= 'jt')
 
-        self.pr = Person.objects.create(first_name='John', last_name='Reviewer',
+        cls.pr = Person.objects.create(first_name='John', last_name='Reviewer',
             email='jr csa com', username= 'jr')
 
-        self.pc = Person.objects.create(first_name='John', last_name='Committer',
+        cls.pc = Person.objects.create(first_name='John', last_name='Committer',
             email='jc alinsudesonpleingre fr', username= 'jc',
             last_login=datetime.now()-timedelta(days=30*6-1)) #active person, but in limit date
 
-        self.pcoo = Person(first_name='John', last_name='Coordinator',
+        cls.pcoo = Person(first_name='John', last_name='Coordinator',
             email='jcoo imthebigboss fr', username= 'jcoo')
-        self.pcoo.set_password('password')
-        self.pcoo.save()
+        cls.pcoo.set_password('password')
+        cls.pcoo.save()
 
-        self.t = Team.objects.create(name='fr', description='French',
+        cls.t = Team.objects.create(name='fr', description='French',
             mailing_list='french_ml example org')
 
-        self.t2 = Team.objects.create(name='pt', description='Portuguese')
+        cls.t2 = Team.objects.create(name='pt', description='Portuguese')
 
-        self.l = Language.objects.create(name='French', locale='fr', team=self.t)
+        cls.l = Language.objects.create(name='French', locale='fr', team=cls.t)
 
         Role.objects.bulk_create([
-            Role(team=self.t, person=self.pt),
-            Role(team=self.t2, person=self.pt, role='reviewer'),
-            Role(team=self.t, person=self.pr, role='reviewer'),
-            Role(team=self.t, person=self.pc, role='committer'),
-            Role(team=self.t, person=self.pcoo, role='coordinator'),
+            Role(team=cls.t, person=cls.pt),
+            Role(team=cls.t2, person=cls.pt, role='reviewer'),
+            Role(team=cls.t, person=cls.pr, role='reviewer'),
+            Role(team=cls.t, person=cls.pc, role='committer'),
+            Role(team=cls.t, person=cls.pcoo, role='coordinator'),
         ])
 
-class TeamTest(TeamsAndRolesTests):
-    def setUp(self):
-        super().setUp()
 
+class TeamTests(TeamsAndRolesMixin, TestCase):
     def test_get_members_by_role_exact(self):
         members = self.t.get_members_by_role_exact('committer')
         t = Team.objects.get(name='fr')
@@ -216,7 +216,7 @@ class TeamTest(TeamsAndRolesTests):
         )
 
 
-class JSONTeamsTest(TeamsAndRolesTests):
+class JSONTeamsTest(TeamsAndRolesMixin, TestCase):
     def setUp(self):
         super().setUp()
         t3 = Team.objects.create(name='gl', description='Galician')
@@ -262,7 +262,7 @@ class JSONTeamsTest(TeamsAndRolesTests):
         self.assertJSONEqual(response.content.decode('utf-8'), expected_JSON)
 
 
-class RoleTest(TeamsAndRolesTests):
+class RoleTest(TeamsAndRolesMixin, TestCase):
 
     def setUp(self):
         super().setUp()
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index d4a6e841..5a719c23 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -9,13 +9,14 @@ from django.core.files.base import File, ContentFile
 from django.core.files.uploadedfile import SimpleUploadedFile
 from django.core import mail
 from django.http import QueryDict
+from django.test import TestCase
 from django.test.utils import override_settings
 from django.urls import reverse
 from django.utils.datastructures import MultiValueDict
 
 from people.models import Person
 from teams.models import Role
-from teams.tests import TeamsAndRolesTests
+from teams.tests import TeamsAndRolesMixin
 from stats.models import Module, Branch, Release, Category, CategoryName, Domain, Statistics
 from stats.tests.utils import patch_shell_command, test_scratchdir
 from vertimus.models import (
@@ -29,7 +30,7 @@ MEDIA_ROOT = tempfile.mkdtemp()
 
 
 @override_settings(MEDIA_ROOT=MEDIA_ROOT)
-class VertimusTest(TeamsAndRolesTests):
+class VertimusTest(TeamsAndRolesMixin, TestCase):
 
     def setUp(self):
         super().setUp()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]