Commit b794e7e3 by Alex Gaynor

Fix up the tests.

parent 3b9cffb0
...@@ -3,7 +3,8 @@ from django.contrib.contenttypes.models import ContentType ...@@ -3,7 +3,8 @@ from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.generic import GenericForeignKey from django.contrib.contenttypes.generic import GenericForeignKey
from django.db import models, IntegrityError, transaction from django.db import models, IntegrityError, transaction
from django.template.defaultfilters import slugify from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _, ugettext
class Tag(models.Model): class Tag(models.Model):
name = models.CharField(verbose_name=_('Name'), max_length=100) name = models.CharField(verbose_name=_('Name'), max_length=100)
...@@ -52,7 +53,10 @@ class TaggedItemBase(models.Model): ...@@ -52,7 +53,10 @@ class TaggedItemBase(models.Model):
tag = models.ForeignKey(Tag, related_name="%(app_label)s_%(class)s_items") tag = models.ForeignKey(Tag, related_name="%(app_label)s_%(class)s_items")
def __unicode__(self): def __unicode__(self):
return _("%(object)s tagged with %(tag)s") % { 'object': self.content_object, 'tag': self.tag } return ugettext("%(object)s tagged with %(tag)s") % {
"object": self.content_object,
"tag": self.tag
}
class Meta: class Meta:
abstract = True abstract = True
...@@ -80,7 +84,8 @@ class TaggedItemBase(models.Model): ...@@ -80,7 +84,8 @@ class TaggedItemBase(models.Model):
class TaggedItem(TaggedItemBase): class TaggedItem(TaggedItemBase):
object_id = models.IntegerField(verbose_name=_('Object id')) object_id = models.IntegerField(verbose_name=_('Object id'))
content_type = models.ForeignKey(ContentType, verbose_name=_('Content type'), related_name="tagged_items") content_type = models.ForeignKey(ContentType, verbose_name=_('Content type'),
related_name="tagged_items")
content_object = GenericForeignKey() content_object = GenericForeignKey()
class Meta: class Meta:
......
...@@ -16,6 +16,10 @@ class Pet(models.Model): ...@@ -16,6 +16,10 @@ class Pet(models.Model):
tags = TaggableManager() tags = TaggableManager()
def __unicode__(self):
return self.name
class HousePet(Pet): class HousePet(Pet):
trained = models.BooleanField() trained = models.BooleanField()
...@@ -37,6 +41,10 @@ class DirectPet(models.Model): ...@@ -37,6 +41,10 @@ class DirectPet(models.Model):
tags = TaggableManager(through=TaggedPet) tags = TaggableManager(through=TaggedPet)
def __unicode__(self):
return self.name
class DirectHousePet(DirectPet): class DirectHousePet(DirectPet):
trained = models.BooleanField() trained = models.BooleanField()
...@@ -58,5 +66,8 @@ class CustomPKPet(models.Model): ...@@ -58,5 +66,8 @@ class CustomPKPet(models.Model):
tags = TaggableManager(through=TaggedCustomPKPet) tags = TaggableManager(through=TaggedCustomPKPet)
def __unicode__(self):
return self.name
class CustomPKHousePet(CustomPKPet): class CustomPKHousePet(CustomPKPet):
trained = models.BooleanField() trained = models.BooleanField()
...@@ -183,6 +183,16 @@ class TaggableManagerTestCase(BaseTaggingTestCase): ...@@ -183,6 +183,16 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
['scary'] ['scary']
) )
def test_taggeditem_unicode(self):
ross = self.pet_model.objects.create(name="ross")
# I keep Ross Perot for a pet, what's it to you?
ross.tags.add("president")
self.assertEqual(
unicode(self.taggeditem_model.objects.all()[0]),
"ross tagged with president"
)
class TaggableManagerDirectTestCase(TaggableManagerTestCase): class TaggableManagerDirectTestCase(TaggableManagerTestCase):
food_model = DirectFood food_model = DirectFood
...@@ -209,7 +219,7 @@ class TaggableFormTestCase(BaseTaggingTestCase): ...@@ -209,7 +219,7 @@ class TaggableFormTestCase(BaseTaggingTestCase):
self.assertEqual(self.form_class.base_fields.keys(), ['name', 'tags']) self.assertEqual(self.form_class.base_fields.keys(), ['name', 'tags'])
f = self.form_class({'name': 'apple', 'tags': 'green, red, yummy'}) f = self.form_class({'name': 'apple', 'tags': 'green, red, yummy'})
self.assertEqual(str(f), """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>\n<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="green, red, yummy" id="id_tags" /></td></tr>""") self.assertEqual(str(f), """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>\n<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>""")
f.save() f.save()
apple = self.food_model.objects.get(name='apple') apple = self.food_model.objects.get(name='apple')
self.assert_tags_equal(apple.tags.all(), ['green', 'red', 'yummy']) self.assert_tags_equal(apple.tags.all(), ['green', 'red', 'yummy'])
...@@ -225,11 +235,11 @@ class TaggableFormTestCase(BaseTaggingTestCase): ...@@ -225,11 +235,11 @@ class TaggableFormTestCase(BaseTaggingTestCase):
self.assert_tags_equal(raspberry.tags.all(), []) self.assert_tags_equal(raspberry.tags.all(), [])
f = self.form_class(instance=apple) f = self.form_class(instance=apple)
self.assertEqual(str(f), """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>\n<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="delicious green red yummy" id="id_tags" /></td></tr>""") self.assertEqual(str(f), """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>\n<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="delicious green red yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>""")
apple.tags.add('has,comma') apple.tags.add('has,comma')
f = self.form_class(instance=apple) f = self.form_class(instance=apple)
self.assertEqual(str(f), """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>\n<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="&quot;has,comma&quot; delicious green red yummy" id="id_tags" /></td></tr>""") self.assertEqual(str(f), """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>\n<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="&quot;has,comma&quot; delicious green red yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>""")
class TaggableFormDirectTestCase(TaggableFormTestCase): class TaggableFormDirectTestCase(TaggableFormTestCase):
......
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