[damned-lies] Optimized common tests
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Optimized common tests
- Date: Sat, 21 Dec 2019 10:41:06 +0000 (UTC)
commit 2a6857fa8def084a03f2504132c6c7e1de3e009e
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Dec 21 11:32:37 2019 +0100
Optimized common tests
common/tests.py | 70 +++++++++++++++++++++-----------------------
damnedlies/settings_tests.py | 1 +
2 files changed, 34 insertions(+), 37 deletions(-)
---
diff --git a/common/tests.py b/common/tests.py
index 88a4b9cf..d41d42b6 100644
--- a/common/tests.py
+++ b/common/tests.py
@@ -1,11 +1,11 @@
import operator
from datetime import datetime, timedelta
-from unittest import skipUnless
+from unittest import TestCase, skipUnless
from unittest.mock import MagicMock, patch
from django.conf import settings
from django.core.management import call_command
-from django.test import TestCase
+from django.test import TestCase as DjangoTestCase
from django.utils import translation
from people.models import Person
@@ -14,47 +14,41 @@ from teams.models import Team, Role
from .utils import lc_sorted, pyicu_present, trans_sort_object_list
-class CommonTest(TestCase):
-
- def setUp(self):
- self.pn = Person(first_name='John', last_name='Note',
- email='jn devnull com', username= 'jn', activation_key='a_activation_key')
- self.pn.save()
- self.pn.set_password('password')
-
- self.pr = Person(first_name='John', last_name='Reviewer',
- username='jr', date_joined=datetime.now()-timedelta(days=11),
- activation_key='non-activated-key') # non-activeted person
- self.pr.save()
-
- self.pt = Person(first_name='John', last_name='Translator',
- username='jt', last_login=datetime.now()-timedelta(days=30*6+1),) # inactive person
- self.pt.save()
-
- self.t1 = Team(name='fr', description='French')
- self.t1.save()
-
- self.t2 = Team(name='fr2', description='French')
- self.t2.save()
-
- self.r1 = Role(team=self.t1, person=self.pt)
- self.r1.save()
-
- self.r2 = Role(team=self.t2, person=self.pt)
- self.r2.save()
+class CommonTest(DjangoTestCase):
def test_house_keeping(self):
+ pn = Person.objects.create(
+ first_name='John', last_name='Note',
+ email='jn devnull com', username='jn', activation_key='a_activation_key'
+ )
+ pn.set_password('password')
+
+ # Unactivated person
+ Person.objects.create(
+ first_name='John', last_name='Reviewer',
+ username='jr', date_joined=datetime.now() - timedelta(days=11),
+ activation_key='non-activated-key'
+ )
+
+ inactive = Person.objects.create(
+ first_name='John', last_name='Translator',
+ username='jt', last_login=datetime.now() - timedelta(days=30*6+1),
+ )
+
+ t1 = Team.objects.create(name='fr', description='French')
+ t2 = Team.objects.create(name='fr2', description='French')
+
+ Role.objects.create(team=t1, person=inactive)
+ Role.objects.create(team=t2, person=inactive)
+
response = self.client.get('/register/activate/a_activation_key', follow=True)
self.assertContains(response, 'Your account has been activated.')
call_command('run-maintenance')
# Testing if the non-activated accounts were deleted
- jn = Person.objects.filter(first_name='John', last_name='Note')
- self.assertEqual(jn.count(), 1)
-
- jr = Person.objects.filter(first_name='John', last_name='Reviewer')
- self.assertEqual(jr.count(), 0)
+ self.assertTrue(Person.objects.filter(last_name='Note').exists())
+ self.assertFalse(Person.objects.filter(last_name='Reviewer').exists())
# Testing if the inactive roles were updated
jt = Person.objects.get(first_name='John', last_name='Translator')
@@ -101,8 +95,10 @@ class LcSortedTest(TestCase):
def test_lc_sorted_with_custom_key(self):
mykey = operator.itemgetter(1)
with translation.override('fr'):
- self.assertEqual([('z', 'a'), ('a', 'z')],
- lc_sorted([('a', 'z'), ('z', 'a')], key=mykey))
+ self.assertEqual(
+ [('z', 'a'), ('a', 'z')],
+ lc_sorted([('a', 'z'), ('z', 'a')], key=mykey)
+ )
class TransSortObjectListTest(TestCase):
diff --git a/damnedlies/settings_tests.py b/damnedlies/settings_tests.py
index c21b3cd4..04f1d7ea 100644
--- a/damnedlies/settings_tests.py
+++ b/damnedlies/settings_tests.py
@@ -6,3 +6,4 @@ SECRET_KEY = 'shRc(?sk+sW3Wqn-lBvs=r52a@#hgC9g'
SCRATCHDIR = os.path.join(BASE_DIR, 'scratch')
POTDIR = os.path.join(SCRATCHDIR, "POT")
+GETTEXT_ITS_DATA = {}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]