def test_duplicate_slug(self): from wagtail.wagtailcore.models import Site # Create a test Site with a root page root = models.TestRootPage(title='title', depth=1, path='0001', slug_en='slug_en', slug_de='slug_de') root.save() site = Site(root_page=root) site.save() # Add children to the root child = root.add_child( instance=models.TestSlugPage1(title='child1', slug_de='child', slug_en='child-en', depth=2, path='00010001') ) child2 = root.add_child( instance=models.TestSlugPage2(title='child2', slug_de='child-2', slug_en='child2-en', depth=2, path='00010002') ) # Clean should work fine as the two slugs are different child2.clean() # Make the slug equal to test if the duplicate is detected child2.slug_de = 'child' self.assertRaises(ValidationError, child2.clean)
def test_relative_url(self): try: from wagtail.core.models import Site except ImportError: from wagtail.wagtailcore.models import Site # Create a test Site with a root page root = models.TestRootPage(title='title slugurl', depth=1, path='0004', slug_en='title_slugurl_en', slug_de='title_slugurl_de') root.save() site = Site(root_page=root) site.save() # Add children to the root child = root.add_child( instance=models.TestSlugPage1(title='child1 slugurl', slug_en='child-slugurl-en', slug_de='child-slugurl-de', depth=2, path='00040001')) child.save_revision().publish() url_1_de = child.relative_url(site) self.assertEqual( url_1_de, '/de/child-slugurl-de/', 'When using the default language, slugurl produces the wrong url.') trans_real.activate('en') url_1_en = child.relative_url(site) self.assertEqual( url_1_en, '/en/child-slugurl-en/', 'When using non-default language, slugurl produces the wrong url.') # Add children using non-default language child2 = root.add_child( instance=models.TestSlugPage2(title='child2 slugurl', title_de='child2 slugurl DE', slug_de='child2-slugurl-de', slug_en='child2-slugurl-en', depth=2, path='00040002')) child2.save_revision().publish() url_2_en = child2.relative_url(site) self.assertEqual( url_2_en, '/en/child2-slugurl-en/', 'When using non-default language, slugurl produces the wrong url.') trans_real.activate('de') url_2_de = child2.relative_url(site) self.assertEqual( url_2_de, '/de/child2-slugurl-de/', 'When using non-default language, slugurl produces the wrong url.')