Пример #1
0
    def setUp(self):
        self.group = TagGroup(name="normal group", system=False)
        self.group.save()

        self.tag_a = Tag(group=self.group, name="tag a")
        self.tag_b = Tag(group=self.group, name="TAG b")
        self.tag_a.save()
        self.tag_b.save()
Пример #2
0
 def test_denormalised_system_flag(self):
     """
     Does tag reflect its group's system flag
     """
     tag = Tag(group=self.groupc, name="foo")
     tag.save()
     self.assertFalse(self.tag1.group_is_system)
     self.assertFalse(self.tag1.system)
     self.assertTrue(tag.group_is_system)
     self.assertTrue(tag.system)
Пример #3
0
    def test_unique_tag_in_group(self):
        tag1_clone = Tag(group=self.group, name=self.tag1.name)
        self.assertRaises(IntegrityError, tag1_clone.save)

        # ... also test to see if we can make a tag with the same name as
        # tag1 but a different group. This must now be allowed.
        tag1_noclone = Tag(group=self.groupb, name=self.tag1.name)
        try:
            tag1_noclone.save()
        except IntegrityError, ie:
            self.fail("Unique constraint on group,name fails: {0}"
                      .format(str(ie)))
Пример #4
0
 def setUp(self):
     self.group = TagGroup(name="test-group")
     self.group.save()
     self.groupb = TagGroup(name="test-group-b")
     self.groupb.save()
     self.groupc = TagGroup(name="system-group", system=True)
     self.groupc.save()
     self.tag1 = Tag(group=self.group, name="test-tag1")
     self.tag1.save()
     self.tag2 = Tag(group=self.group, name="test-tag2")
     self.tag2.save()
     self.item = TestItem(name="test-item")
     self.item.save()
     self.tags = [self.tag1, self.tag2]
Пример #5
0
class TestSlugification(TestCase):
    def setUp(self):
        self.group = TagGroup(name="normal group", system=False)
        self.group.save()

        self.tag_a = Tag(group=self.group, name="tag a")
        self.tag_b = Tag(group=self.group, name="TAG b")
        self.tag_a.save()
        self.tag_b.save()

    def test_slug_values_a(self):
        self.assertEquals(self.tag_a.slug, "tag-a")

    def test_slug_values_b(self):
        self.assertEquals(self.tag_b.slug, "tag-b")
Пример #6
0
 def test_get_tags_for_string(self):
     string = ""
     for idx, tag in enumerate(self.tags):
         self.group.tag_set.add(tag)
         string += "%s%s" % (str(tag), ","
                   if idx + 1 is not len(self.tags) else "")
     self.assertTrue([tag for tag in Tag.tags_for_string(string)
                      if tag in self.tags])
Пример #7
0
class TestTags(TestCase):

    def setUp(self):
        self.group = TagGroup(name="test-group")
        self.group.save()
        self.groupb = TagGroup(name="test-group-b")
        self.groupb.save()
        self.groupc = TagGroup(name="system-group", system=True)
        self.groupc.save()
        self.tag1 = Tag(group=self.group, name="test-tag1")
        self.tag1.save()
        self.tag2 = Tag(group=self.group, name="test-tag2")
        self.tag2.save()
        self.item = TestItem(name="test-item")
        self.item.save()
        self.tags = [self.tag1, self.tag2]

    def test_create_tag(self):
        self.assertIsNotNone(self.tag1.pk)

    def test_create_group(self):
        self.assertIsNotNone(self.group.pk)

    def test_add_tag_to_item(self):
        [self.item.tags.add(tag) for tag in self.tags]
        self.assertTrue([tag for tag in self.item.tags.all()
                        if tag in self.tags])

    def test_tags_in_group(self):
        [self.group.tag_set.add(tag) for tag in self.tags]
        self.assertTrue([tag for tag in self.group.tags_for_group()
                         if tag in self.tags])

    def test_unique_tag_in_group(self):
        tag1_clone = Tag(group=self.group, name=self.tag1.name)
        self.assertRaises(IntegrityError, tag1_clone.save)

        # ... also test to see if we can make a tag with the same name as
        # tag1 but a different group. This must now be allowed.
        tag1_noclone = Tag(group=self.groupb, name=self.tag1.name)
        try:
            tag1_noclone.save()
        except IntegrityError, ie:
            self.fail("Unique constraint on group,name fails: {0}"
                      .format(str(ie)))
Пример #8
0
 def test_get_tag_for_string(self):
     self.group.tag_set.add(self.tag1)
     self.assertTrue(self.tag1 == Tag.tag_for_string(str(self.tag1)))
Пример #9
0
 def test_unique_tag_in_system_group(self):
     tag = Tag(group=self.groupc, name="foo")
     tag.save()
     tagb = Tag(group=self.groupc, name="foo")
     self.assertRaises(IntegrityError, tagb.save)
Пример #10
0
 def test_tag_for_string_system_group(self):
     t = Tag.tag_for_string("*system_group:tag_a")
     self.assertEquals(t, self.tag_a)
Пример #11
0
 def test_repr_system_tag(self):
     tag = Tag(group=self.groupc, name="foo")
     tag.save()
     self.assertEquals(repr(tag), "system-group:foo")
