Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Gender.FEMALE,
Gender.MALE,
],
)
def test_full_name(self, person, gender):
result = person.full_name(gender=gender)
result = result.split(' ')
assert result[0] is not None
assert result[1] is not None
result = person.full_name(reverse=True)
assert result is not None
with pytest.raises(NonEnumerableError):
person.full_name(gender='nil')
from mimesis_factory import MimesisField
class Guest(object):
def __init__(self, full_name, patronymic):
self.full_name = full_name
self.patronymic = patronymic
@register
class FactoryWithNoProviders(factory.Factory):
class Meta(object):
model = Guest
full_name = MimesisField('full_name', gender=Gender.FEMALE)
patronymic = MimesisField('patronymic')
@register
class FactoryWithProviders(factory.Factory):
class Meta(object):
model = Guest
class Params(object):
providers = (builtins.RussiaSpecProvider,)
full_name = MimesisField('full_name', gender=Gender.FEMALE)
patronymic = MimesisField('patronymic')
def test_factory_with_not_extended_providers(factory_with_no_providers):
(Gender.FEMALE, 'female'),
(None, ['female', 'male']),
],
)
def test_validate_enum(self, base_data_provider, gender, excepted):
result = base_data_provider._validate_enum(gender, Gender)
assert (result == excepted) or (result in excepted)
assert result in [item.value for item in Gender]
with pytest.raises(NonEnumerableError):
base_data_provider._validate_enum('', '')
MIN_AGE = 30
MAX_AGE = 32
class Guest(object):
def __init__(self, full_name, age):
self.full_name = full_name
self.age = age
@register
class GuestFactory(factory.Factory):
class Meta(object):
model = Guest
full_name = MimesisField('full_name', gender=Gender.FEMALE)
age = MimesisField('age', minimum=MIN_AGE, maximum=MAX_AGE)
def test_guest_factory_different_data(guest_factory):
guest1 = guest_factory()
guest2 = guest_factory()
assert isinstance(guest1, Guest)
assert isinstance(guest2, Guest)
assert guest1 != guest2
assert guest1.full_name != guest2.full_name
assert MIN_AGE <= guest1.age <= MAX_AGE
assert MIN_AGE <= guest2.age <= MAX_AGE
def test_guest_factory_create_batch(guest_factory):
def test_name(self, p1, p2):
assert p1.name() == p2.name()
assert p1.name(gender=Gender.FEMALE) == \
p2.name(gender=Gender.FEMALE)
return lambda: {
'id': field('uuid'),
'name': field('word'),
'version': field(
'version', key=str.lower, pre_release=True,
),
'timestamp': field('timestamp'),
'mime_type': field('mime_type'),
'zip_code': field('postal_code'),
'owner': {
'email': field('email', key=str.lower),
'token': field('token_hex'),
'creator': field(
'full_name', gender=Gender.FEMALE,
),
'billing': {
'ethereum_address': field('ethereum_address'),
},
},
'defined_cls': {
'title': field('person.title'),
'title2': field('text.title'),
},
'items': field(
'choice', items=[
.1, .3, .4,
.5, .6, .7,
.8, .9, .10,
]),
'unique_items': field(
Gender.FEMALE,
],
)
def test_credit_card_owner(self, payment, gender):
result = payment.credit_card_owner(gender=gender)
assert isinstance(result, dict)
assert 'owner' in result
assert 'credit_card' in result
assert 'expiration_date' in result
def test_credit_card_owner(self, p1, p2):
assert p1.credit_card_owner() == p2.credit_card_owner()
assert p1.credit_card_owner(gender=Gender.FEMALE) == \
p2.credit_card_owner(gender=Gender.FEMALE)
month += 80
elif 2000 <= year <= 2099:
month += 20
elif 2100 <= year <= 2199:
month += 40
elif 2200 <= year <= 2299:
month += 60
pesel_digits += [int(d) for d in '{:02d}'.format(month)]
pesel_digits += [int(d) for d in '{:02d}'.format(day)]
series_number = self.random.randint(0, 999)
pesel_digits += [int(d) for d in '{:03d}'.format(series_number)]
if gender == Gender.MALE:
gender_digit = self.random.choice((1, 3, 5, 7, 9))
elif gender == Gender.FEMALE:
gender_digit = self.random.choice((0, 2, 4, 6, 8))
else:
gender_digit = self.random.choice(range(10))
pesel_digits.append(gender_digit)
pesel_coeffs = (9, 7, 3, 1, 9, 7, 3, 1, 9, 7)
sum_v = sum([nc * nd for nc, nd in
zip(pesel_coeffs, pesel_digits)])
checksum_digit = sum_v % 10
pesel_digits.append(checksum_digit)
return ''.join(str(d) for d in pesel_digits)