def test_updating_subtree_slugs_when_moving_category_to_new_parent(self): trail = 'A > B > C' create_from_breadcrumbs(trail) trail = 'A > B > D' create_from_breadcrumbs(trail) trail = 'A > E > F' create_from_breadcrumbs(trail) trail = 'A > E > G' create_from_breadcrumbs(trail) trail = 'T' target = create_from_breadcrumbs(trail) category = Category.objects.get(name='A') category.move(target, pos='first-child') c1 = Category.objects.get(name='A') self.assertEqual(c1.full_slug, 't/a') self.assertEqual(c1.full_name, 'T > A') child = Category.objects.get(name='F') self.assertEqual(child.full_slug, 't/a/e/f') self.assertEqual(child.full_name, 'T > A > E > F') child = Category.objects.get(name='D') self.assertEqual(child.full_slug, 't/a/b/d') self.assertEqual(child.full_name, 'T > A > B > D')
def setUp(self): breadcrumbs = ( 'Books > Fiction > Horror > Teen', 'Books > Fiction > Horror > Gothic', 'Books > Fiction > Comedy', 'Books > Non-fiction > Biography', 'Books > Non-fiction > Programming', 'Books > Children', ) for trail in breadcrumbs: create_from_breadcrumbs(trail)
def test_can_create_multiple_categories(self): trail = 'Books > Science-Fiction > Star Trek' create_from_breadcrumbs(trail) trail = 'Books > Factual > Popular Science' category = create_from_breadcrumbs(trail) self.assertIsNotNone(category) self.assertEqual(category.name, 'Popular Science') self.assertEqual(category.get_depth(), 3) self.assertEqual(category.get_parent().name, 'Factual') self.assertEqual(5, Category.objects.count()) self.assertEqual( category.full_slug, 'books/factual/popular-science', )
def setUp(self): breadcrumbs = ( 'Books > Fiction > Horror > Teen', 'Books > Fiction > Horror > Gothic', 'Books > Fiction > Comedy', 'Books > Non-fiction > Biography', 'Books > Non-fiction > Programming', 'Books > Children', ) for trail in breadcrumbs: create_from_breadcrumbs(trail) horror = Category.objects.get(name="Horror") programming = Category.objects.get(name="Programming") horror.move(programming) # Reload horror instance to pick up changes self.horror = Category.objects.get(name="Horror")
def test_can_create_parent_and_child_categories(self): trail = 'Books > Science-Fiction' category = create_from_breadcrumbs(trail) self.assertIsNotNone(category) self.assertEqual(category.name, 'Science-Fiction') self.assertEqual(category.get_depth(), 2) self.assertEqual(category.get_parent().name, 'Books') self.assertEqual(2, Category.objects.count()) self.assertEqual(category.full_slug, 'books/science-fiction')
def test_updating_subtree_when_moving_category_to_new_sibling(self): trail = 'A > B > C' create_from_breadcrumbs(trail) trail = 'A > B > D' create_from_breadcrumbs(trail) trail = 'A > E > F' create_from_breadcrumbs(trail) trail = 'A > E > G' create_from_breadcrumbs(trail) category = Category.objects.get(name='E') target = Category.objects.get(name='A') category.move(target, pos='right') child = Category.objects.get(name='E') self.assertEqual(child.full_slug, 'e') self.assertEqual(child.full_name, 'E') child = Category.objects.get(name='F') self.assertEqual(child.full_slug, 'e/f') self.assertEqual(child.full_name, 'E > F')
def test_can_use_alternative_separator(self): trail = 'Food|Cheese|Blue' create_from_breadcrumbs(trail, separator='|') self.assertEqual(3, len(Category.objects.all()))
def test_can_create_single_level_category(self): trail = 'Books' category = create_from_breadcrumbs(trail) self.assertIsNotNone(category) self.assertEqual(category.name, 'Books') self.assertEqual(category.slug, 'books')
def setUp(self): self.staff = UserFactory(is_staff=True) create_from_breadcrumbs('A > B > C')