class TestTaggedContentItem(TestCase): """ Test the features of TaggedContentItem, anything that is tagged in some way and which will automatically assign itself tags. """ def setUp(self): self.tci = TCI() self.tci.save() self.tci.associate_auto_tags() self.tci.save() def test_gen_tag_string(self): tag_str = self.tci.self_tag_string self.assertEquals(tag_str, '*TCI:tci-slug') def test_make_self_tag_name(self): name = self.tci._make_self_tag_name() self.assertEquals(name, 'tci-slug') def test_self_autotag(self): """Test method which returns object's own unique auto tag""" auto_tag = self.tci.self_auto_tag self.assertEquals(auto_tag, Tag.objects.get(slug='tci-slug')) def test_auto_tag_creation(self): self.tci.associate_auto_tags() at = self.tci.auto_tags.all() self.assertEquals(len(at), 1) tag = at[0] self.assertEquals(tag.group.name, 'TCI') self.assertEquals(tag.name, 'tci-slug') self.assertEquals(tag.system, True) def test_get_auto_tagged_items(self): self.tci.associate_auto_tags() auto_tag = self.tci.auto_tags.all()[0] tci_models = auto_tag.tagged_model_items(model_cls=self.tci.__class__) self.assertTrue(self.tci in tci_models) def test_get_tci_from_auto_tag(self): """ Test the Tag.auto_tagged_model_items method by looking to retrieve our TCI based on its auto-tag. """ auto_tag = Tag.objects.get(slug='tci-slug') item_set = auto_tag.auto_tagged_model_items(model_cls=TCI) self.assertEquals(len(item_set), 1) self.assertEquals(item_set.pop(), self.tci)
def setUp(self): self.tci = TCI() self.tci.save() self.tci.associate_auto_tags() self.tci.save()
class TestTaggedContentItem(TestCase): """ Test the features of TaggedContentItem, anything that is tagged in some way and which will automatically assign itself tags. """ def setUp(self): self.tci = TCI() self.tci.save() self.tci.associate_auto_tags() self.tci.save() def test_gen_tag_string(self): tag_str = self.tci.self_tag_string self.assertEquals(tag_str, '*TCI:tci-slug') def test_make_self_tag_name(self): name = self.tci._make_self_tag_name() self.assertEquals(name, 'tci-slug') def test_self_autotag(self): """Test method which returns object's own unique auto tag""" auto_tag = self.tci.self_auto_tag self.assertEquals(auto_tag, Tag.objects.get(slug='tci-slug')) def test_auto_tag_creation(self): self.tci.associate_auto_tags() at = self.tci.auto_tags.all() self.assertEquals(len(at), 1) tag = at[0] self.assertEquals(tag.group.name, 'TCI') self.assertEquals(tag.name, 'tci-slug') self.assertEquals(tag.system, True) def test_get_auto_tagged_items(self): self.tci.associate_auto_tags() auto_tag = self.tci.auto_tags.all()[0] tci_models = list( auto_tag.auto_tagged_model_items (model_cls=self.tci.__class__).all() ) self.assertTrue(self.tci in tci_models) def test_get_tci_from_auto_tag(self): """ Test the Tag.auto_tagged_model_items method by looking to retrieve our TCI based on its auto-tag. """ auto_tag = Tag.objects.get(slug='tci-slug') item_set = set(auto_tag.auto_tagged_model_items(model_cls=TCI).all()) self.assertEquals(len(item_set), 1) self.assertEquals(item_set.pop(), self.tci) def test_tci_change_name_updates_tag_not_add(self): """ If the slug for an item changes, it's self tag should be updated - a new tag should not be made """ self.tci.associate_auto_tags() auto_tags = self.tci.auto_tags.all() self.assertEquals(len(auto_tags), 1) self.assertEquals(auto_tags[0].name, "tci-slug") # now re-name our content item self.tci.slug = "new-tci-slug" self.tci.save() self.tci.associate_auto_tags() auto_tags = self.tci.auto_tags.all() self.assertEquals(len(auto_tags), 1) self.assertEquals(auto_tags[0].name, "new-tci-slug") self.assertEquals(auto_tags[0].slug, "new-tci-slug")