Commit f3a2ce5a by Alex Gaynor

Make this test be transactional.

parent b3f9995b
from taggit.tests.tests import (TaggableManagerTestCase, TaggableFormTestCase,
TaggableManagerDirectTestCase, TaggableFormDirectTestCase,
TaggableManagerCustomPKTestCase, TaggableFormCustomPKTestCase)
DATABASE_ENGINE = 'sqlite3' DATABASE_ENGINE = 'sqlite3'
INSTALLED_APPS = [ INSTALLED_APPS = [
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'taggit', 'taggit',
......
from django.test import TestCase from django.test import TestCase, TransactionTestCase
from taggit.models import Tag, TaggedItem from taggit.models import Tag, TaggedItem
from taggit.tests.forms import FoodForm, DirectFoodForm, CustomPKFoodForm from taggit.tests.forms import FoodForm, DirectFoodForm, CustomPKFoodForm
...@@ -7,7 +7,7 @@ from taggit.tests.models import (Food, Pet, HousePet, DirectFood, DirectPet, ...@@ -7,7 +7,7 @@ from taggit.tests.models import (Food, Pet, HousePet, DirectFood, DirectPet,
TaggedCustomPKPet) TaggedCustomPKPet)
class BaseTaggingTest(TestCase): class BaseTaggingTest(object):
def assert_tags_equal(self, qs, tags, sort=True): def assert_tags_equal(self, qs, tags, sort=True):
got = map(lambda tag: tag.name, qs) got = map(lambda tag: tag.name, qs)
if sort: if sort:
...@@ -15,8 +15,28 @@ class BaseTaggingTest(TestCase): ...@@ -15,8 +15,28 @@ class BaseTaggingTest(TestCase):
tags.sort() tags.sort()
self.assertEqual(got, tags) self.assertEqual(got, tags)
class BaseTaggingTestCase(TestCase, BaseTaggingTest):
pass
class BaseTaggingTransactionTestCase(TransactionTestCase, BaseTaggingTest):
pass
class TaggableManagerTestCase(BaseTaggingTest):
class TagModelTestCase(BaseTaggingTransactionTestCase):
food_model = Food
def test_unique_slug(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add("Red", "red")
class TagModelDirectTestCase(TagModelTestCase):
food_model = DirectFood
class TagModelCustomPKTestCase(TagModelTestCase):
food_model = CustomPKFood
class TaggableManagerTestCase(BaseTaggingTestCase):
food_model = Food food_model = Food
pet_model = Pet pet_model = Pet
housepet_model = HousePet housepet_model = HousePet
...@@ -60,10 +80,6 @@ class TaggableManagerTestCase(BaseTaggingTest): ...@@ -60,10 +80,6 @@ class TaggableManagerTestCase(BaseTaggingTest):
food_instance = self.food_model() food_instance = self.food_model()
self.assertRaises(ValueError, lambda: food_instance.tags.all()) self.assertRaises(ValueError, lambda: food_instance.tags.all())
def test_unique_slug(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add("Red", "red")
def test_delete_obj(self): def test_delete_obj(self):
apple = self.food_model.objects.create(name="apple") apple = self.food_model.objects.create(name="apple")
apple.tags.add("red") apple.tags.add("red")
...@@ -168,7 +184,7 @@ class TaggableManagerCustomPKTestCase(TaggableManagerTestCase): ...@@ -168,7 +184,7 @@ class TaggableManagerCustomPKTestCase(TaggableManagerTestCase):
# tell if the instance is saved or not # tell if the instance is saved or not
pass pass
class TaggableFormTestCase(BaseTaggingTest): class TaggableFormTestCase(BaseTaggingTestCase):
form_class = FoodForm form_class = FoodForm
food_model = Food food_model = Food
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment