Exemplo n.º 1
0
    def test_unique_slugs(self):
        # create 2 sites
        site_1 = Site(id=201, domain="site1.example.com")
        site_1.save()
        site_2 = Site(id=202, domain="site2.example.com")
        site_2.save()

        # Create an object for site 1
        obj_1 = ModelBase(title='object for site 1')
        obj_1.save()
        obj_1.sites.add(site_1)
        obj_1.slug = 'generic_slug'
        obj_1.save()

        # Create an object for site 2
        obj_2 = ModelBase(title='object for site 2')
        obj_2.save()
        obj_2.sites.add(site_2)
        obj_2.slug = 'generic_slug'
        obj_2.save()

        # Trying to add site_1 should raise an error.
        with self.assertRaises(RuntimeError):
            obj_2.sites.add(site_1)
            obj_2.save()

        # When the slugs differ, you can add site_1.
        obj_2.slug = 'generic_slug_2'
        obj_2.sites.add(site_1)
        obj_2.save()

        # Trying to change the slug to an existing one should raise an error.
        with self.assertRaises(RuntimeError):
            obj_2.slug = 'generic_slug'
            obj_2.save()
Exemplo n.º 2
0
    def test_unique_slugs(self):
        obj_1 = ModelBase(title="object for site 1")
        obj_1.save()
        obj_1.sites.add(self.web_site)
        obj_1.slug = "generic_slug"
        obj_1.save()

        # Create an object for site 2
        obj_2 = ModelBase(title="object for site 2")
        obj_2.save()
        obj_2.sites.add(self.mobile_site)
        obj_2.slug = "generic_slug"
        obj_2.save()

        # Trying to add site_1 should raise an error.
        with self.assertRaises(IntegrityError):
            with transaction.atomic():
                obj_2.sites.add(self.web_site)
                obj_2.save()

        # When the slugs differ, you can add site_1.
        obj_2.slug = "generic_slug_2"
        obj_2.sites.add(self.web_site)
        obj_2.save()

        # Trying to change the slug to an existing one should raise an error.
        with self.assertRaises(IntegrityError):
            with transaction.atomic():
                obj_2.slug = "generic_slug"
                obj_2.save()
Exemplo n.º 3
0
    def test_unique_slugs(self):
        # create 2 sites
        site_1 = Site(domain="site1.example.com")
        site_1.save()
        site_2 = Site(domain="site2.example.com")
        site_2.save()

        # Create an object for site 1
        obj_1 = ModelBase(title='object for site 1')
        obj_1.save()
        obj_1.sites.add(site_1)
        obj_1.slug = 'generic_slug'
        obj_1.save()

        # Create an object for site 2
        obj_2 = ModelBase(title='object for site 2')
        obj_2.save()
        obj_2.sites.add(site_2)
        obj_2.slug = 'generic_slug'
        obj_2.save()

        # Trying to add site_1 should raise an error.
        with self.assertRaises(RuntimeError):
            obj_2.sites.add(site_1)
            obj_2.save()

        # When the slugs differ, you can add site_1.
        obj_2.slug = 'generic_slug_2'
        obj_2.sites.add(site_1)
        obj_2.save()

        # Trying to change the slug to an existing one should raise an error.
        with self.assertRaises(RuntimeError):
            obj_2.slug = 'generic_slug'
            obj_2.save()
Exemplo n.º 4
0
    def test_unique_slugs(self):
        obj_1 = ModelBase(title="object for site 1")
        obj_1.save()
        obj_1.sites.add(self.web_site)
        obj_1.slug = "generic_slug"
        obj_1.save()

        # Create an object for site 2
        obj_2 = ModelBase(title="object for site 2")
        obj_2.save()
        obj_2.sites.add(self.mobile_site)
        obj_2.slug = "generic_slug"
        obj_2.save()

        # Trying to add site_1 should raise an error.
        with self.assertRaises(IntegrityError):
            with transaction.atomic():
                obj_2.sites.add(self.web_site)
                obj_2.save()

        # When the slugs differ, you can add site_1.
        obj_2.slug = "generic_slug_2"
        obj_2.sites.add(self.web_site)
        obj_2.save()

        # Trying to change the slug to an existing one should raise an error.
        with self.assertRaises(IntegrityError):
            with transaction.atomic():
                obj_2.slug = "generic_slug"
                obj_2.save()