mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Switched setUp() to setUpTestData() where possible in Django's tests.
This commit is contained in:
parent
9a7d336c38
commit
84e7a9f4a7
49 changed files with 421 additions and 334 deletions
|
@ -138,14 +138,15 @@ class TestSaveLoad(PostgreSQLTestCase):
|
|||
|
||||
class TestQuerying(PostgreSQLTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.objs = [
|
||||
NullableIntegerArrayModel.objects.create(field=[1]),
|
||||
NullableIntegerArrayModel.objects.create(field=[2]),
|
||||
NullableIntegerArrayModel.objects.create(field=[2, 3]),
|
||||
NullableIntegerArrayModel.objects.create(field=[20, 30, 40]),
|
||||
NullableIntegerArrayModel.objects.create(field=None),
|
||||
]
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.objs = NullableIntegerArrayModel.objects.bulk_create([
|
||||
NullableIntegerArrayModel(field=[1]),
|
||||
NullableIntegerArrayModel(field=[2]),
|
||||
NullableIntegerArrayModel(field=[2, 3]),
|
||||
NullableIntegerArrayModel(field=[20, 30, 40]),
|
||||
NullableIntegerArrayModel(field=None),
|
||||
])
|
||||
|
||||
def test_exact(self):
|
||||
self.assertSequenceEqual(
|
||||
|
@ -368,16 +369,17 @@ class TestQuerying(PostgreSQLTestCase):
|
|||
|
||||
class TestDateTimeExactQuerying(PostgreSQLTestCase):
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
now = timezone.now()
|
||||
self.datetimes = [now]
|
||||
self.dates = [now.date()]
|
||||
self.times = [now.time()]
|
||||
self.objs = [
|
||||
cls.datetimes = [now]
|
||||
cls.dates = [now.date()]
|
||||
cls.times = [now.time()]
|
||||
cls.objs = [
|
||||
DateTimeArrayModel.objects.create(
|
||||
datetimes=self.datetimes,
|
||||
dates=self.dates,
|
||||
times=self.times,
|
||||
datetimes=cls.datetimes,
|
||||
dates=cls.dates,
|
||||
times=cls.times,
|
||||
)
|
||||
]
|
||||
|
||||
|
@ -402,17 +404,18 @@ class TestDateTimeExactQuerying(PostgreSQLTestCase):
|
|||
|
||||
class TestOtherTypesExactQuerying(PostgreSQLTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.ips = ['192.168.0.1', '::1']
|
||||
self.uuids = [uuid.uuid4()]
|
||||
self.decimals = [decimal.Decimal(1.25), 1.75]
|
||||
self.tags = [Tag(1), Tag(2), Tag(3)]
|
||||
self.objs = [
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.ips = ['192.168.0.1', '::1']
|
||||
cls.uuids = [uuid.uuid4()]
|
||||
cls.decimals = [decimal.Decimal(1.25), 1.75]
|
||||
cls.tags = [Tag(1), Tag(2), Tag(3)]
|
||||
cls.objs = [
|
||||
OtherTypesArrayModel.objects.create(
|
||||
ips=self.ips,
|
||||
uuids=self.uuids,
|
||||
decimals=self.decimals,
|
||||
tags=self.tags,
|
||||
ips=cls.ips,
|
||||
uuids=cls.uuids,
|
||||
decimals=cls.decimals,
|
||||
tags=cls.tags,
|
||||
)
|
||||
]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue