def test_slugify(self): self.assertEqual( slugify( ' Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/' ), 'Jack-Jill-like-numbers-123-and-4-and-silly-characters-', )
def test_slugify_lazy_string(self): lazy_str = lazy(lambda string: string, str) self.assertEqual( slugify( lazy_str(' Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/')), 'Jack-Jill-like-numbers-123-and-4-and-silly-characters-', )
def validate_username(username): """ This validation step is done when we are sure the user does not exit on the systems and we need to create a new user. """ try: validate_slug(username) except ValidationError: username = slugify(username) user_model_cls = get_user_model() _username = username while user_model_cls.objects.filter(username=_username).exists(): _username = '******'.format(username, random.randint(1, 100)) return _username
def test_non_string_input(self): self.assertEqual(slugify(123), '123')
def test_unicode(self): self.assertEqual( slugify("Un \xe9l\xe9phant \xe0 l'or\xe9e du bois"), 'Un-elephant-a-loree-du-bois', )