def test_slugify(self): slug = text.slugify("a'b/c") self.assertEqual(slug, 'abc') slug = text.slugify("àeìöú") self.assertEqual(slug, 'aeiou') slug = text.slugify("àeì.öú") self.assertEqual(slug, 'aeiou') slug = text.slugify("àeì.öú", allow_dots=True) self.assertEqual(slug, 'aei.ou') @decorators.slugify def fn(s): return s slug = fn("a'b/c") self.assertEqual(slug, 'abc') @decorators.slugify_domain def fn(s): return s slug = fn("a'b/.c") self.assertEqual(slug, 'ab.c')
def perform_create(self, serializer): serializer.context['user'] = self.request.user article = serializer.save() article.user = self.request.user if not self.request.user.is_authenticated: article.user = AppUser.objects.first() categories = self.request.get('categories', []) tags = self.request.get('tags', []) for category in categories: if hasattr(category, 'name'): article.categories.add( Category.objects.get_or_create( # name=category.name, slug=slugify(category.name), defaults={ 'description', getattr(category, 'description', '') })) for tag in tags: if hasattr(tag, 'name'): article.tags.add( Tag.objects.get_or_create( # name=tag.name, slug=slugify(tag.name), defaults={'name': tag.name, 'description': getattr(tag, 'description', '')})) article.save()
class UserFactory(factory.DjangoModelFactory): """ Factory for User accounts """ username = factory.lazy_attribute( lambda o: slugify(o.first_name + '.' + o.last_name)) email = factory.lazy_attribute(lambda o: '*****@*****.**' % o.username) mobile_number = '+919876543210' gender = fuzzy.FuzzyChoice(User.GENDER_CHOICES, getter=lambda c: c[0]) is_staff = False @lazy_attribute def first_name(self): faker = Faker() return faker.first_name_male( ) if self.gender is User.MALE else faker.first_name_female() @lazy_attribute def last_name(self): faker = Faker() return faker.last_name_male( ) if self.gender is User.MALE else faker.last_name_female() generic_cart = None class Params: has_cart = factory.Trait(generic_cart=factory.RelatedFactory( 'tests.restaurant.factories.GenericCartFactory', 'user')) class Meta: model = User
def create(self) -> User: return User( username=slugify(self.fake.name()), email=self.fake.email(), password=self.fake.password(), first_name=self.fake.first_name(), last_name=self.fake.last_name(), phone=self.fake.last_name() )
def test_internet(self): names = JaProvider.last_romanized_names domain_word = self.factory.domain_word() assert isinstance(domain_word, string_types) assert any(domain_word == text.slugify(name) for name in names) user_name = self.factory.user_name() assert isinstance(user_name, string_types) tld = self.factory.tld() assert isinstance(tld, string_types)
def test_ja_JP_internet(self): from faker.providers.person.ja_JP import Provider last_romanized_names = Provider.last_romanized_names domain_word = self.factory.domain_word() assert domain_word assert isinstance(domain_word, string_types) assert any(domain_word == text.slugify(last_romanized_name) for last_romanized_name in last_romanized_names) user_name = self.factory.user_name() assert user_name assert isinstance(user_name, string_types) tld = self.factory.tld() assert tld assert isinstance(tld, string_types)
def test_internet(self): names = JaProvider.last_romanized_names domain_word = self.factory.domain_word() self.assertIsInstance(domain_word, six.string_types) self.assertTrue(any(domain_word == text.slugify(name) for name in names)) domain_name = self.factory.domain_name() deep_domain_name = self.factory.domain_name(3) self.assertIsInstance(domain_name, six.string_types) self.assertIsInstance(deep_domain_name, six.string_types) self.assertEqual(deep_domain_name.count('.'), 3) self.assertRaises(ValueError, self.factory.domain_name, -1) user_name = self.factory.user_name() self.assertIsInstance(user_name, six.string_types) tld = self.factory.tld() self.assertIsInstance(tld, six.string_types)
def test_internet(self): names = JaProvider.last_romanized_names domain_word = self.factory.domain_word() assert isinstance(domain_word, string_types) assert any(domain_word == text.slugify(name) for name in names) domain_name = self.factory.domain_name() deep_domain_name = self.factory.domain_name(3) assert isinstance(domain_name, string_types) assert isinstance(deep_domain_name, string_types) assert deep_domain_name.count('.') == 3 self.assertRaises(ValueError, self.factory.domain_name, -1) user_name = self.factory.user_name() assert isinstance(user_name, string_types) tld = self.factory.tld() assert isinstance(tld, string_types)
def test_internet(self): names = JaProvider.last_romanized_names domain_word = self.fake.domain_word() self.assertIsInstance(domain_word, str) assert any(domain_word == text.slugify(name) for name in names) domain_name = self.fake.domain_name() deep_domain_name = self.fake.domain_name(3) self.assertIsInstance(domain_name, str) self.assertIsInstance(deep_domain_name, str) assert deep_domain_name.count('.') == 3 with pytest.raises(ValueError): self.fake.domain_name(-1) user_name = self.fake.user_name() self.assertIsInstance(user_name, str) tld = self.fake.tld() self.assertIsInstance(tld, str)
def test_internet(self, faker): names = JaPersonProvider.last_romanized_names domain_word = faker.domain_word() assert isinstance(domain_word, str) assert any(domain_word == text.slugify(name) for name in names) domain_name = faker.domain_name() deep_domain_name = faker.domain_name(3) assert isinstance(domain_name, str) assert isinstance(deep_domain_name, str) assert deep_domain_name.count('.') == 3 with pytest.raises(ValueError): faker.domain_name(-1) user_name = faker.user_name() assert isinstance(user_name, str) tld = faker.tld() assert isinstance(tld, str)
def test_slugify(self): slug = text.slugify("a'b/c") assert slug == 'abc' slug = text.slugify("àeìöú") assert slug == 'aeiou' slug = text.slugify("àeì.öú") assert slug == 'aeiou' slug = text.slugify("àeì.öú", allow_dots=True) assert slug == 'aei.ou' slug = text.slugify("àeì.öú", allow_unicode=True) assert slug == 'àeìöú' slug = text.slugify("àeì.öú", allow_unicode=True, allow_dots=True) assert slug == 'àeì.öú' @decorators.slugify def fn(s): return s slug = fn("a'b/c") assert slug == 'abc' @decorators.slugify_domain def fn(s): return s slug = fn("a'b/.c") assert slug == 'ab.c' @decorators.slugify_unicode def fn(s): return s slug = fn("a'b/.cé") assert slug == 'abcé'
def test_slugify(self): slug = text.slugify("a'b/c") self.assertEqual(slug, "abc") slug = text.slugify("àeìöú") self.assertEqual(slug, "aeiou") slug = text.slugify("àeì.öú") self.assertEqual(slug, "aeiou") slug = text.slugify("àeì.öú", allow_dots=True) self.assertEqual(slug, "aei.ou") slug = text.slugify("àeì.öú", allow_unicode=True) self.assertEqual(slug, "àeìöú") slug = text.slugify("àeì.öú", allow_unicode=True, allow_dots=True) self.assertEqual(slug, "àeì.öú") @decorators.slugify def fn(s): return s slug = fn("a'b/c") self.assertEqual(slug, "abc") @decorators.slugify_domain def fn(s): return s slug = fn("a'b/.c") self.assertEqual(slug, "ab.c") @decorators.slugify_unicode def fn(s): return s slug = fn("a'b/.cé") self.assertEqual(slug, "abcé")
def wrapper(*args, **kwargs): return text.slugify(fn(*args, **kwargs), allow_dots=True)
def wrapper(*args: Tuple[Any, ...], **kwargs: Dict[str, Any]) -> str: return text.slugify(fn(*args, **kwargs))
def wrapper(*args: Tuple[Any, ...], **kwargs: Dict[str, Any]) -> str: return text.slugify(fn(*args, **kwargs), allow_unicode=True)
def RemoveSlugify(str, allow_dots=False): #"a'b/c" => 'abc' slug = text.slugify("a'b/c", allow_dots=allow_dots) return slug
def alias(self): return slugify(self.name)
def wrapper(*args, **kwargs): return text.slugify(fn(*args, **kwargs), allow_unicode=True)
def wrapper(*args, **kwargs): return text.slugify(fn(*args, **kwargs))
def slug(self, create, extracted, **kwargs): """Slugs are derived from the copy supplied.""" if create and extracted: self.slug = slugify(self.copy)