Commit 162f0857 by Florian Apolloner

Test fixes and more 1.7 fixes.

parent 94485073
...@@ -301,7 +301,8 @@ class TaggableManager(RelatedField, Field): ...@@ -301,7 +301,8 @@ class TaggableManager(RelatedField, Field):
self.use_gfk = ( self.use_gfk = (
self.through is None or issubclass(self.through, GenericTaggedItemBase) self.through is None or issubclass(self.through, GenericTaggedItemBase)
) )
self.rel.to = self.through._meta.get_field("tag").rel.to if not self.rel.to:
self.rel.to = self.through._meta.get_field("tag").rel.to
self.related = RelatedObject(self.through, cls, self) self.related = RelatedObject(self.through, cls, self)
if self.use_gfk: if self.use_gfk:
tagged_items = GenericRelation(self.through) tagged_items = GenericRelation(self.through)
......
...@@ -22,8 +22,8 @@ from taggit.models import Tag, TaggedItem ...@@ -22,8 +22,8 @@ from taggit.models import Tag, TaggedItem
from .forms import (FoodForm, DirectFoodForm, CustomPKFoodForm, from .forms import (FoodForm, DirectFoodForm, CustomPKFoodForm,
OfficialFoodForm) OfficialFoodForm)
from .models import (Food, Pet, HousePet, DirectFood, DirectPet, from .models import (Food, Pet, HousePet, DirectFood, DirectPet,
DirectHousePet, TaggedPet, CustomPKFood, CustomPKPet, CustomPKHousePet, DirectHousePet, TaggedFood, CustomPKFood, CustomPKPet, CustomPKHousePet,
TaggedCustomPKPet, OfficialFood, OfficialPet, OfficialHousePet, TaggedCustomPKFood, OfficialFood, OfficialPet, OfficialHousePet,
OfficialThroughModel, OfficialTag, Photo, Movie, Article, CustomManager) OfficialThroughModel, OfficialTag, Photo, Movie, Article, CustomManager)
from taggit.utils import parse_tags, edit_string_for_tags from taggit.utils import parse_tags, edit_string_for_tags
...@@ -298,13 +298,12 @@ class TaggableManagerTestCase(BaseTaggingTestCase): ...@@ -298,13 +298,12 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
) )
def test_taggeditem_unicode(self): def test_taggeditem_unicode(self):
ross = self.pet_model.objects.create(name="ross") apple = self.food_model.objects.create(name="apple")
# I keep Ross Perot for a pet, what's it to you? apple.tags.add("juicy")
ross.tags.add("president")
self.assertEqual( self.assertEqual(
force_text(self.taggeditem_model.objects.all()[0]), force_text(self.taggeditem_model.objects.all()[0]),
"ross tagged with president" "apple tagged with juicy"
) )
def test_abstract_subclasses(self): def test_abstract_subclasses(self):
...@@ -364,13 +363,13 @@ class TaggableManagerDirectTestCase(TaggableManagerTestCase): ...@@ -364,13 +363,13 @@ class TaggableManagerDirectTestCase(TaggableManagerTestCase):
food_model = DirectFood food_model = DirectFood
pet_model = DirectPet pet_model = DirectPet
housepet_model = DirectHousePet housepet_model = DirectHousePet
taggeditem_model = TaggedPet taggeditem_model = TaggedFood
class TaggableManagerCustomPKTestCase(TaggableManagerTestCase): class TaggableManagerCustomPKTestCase(TaggableManagerTestCase):
food_model = CustomPKFood food_model = CustomPKFood
pet_model = CustomPKPet pet_model = CustomPKPet
housepet_model = CustomPKHousePet housepet_model = CustomPKHousePet
taggeditem_model = TaggedCustomPKPet taggeditem_model = TaggedCustomPKFood
def test_require_pk(self): def test_require_pk(self):
# TODO with a charfield pk, pk is never None, so taggit has no way to # TODO with a charfield pk, pk is never None, so taggit has no way to
...@@ -557,10 +556,11 @@ class TagStringParseTestCase(UnitTestCase): ...@@ -557,10 +556,11 @@ class TagStringParseTestCase(UnitTestCase):
@skipIf(django.VERSION < (1, 7), "not relevant for Django < 1.7") @skipIf(django.VERSION < (1, 7), "not relevant for Django < 1.7")
class DeconstructTestCase(UnitTestCase): class DeconstructTestCase(UnitTestCase):
def test_deconstruct_kwargs_kept(self): def test_deconstruct_kwargs_kept(self):
instance = TaggableManager(through=OfficialThroughModel) instance = TaggableManager(through=OfficialThroughModel, to='dummy.To')
name, path, args, kwargs = instance.deconstruct() name, path, args, kwargs = instance.deconstruct()
new_instance = TaggableManager(*args, **kwargs) new_instance = TaggableManager(*args, **kwargs)
self.assertEqual(instance.rel.through, new_instance.rel.through) self.assertEqual('tests.OfficialThroughModel', new_instance.rel.through)
self.assertEqual('dummy.To', new_instance.rel.to)
@skipUnless(django.VERSION < (1, 7), "test only applies to 1.6 and below") @skipUnless(django.VERSION < (1, 7), "test only applies to 1.6 and below")
......
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