Commit 6781567d by Carl Meyer

custom-pk tests

parent 15645ff6
from taggit.tests.tests import (TaggableManagerTestCase, TaggableManagerDirectTestCase,
TaggableFormTestCase, TaggableFormDirectTestCase)
from taggit.tests.tests import (TaggableManagerTestCase, TaggableFormTestCase,
TaggableManagerDirectTestCase,
TaggableFormDirectTestCase,
TaggableManagerCustomPKTestCase,
TaggableFormCustomPKTestCase)
from django import forms
from taggit.tests.models import Food, DirectFood
from taggit.tests.models import Food, DirectFood, CustomPKFood
class FoodForm(forms.ModelForm):
......@@ -10,3 +10,7 @@ class FoodForm(forms.ModelForm):
class DirectFoodForm(forms.ModelForm):
class Meta:
model = DirectFood
class CustomPKFoodForm(forms.ModelForm):
class Meta:
model = CustomPKFood
......@@ -19,6 +19,8 @@ class Pet(models.Model):
class HousePet(Pet):
trained = models.BooleanField()
# test direct-tagging with custom through model
class TaggedFood(TaggedItemBase):
content_object = models.ForeignKey('DirectFood')
......@@ -37,3 +39,24 @@ class DirectPet(models.Model):
class DirectHousePet(DirectPet):
trained = models.BooleanField()
# test custom through model to model with custom PK
class TaggedCustomPKFood(TaggedItemBase):
content_object = models.ForeignKey('CustomPKFood')
class CustomPKFood(models.Model):
name = models.CharField(max_length=50, primary_key=True)
tags = TaggableManager(through=TaggedCustomPKFood)
class TaggedCustomPKPet(TaggedItemBase):
content_object = models.ForeignKey('CustomPKPet')
class CustomPKPet(models.Model):
name = models.CharField(max_length=50, primary_key=True)
tags = TaggableManager(through=TaggedCustomPKPet)
class CustomPKHousePet(CustomPKPet):
trained = models.BooleanField()
......@@ -4,8 +4,12 @@ from contextlib import contextmanager
from django.test import TestCase
from taggit.models import Tag, TaggedItem
from taggit.tests.forms import FoodForm, DirectFoodForm
from taggit.tests.models import Food, Pet, HousePet, DirectFood, DirectPet, DirectHousePet, TaggedPet
from taggit.tests.forms import FoodForm, DirectFoodForm, CustomPKFoodForm
from taggit.tests.models import (Food, Pet, HousePet,
DirectFood, DirectPet, DirectHousePet,
TaggedPet,
CustomPKFood, CustomPKPet, CustomPKHousePet,
TaggedCustomPKPet)
class BaseTaggingTest(TestCase):
......@@ -86,7 +90,7 @@ class TaggableManagerTestCase(BaseTaggingTest):
def test_delete_bulk(self):
apple = self.food_model.objects.create(name="apple")
kitty = self.pet_model.objects.create(id=apple.pk, name="kitty")
kitty = self.pet_model.objects.create(pk=apple.pk, name="kitty")
apple.tags.add("red", "delicious", "fruit")
kitty.tags.add("feline")
......@@ -168,6 +172,12 @@ class TaggableManagerDirectTestCase(TaggableManagerTestCase):
housepet_model = DirectHousePet
taggeditem_model = TaggedPet
class TaggableManagerCustomPKTestCase(TaggableManagerTestCase):
food_model = CustomPKFood
pet_model = CustomPKPet
housepet_model = CustomPKHousePet
taggeditem_model = TaggedCustomPKPet
class TaggableFormTestCase(BaseTaggingTest):
form_class = FoodForm
......@@ -198,3 +208,7 @@ class TaggableFormTestCase(BaseTaggingTest):
class TaggableFormDirectTestCase(TaggableFormTestCase):
form_class = DirectFoodForm
food_model = DirectFood
class TaggableFormCustomPKTestCase(TaggableFormTestCase):
form_class = CustomPKFoodForm
food_model = CustomPKFood
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