Example #1
0
    def _setup_items_with_tags(self):
        self.item.tags.add(self.tag1)

        ignored_model = IgnoreTestItem(name="ignore_me")
        ignored_model.save()
        ignored_model.tags.add(self.tag1)

        item2 = TestItem(name="test-item-2")
        item2.save()
        item2.tags.add(self.tag1)
Example #2
0
 def test_get_tagged_items(self):
     self.item.tags.add(self.tag1)
     item_model_name = self.item.__class__.__name__.lower()
     # Create a model that should be ignored
     ignored_model = IgnoreTestItem(name="ignore_me")
     ignored_model.save()
     ignored_model.tags.add(self.tag1)
     ignored_model_name = ignored_model.__class__.__name__.lower()
     # first check the default call returns both
     items = self.tag1.tagged_items()
     self.assertTrue(self.item in items[item_model_name])
     self.assertTrue(ignored_model in items[ignored_model_name])
     # now ignore the model and check that its not returned
     items = self.tag1.tagged_items(ignore_models=[ignored_model_name])
     self.assertTrue(self.item in items[item_model_name])
     self.assertTrue(ignored_model_name not in items.keys())
Example #3
0
    def test_get_tagged_items_filter(self):
        self.item.tags.add(self.tag1)
        item_model_name = self.item.__class__.__name__.lower()
        # Create a model that should be ignored
        ignored_model = IgnoreTestItem(name="ignore_me")
        ignored_model.save()
        ignored_model.tags.add(self.tag1)
        ignored_model_name = ignored_model.__class__.__name__.lower()

        # first check the default call returns both
        items = self.tag1.tagged_items()
        self.assertTrue(self.item in list(items[item_model_name].all()))
        self.assertTrue(ignored_model in list(items[ignored_model_name].all()))

        # now retrieve only the selected models
        items = self.tag1.tagged_items(models=[TestItem])
        self.assertTrue(self.item in list(items[item_model_name].all()))
        self.assertFalse(ignored_model_name in items.keys())
        items = self.tag1.tagged_items(models=[IgnoreTestItem])
        self.assertFalse(item_model_name in items.keys())
        self.assertTrue(ignored_model in list(items[ignored_model_name].all()))
        items = self.tag1.tagged_items(models=[IgnoreTestItem, TestItem])
        self.assertTrue(self.item in list(items[item_model_name].all()))
        self.assertTrue(ignored_model in list(items[ignored_model_name].all()))