summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2018-11-24 06:28:28 -0500
committerTim Graham <timograham@gmail.com>2018-11-27 09:48:22 -0500
commit7f63b894c02effb09c15ab0b40d28b89553b8e37 (patch)
tree03802b01266db92834562ae80cf73c97b0cb8f5a
parent84e7a9f4a7bb3cad2bffae97baaae99de152c451 (diff)
Adjusted code style of a few test data setup methods.
Thanks Mariusz for suggesting it.
-rw-r--r--tests/admin_inlines/tests.py6
-rw-r--r--tests/admin_views/tests.py13
-rw-r--r--tests/foreign_object/tests.py5
-rw-r--r--tests/m2o_recursive/tests.py15
-rw-r--r--tests/postgres_tests/test_array.py6
-rw-r--r--tests/properties/tests.py3
-rw-r--r--tests/sites_tests/tests.py6
7 files changed, 18 insertions, 36 deletions
diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py
index 9ba9bd279e..bad1986fd0 100644
--- a/tests/admin_inlines/tests.py
+++ b/tests/admin_inlines/tests.py
@@ -31,7 +31,7 @@ class TestInline(TestDataMixin, TestCase):
def setUpTestData(cls):
super().setUpTestData()
cls.holder = Holder.objects.create(dummy=13)
- Inner(dummy=42, holder=cls.holder).save()
+ Inner.objects.create(dummy=42, holder=cls.holder)
def setUp(self):
self.client.force_login(self.superuser)
@@ -572,9 +572,7 @@ class TestInlinePermissions(TestCase):
@classmethod
def setUpTestData(cls):
- cls.user = User(username='admin')
- cls.user.is_staff = True
- cls.user.is_active = True
+ cls.user = User(username='admin', is_staff=True, is_active=True)
cls.user.set_password('secret')
cls.user.save()
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 8f486b93fe..fb10f485cd 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -3691,10 +3691,12 @@ class AdminInlineFileUploadTest(TestCase):
file1.write(b'a' * (2 ** 21))
filename = file1.name
file1.close()
- cls.gallery = Gallery(name="Test Gallery")
- cls.gallery.save()
- cls.picture = Picture(name="Test Picture", image=filename, gallery=cls.gallery)
- cls.picture.save()
+ cls.gallery = Gallery.objects.create(name='Test Gallery')
+ cls.picture = Picture.objects.create(
+ name='Test Picture',
+ image=filename,
+ gallery=cls.gallery,
+ )
def setUp(self):
self.client.force_login(self.superuser)
@@ -3736,8 +3738,7 @@ class AdminInlineTests(TestCase):
@classmethod
def setUpTestData(cls):
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
- cls.collector = Collector(pk=1, name='John Fowles')
- cls.collector.save()
+ cls.collector = Collector.objects.create(pk=1, name='John Fowles')
def setUp(self):
self.post_data = {
diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py
index 2469250a12..7fed5557eb 100644
--- a/tests/foreign_object/tests.py
+++ b/tests/foreign_object/tests.py
@@ -24,10 +24,7 @@ class MultiColumnFKTests(TestCase):
cls.usa = Country.objects.create(name="United States of America")
cls.soviet_union = Country.objects.create(name="Soviet Union")
# Creating People
- cls.bob = Person()
- cls.bob.name = 'Bob'
- cls.bob.person_country = cls.usa
- cls.bob.save()
+ cls.bob = Person.objects.create(name='Bob', person_country=cls.usa)
cls.jim = Person.objects.create(name='Jim', person_country=cls.usa)
cls.george = Person.objects.create(name='George', person_country=cls.usa)
diff --git a/tests/m2o_recursive/tests.py b/tests/m2o_recursive/tests.py
index 309b61f260..95b60a8e49 100644
--- a/tests/m2o_recursive/tests.py
+++ b/tests/m2o_recursive/tests.py
@@ -7,10 +7,8 @@ class ManyToOneRecursiveTests(TestCase):
@classmethod
def setUpTestData(cls):
- cls.r = Category(id=None, name='Root category', parent=None)
- cls.r.save()
- cls.c = Category(id=None, name='Child category', parent=cls.r)
- cls.c.save()
+ cls.r = Category.objects.create(id=None, name='Root category', parent=None)
+ cls.c = Category.objects.create(id=None, name='Child category', parent=cls.r)
def test_m2o_recursive(self):
self.assertQuerysetEqual(self.r.child_set.all(),
@@ -25,12 +23,9 @@ class MultipleManyToOneRecursiveTests(TestCase):
@classmethod
def setUpTestData(cls):
- cls.dad = Person(full_name='John Smith Senior', mother=None, father=None)
- cls.dad.save()
- cls.mom = Person(full_name='Jane Smith', mother=None, father=None)
- cls.mom.save()
- cls.kid = Person(full_name='John Smith Junior', mother=cls.mom, father=cls.dad)
- cls.kid.save()
+ cls.dad = Person.objects.create(full_name='John Smith Senior', mother=None, father=None)
+ cls.mom = Person.objects.create(full_name='Jane Smith', mother=None, father=None)
+ cls.kid = Person.objects.create(full_name='John Smith Junior', mother=cls.mom, father=cls.dad)
def test_m2o_recursive2(self):
self.assertEqual(self.kid.mother.id, self.mom.id)
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index f878ad3fb5..447d511c9f 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -376,11 +376,7 @@ class TestDateTimeExactQuerying(PostgreSQLTestCase):
cls.dates = [now.date()]
cls.times = [now.time()]
cls.objs = [
- DateTimeArrayModel.objects.create(
- datetimes=cls.datetimes,
- dates=cls.dates,
- times=cls.times,
- )
+ DateTimeArrayModel.objects.create(datetimes=cls.datetimes, dates=cls.dates, times=cls.times),
]
def test_exact_datetimes(self):
diff --git a/tests/properties/tests.py b/tests/properties/tests.py
index 38f39a1dbb..ce29668644 100644
--- a/tests/properties/tests.py
+++ b/tests/properties/tests.py
@@ -7,8 +7,7 @@ class PropertyTests(TestCase):
@classmethod
def setUpTestData(cls):
- cls.a = Person(first_name='John', last_name='Lennon')
- cls.a.save()
+ cls.a = Person.objects.create(first_name='John', last_name='Lennon')
def test_getter(self):
self.assertEqual(self.a.full_name, 'John Lennon')
diff --git a/tests/sites_tests/tests.py b/tests/sites_tests/tests.py
index 95b4373642..c5e20b4549 100644
--- a/tests/sites_tests/tests.py
+++ b/tests/sites_tests/tests.py
@@ -22,11 +22,7 @@ class SitesFrameworkTests(TestCase):
@classmethod
def setUpTestData(cls):
- cls.site = Site(
- id=settings.SITE_ID,
- domain="example.com",
- name="example.com",
- )
+ cls.site = Site(id=settings.SITE_ID, domain='example.com', name='example.com')
cls.site.save()
def tearDown(self):