1
0
mirror of https://github.com/django/django.git synced 2025-03-13 19:00:45 +00:00

Used setupTestData in m2m_through tests.

This commit is contained in:
Simon Charette 2015-11-04 11:14:22 +01:00
parent 7b8e4545c3
commit 5ccb7f5f22

View File

@ -13,12 +13,13 @@ from .models import (
class M2mThroughTests(TestCase): class M2mThroughTests(TestCase):
def setUp(self): @classmethod
self.bob = Person.objects.create(name='Bob') def setUpTestData(cls):
self.jim = Person.objects.create(name='Jim') cls.bob = Person.objects.create(name='Bob')
self.jane = Person.objects.create(name='Jane') cls.jim = Person.objects.create(name='Jim')
self.rock = Group.objects.create(name='Rock') cls.jane = Person.objects.create(name='Jane')
self.roll = Group.objects.create(name='Roll') cls.rock = Group.objects.create(name='Rock')
cls.roll = Group.objects.create(name='Roll')
def test_retrieve_intermediate_items(self): def test_retrieve_intermediate_items(self):
Membership.objects.create(person=self.jim, group=self.rock) Membership.objects.create(person=self.jim, group=self.rock)
@ -432,14 +433,15 @@ class M2mThroughReferentialTests(TestCase):
class M2mThroughToFieldsTests(TestCase): class M2mThroughToFieldsTests(TestCase):
def setUp(self): @classmethod
self.pea = Ingredient.objects.create(iname='pea') def setUpTestData(cls):
self.potato = Ingredient.objects.create(iname='potato') cls.pea = Ingredient.objects.create(iname='pea')
self.tomato = Ingredient.objects.create(iname='tomato') cls.potato = Ingredient.objects.create(iname='potato')
self.curry = Recipe.objects.create(rname='curry') cls.tomato = Ingredient.objects.create(iname='tomato')
RecipeIngredient.objects.create(recipe=self.curry, ingredient=self.potato) cls.curry = Recipe.objects.create(rname='curry')
RecipeIngredient.objects.create(recipe=self.curry, ingredient=self.pea) RecipeIngredient.objects.create(recipe=cls.curry, ingredient=cls.potato)
RecipeIngredient.objects.create(recipe=self.curry, ingredient=self.tomato) RecipeIngredient.objects.create(recipe=cls.curry, ingredient=cls.pea)
RecipeIngredient.objects.create(recipe=cls.curry, ingredient=cls.tomato)
def test_retrieval(self): def test_retrieval(self):
# Forward retrieval # Forward retrieval