Пример #12
0
 def test_unicode_system_tag(self):
     tag = Tag(group=self.groupc, name="foo")
     tag.save()
     self.assertEquals(str(tag), "*system-group:foo")
Пример #13
0
class TestTags(TestCase):

    def setUp(self):
        self.group = TagGroup(name="test-group")
        self.group.save()
        self.groupb = TagGroup(name="test-group-b")
        self.groupb.save()
        self.groupc = TagGroup(name="system-group", system=True)
        self.groupc.save()
        self.tag1 = Tag(group=self.group, name="test-tag1")
        self.tag1.save()
        self.tag2 = Tag(group=self.group, name="test-tag2")
        self.tag2.save()
        self.item = TestItem(name="test-item")
        self.item.save()
        self.tags = [self.tag1, self.tag2]

    def test_create_tag(self):
        self.assertIsNotNone(self.tag1.pk)

    def test_create_group(self):
        self.assertIsNotNone(self.group.pk)

    def test_group_name(self):
        """
        Test that the group name is correctly saved on tag

        This is inserted at time of re-factoring code to de-normalise
        group name into Tag.group_name
        """
        self.assertEquals(self.tag1.group_name, self.group.name)

    def test_group_name_change(self):
        """
        Test that group name re-set on group change for tag

        Confirms that de-normalisation works when group changes
        """
        self.assertEquals(self.tag1.group_name, self.group.name)
        self.tag1.group = self.groupb
        self.tag1.save()
        self.assertEquals(self.tag1.group_name, self.groupb.name)

    def test_group_slug(self):
        """
        Test that the group slug is correctly saved on tag

        This is inserted at time of re-factoring code to de-normalise
        group slug into Tag.group_slug
        """
        self.assertEquals(self.tag1.group_slug, self.group.slug)

    def test_group_slug_change(self):
        """
        Test that group slug re-set on group change for tag

        Confirms that de-normalisation works when group changes
        """
        self.assertEquals(self.tag1.group_slug, self.group.slug)
        self.tag1.group = self.groupb
        self.tag1.save()
        self.assertEquals(self.tag1.group_slug, self.groupb.slug)

    def test_unicode(self):
        """
        Does the tag represent itself correctly when stringified
        """
        self.assertEquals(str(self.tag1), "test-group:test-tag1")

    def test_unicode_system_tag(self):
        tag = Tag(group=self.groupc, name="foo")
        tag.save()
        self.assertEquals(str(tag), "*system-group:foo")

    def test_repr_system_tag(self):
        tag = Tag(group=self.groupc, name="foo")
        tag.save()
        self.assertEquals(repr(tag), "system-group:foo")

    def test_repr(self):
        """
        Does the tag represent itself correctly
        """
        self.assertEquals(repr(self.tag1), "test-group:test-tag1")

    def test_denormalised_system_flag(self):
        """
        Does tag reflect its group's system flag
        """
        tag = Tag(group=self.groupc, name="foo")
        tag.save()
        self.assertFalse(self.tag1.group_is_system)
        self.assertFalse(self.tag1.system)
        self.assertTrue(tag.group_is_system)
        self.assertTrue(tag.system)

    def test_group_change_updates_denormalised_tags_name(self):
        """
        Change group name and check tags de-normalised fields update
        """
        self.assertEquals(str(self.tag1), "test-group:test-tag1")
        self.group.name = "new-test-group"
        self.group.save()
        tag = Tag.objects.get(name="test-tag1")
        self.assertEquals(str(tag), "new-test-group:test-tag1")

    def test_group_change_updates_denormalised_tags_slug(self):
        """
        Change group slug and check tags de-normalised fields update
        """
        self.assertEquals(self.tag1.group_slug, "test-group")
        self.group.slug = "new-test-group"
        self.group.save()
        tag = Tag.objects.get(name="test-tag1")
        self.assertEquals(tag.group_slug, "new-test-group")

    def test_group_change_updates_denormalised_tags_system(self):
        """
        Change group system and check tags de-normalised fields update
        """
        self.assertEquals(self.tag1.group_is_system, False)
        self.group.system = True
        self.group.save()
        tag = Tag.objects.get(name="test-tag1")
        self.assertEquals(tag.group_is_system, True)

    def test_add_tag_to_item(self):
        [self.item.tags.add(tag) for tag in self.tags]
        self.assertTrue([tag for tag in self.item.tags.all()
                        if tag in self.tags])

    def test_tags_in_group(self):
        [self.group.tag_set.add(tag) for tag in self.tags]
        self.assertTrue([tag for tag in self.group.tags_for_group()
                         if tag in self.tags])

    def test_unique_tag_in_group(self):
        tag1_clone = Tag(group=self.group, name=self.tag1.name)
        self.assertRaises(IntegrityError, tag1_clone.save)

        # ... also test to see if we can make a tag with the same name as
        # tag1 but a different group. This must now be allowed.
        tag1_noclone = Tag(group=self.groupb, name=self.tag1.name)
        try:
            tag1_noclone.save()
        except IntegrityError, ie:
            self.fail("Unique constraint on group,name fails: {0}"
                      .format(str(ie)))