Beispiel #1
0
    def test_category_two_deep(self):
        child_category = Category(name='Child category')
        child_category.parent = self.category
        child_category.save()

        self.category.refresh_from_db()
        self.assertEqual(1, self.category.children.count())
Beispiel #2
0
    def test_category_three_deep_as_grandchild(self):
        child_category = Category(name='Child category')
        child_category.parent = self.category
        child_category.save()

        grand_child_category = Category(name='Grandchild category')
        grand_child_category.parent = child_category

        self.assertRaises(ValidationError, grand_child_category.save)
Beispiel #3
0
    def test_slug_only_created_once(self):
        just_a_slug = slugify('just a slug')

        category = Category(slug=just_a_slug,
                            name='This will generate the slug only once')

        category.save()
        category.refresh_from_db()

        slug = slugify(category.name)

        self.assertNotEqual(just_a_slug, category.slug)
        self.assertEqual(slug, category.slug)
        self.assertEqual('This will generate the slug only once',
                         category.name)

        category.name = 'And now for something completely different'
        category.save()
        category.refresh_from_db()

        self.assertEqual(slug, category.slug)
        self.assertEqual('And now for something completely different',
                         category.name)

        this_should_not_be_the_slug = slugify(category.name)
        self.assertNotEqual(this_should_not_be_the_slug, category.slug)

        with self.assertRaises(ValidationError):
            category.slug = just_a_slug
            category.save()

        with self.assertRaises(ValidationError):
            category.save(slug='no-saving-me-please')