mirror of https://github.com/django/django.git
Adjusted code style of a few test data setup methods.
Thanks Mariusz for suggesting it.
This commit is contained in:
parent
84e7a9f4a7
commit
7f63b894c0
|
@ -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()
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue