def test_existing_object(self): simple = Simple() simple.set_current_language('en') simple.save() # slug is now the default simple.name = 'A new name' simple.slug = None simple.save() self.assertEquals('a-new-name', simple.slug)
def test_existing_object(self): simple = Simple() simple.set_current_language('en') simple.save() # slug is now the default simple.name = 'A new name' simple.slug = None simple.save() self.assertEquals('a-new-name', simple.slug)
class SimpleTestMixin(TestUtilityMixin): """This mixin adds data and methods useful for testing Things.""" data = { 'simple1': { 'de': { 'name': 'Objekt eins', }, 'en': { 'name': 'Simple one', }, 'fr': { 'name': 'objet un' }, }, 'simple2': { 'de': { 'name': 'Objekt zwei', }, 'en': { 'name': 'Simple two', }, 'fr': { 'name': 'objet deux', }, }, 'untranslated1': { 'name': 'Untranslated Object', 'slug': 'untranslated-object', } } simple1 = None simple2 = None untranslated1 = None def setUp(self): super(SimpleTestMixin, self).setUp() with override('de'): self.simple1 = Simple() self.simple1.name = self.data['simple1']['de']['name'] self.simple1.save() self.simple2 = Simple() self.simple2.name = self.data['simple2']['de']['name'] self.simple2.save() for lc in ['en', 'fr']: with switch_language(self.simple1, lc): self.simple1.name = self.data['simple1'][lc]['name'] self.simple1.save() with switch_language(self.simple2, lc): self.simple2.name = self.data['simple2'][lc]['name'] self.simple2.save() if not self.untranslated1: self.untranslated1 = Untranslated(**self.data['untranslated1']) self.untranslated1.save()
def setUp(self): super(SimpleTestMixin, self).setUp() with override('de'): self.simple1 = Simple() self.simple1.name = self.data['simple1']['de']['name'] self.simple1.save() self.simple2 = Simple() self.simple2.name = self.data['simple2']['de']['name'] self.simple2.save() for lc in ['en', 'fr']: with switch_language(self.simple1, lc): self.simple1.name = self.data['simple1'][lc]['name'] self.simple1.save() with switch_language(self.simple2, lc): self.simple2.name = self.data['simple2'][lc]['name'] self.simple2.save() if not self.untranslated1: self.untranslated1 = Untranslated(**self.data['untranslated1']) self.untranslated1.save()
def test_limited_length(self): Simple.slug_max_length = 6 try: for r in range(0, 101): simple = Simple() simple.set_current_language('en') simple.name = 'Simple' simple.save() except: self.fail() Simple.slug_max_length = None
def setUp(self): super(SimpleTestMixin, self).setUp() with override('de'): self.simple1 = Simple() self.simple1.name = self.data['simple1']['de']['name'] self.simple1.save() self.simple2 = Simple() self.simple2.name = self.data['simple2']['de']['name'] self.simple2.save() for lc in ['en', 'fr']: with switch_language(self.simple1, lc): self.simple1.name = self.data['simple1'][lc]['name'] self.simple1.save() with switch_language(self.simple2, lc): self.simple2.name = self.data['simple2'][lc]['name'] self.simple2.save() if not self.untranslated1: self.untranslated1 = Untranslated(**self.data['untranslated1']) self.untranslated1.save()
class SimpleTestMixin(TestUtilityMixin): """This mixin adds data and methods useful for testing Things.""" data = { 'simple1': { 'de': {'name': 'Objekt eins', }, 'en': {'name': 'Simple one', }, 'fr': {'name': 'objet un'}, }, 'simple2': { 'de': {'name': 'Objekt zwei', }, 'en': {'name': 'Simple two', }, 'fr': {'name': 'objet deux', }, }, 'untranslated1': { 'name': 'Untranslated Object', 'slug': 'untranslated-object', } } simple1 = None simple2 = None untranslated1 = None def setUp(self): super(SimpleTestMixin, self).setUp() with override('de'): self.simple1 = Simple() self.simple1.name = self.data['simple1']['de']['name'] self.simple1.save() self.simple2 = Simple() self.simple2.name = self.data['simple2']['de']['name'] self.simple2.save() for lc in ['en', 'fr']: with switch_language(self.simple1, lc): self.simple1.name = self.data['simple1'][lc]['name'] self.simple1.save() with switch_language(self.simple2, lc): self.simple2.name = self.data['simple2'][lc]['name'] self.simple2.save() if not self.untranslated1: self.untranslated1 = Untranslated(**self.data['untranslated1']) self.untranslated1.save()
def test_limited_length(self): Simple.slug_max_length = 6 try: for r in range(0, 101): simple = Simple() simple.set_current_language('en') simple.name = 'Simple' simple.save() except Exception: self.fail() Simple.slug_max_length = None
def test_slug_unique_for_language_if_slug_is_the_same(self): simple_en_1 = Simple() simple_en_1.set_current_language('en') simple_en_1.name = 'SimpleOne' simple_en_1.slug = 'simpleone' simple_en_1.save() # make another instance with same name simple_en_2 = Simple() simple_en_2.set_current_language('en') simple_en_2.name = 'SimpleOne' simple_en_2.slug = 'simpleone' simple_en_2.save() # slugs should not be same. self.assertNotEquals(simple_en_1.slug, simple_en_2.slug)
def test_slug_unique_global(self): Simple.slug_globally_unique = True simple_en = Simple() simple_en.set_current_language('en') simple_en.name = 'SimpleOne' simple_en.save() simple_fr = Simple() simple_fr.set_current_language('fr') simple_fr.name = 'SimpleOne' simple_fr.save() self.assertNotEquals(simple_en.slug, simple_fr.slug) Simple.slug_globally_unique = None # default is False simple_en = Simple() simple_en.set_current_language('en') simple_en.name = 'SimpleTwo' simple_en.save() simple_fr = Simple() simple_fr.set_current_language('fr') simple_fr.name = 'SimpleTwo' simple_fr.save() self.assertEquals(simple_en.slug, simple_fr.slug)
def test_simple_slug(self): simple = Simple() simple.set_current_language('en') simple.name = 'Simple' simple.save() self.assertEquals(simple.slug, 'simple')
def test_simple_slug_default(self): # First test that the default works simple = Simple() simple.set_current_language('en') simple.save() self.assertEquals( 'simple-without-name', simple.get_slug_default()) # Also test without explicit language self.assertEquals( 'simple-without-name', simple.get_slug_default()) # Now test that a default would be used if available Simple.slug_default = _('unnamed-simple-object') simple = Simple() simple.set_current_language('en') simple.save() self.assertEquals( 'unnamed-simple-object', simple.get_slug_default()) # Also test without explicit language self.assertEquals( 'unnamed-simple-object', simple.get_slug_default())
def test_slug_unique_for_language_if_slug_is_the_same(self): simple_en_1 = Simple() simple_en_1.set_current_language('en') simple_en_1.name = 'SimpleOne' simple_en_1.slug = 'simpleone' simple_en_1.save() # make another instance with same name simple_en_2 = Simple() simple_en_2.set_current_language('en') simple_en_2.name = 'SimpleOne' simple_en_2.slug = 'simpleone' simple_en_2.save() # slugs should not be same. self.assertNotEquals(simple_en_1.slug, simple_en_2.slug)
def test_slug_unique_global(self): Simple.slug_globally_unique = True simple_en = Simple() simple_en.set_current_language('en') simple_en.name = 'SimpleOne' simple_en.save() simple_fr = Simple() simple_fr.set_current_language('fr') simple_fr.name = 'SimpleOne' simple_fr.save() self.assertNotEquals(simple_en.slug, simple_fr.slug) Simple.slug_globally_unique = None # default is False simple_en = Simple() simple_en.set_current_language('en') simple_en.name = 'SimpleTwo' simple_en.save() simple_fr = Simple() simple_fr.set_current_language('fr') simple_fr.name = 'SimpleTwo' simple_fr.save() self.assertEquals(simple_en.slug, simple_fr.slug)
def test_simple_slug_default(self): # First test that the default works simple = Simple() simple.set_current_language('en') simple.save() self.assertEquals('simple-without-name', simple.get_slug_default()) # Also test without explicit language self.assertEquals('simple-without-name', simple.get_slug_default()) # Now test that a default would be used if available Simple.slug_default = _('unnamed-simple-object') simple = Simple() simple.set_current_language('en') simple.save() self.assertEquals('unnamed-simple-object', simple.get_slug_default()) # Also test without explicit language self.assertEquals('unnamed-simple-object', simple.get_slug_default())
def test_simple_slug(self): simple = Simple() simple.set_current_language('en') simple.name = 'Simple' simple.save() self.assertEquals(simple.slug, 'simple')