class AbstractUserFactory(DjangoModelFactory): """Abstract factory for creating users.""" password = PostGenerationMethodCall("set_password", TEST_PASSWORD) username = Sequence(lambda n: "user%d" % n) first_name = Faker("first_name") last_name = Faker("last_name") # first_name = Faker('first_name_max_length_30') # last_name = Faker('last_name_max_length_30') email = Faker("ascii_safe_email") is_active = False is_staff = False is_superuser = False class Meta(object): """Meta options.""" model = settings.AUTH_USER_MODEL django_get_or_create = ("username",) abstract = True @post_generation def groups(obj, created, extracted, **kwargs): """Create Group objects for the created User instance.""" if created: # Create from 1 to 7 ``Group`` objects. amount = random.randint(1, 5) groups = LimitedGroupFactory.create_batch(amount) obj.groups.add(*groups)
class UserFactory(DjangoModelFactory): class Meta: model = User username = Sequence(lambda n: 'user%d' % n) password = PostGenerationMethodCall('set_password', 'test') email = LazyAttribute(lambda u: '*****@*****.**' % u.username)
class UserFactory(DjangoModelFactory): name = Faker('name_male') email = Faker('email') password = PostGenerationMethodCall('set_unusable_password') is_active = True class Meta: model = User
class UserFactory(BaseFactory): username = Sequence(lambda n: f'user{n}') email = Sequence(lambda n: f'user{n}@example.com') password = PostGenerationMethodCall('set_password', 'example') class Meta: model = User
class UserFactory(DjangoModelFactory): """Factory Boy factory for Improved User Generates a user with a default password of ``password!``. The user is active, but is not staff or a superuser. Any value can be overridden by passing in a value, as shown below. .. code:: python UserFactory( password='******', is_superuser=True, ) """ class Meta: """Configuration Options""" model = User email = Faker("email") password = PostGenerationMethodCall("set_password", "password!") full_name = Faker("name") short_name = Faker("first_name") is_active = True is_staff = False is_superuser = False
class UserFactory(DjangoModelFactory): username = Faker('uuid4') password = PostGenerationMethodCall('set_password', 'password') is_staff = False class Meta: model = User
class UserFactory(DjangoModelFactory): FACTORY_FOR = User username = Sequence(u'robot{0}'.format) email = Sequence(u'robot+test+{0}@edx.org'.format) password = PostGenerationMethodCall('set_password', 'test') first_name = Sequence(u'Robot{0}'.format) last_name = 'Test' is_staff = False is_active = True is_superuser = False last_login = datetime(2012, 1, 1) date_joined = datetime(2011, 1, 1) @post_generation def profile(obj, create, extracted, **kwargs): if create: obj.save() return UserProfileFactory.create(user=obj, **kwargs) elif kwargs: raise Exception( "Cannot build a user profile without saving the user") else: return None
class UserFactory(BaseFactory): FACTORY_FOR = User username = Sequence(lambda n: "user{0}".format(n)) email = Sequence(lambda n: "user{0}@example.com".format(n)) password = PostGenerationMethodCall('set_password', 'example') active = True
def create_users(self, num): # Create random users. # All users have the password 'codebuddies'. return [ UserFactory(password=PostGenerationMethodCall( 'set_password', 'codebuddies')) for _ in range(0, num) ]
class UserFactory(DjangoModelFactory): class Meta: model = User username = "******" email = "*****@*****.**" password = PostGenerationMethodCall("set_password", "123")
class UserFactory(DjangoModelFactory): """ Factory for default Django User model. Calls full_clean before saving to ensure that generated User instance is valid. """ class Meta: model = get_user_model() email = LazyFunction(faker.safe_email) first_name = LazyFunction(faker.first_name) last_name = LazyFunction(faker.last_name) password = PostGenerationMethodCall('set_password', 'password') @lazy_attribute def username(self): """ Create a username from faker's profile generator, but ensure that it's not in the database before using it. This is a pre-full_clean check. Uses a simple single uniqueness check, cached against a set of already tried names. 200 max tries is on the username generation, not the round trip to the database - although that could be changed if required. Raises: RuntimeError: If a unique username can not be found after 200 retries. """ unique_usernames = unique_username() non_uniques = set() for _ in range(max_retries): username = next(unique_usernames) username_unique = (username not in non_uniques and get_user_model().objects.filter( username=username).count() == 0) if username_unique: return username non_uniques.add(username) else: non_uniques_str = ', '.join( ['"{}"'.format(name) for name in non_uniques]) message = ( 'Unique username not found after 200 tries. Unique values tried: {}' ).format(non_uniques_str) raise RuntimeError(message) @post_generation def z_full_clean(self, create, extracted, **kwargs): """ Assert that created User is "clean" in Django's opinion if build strategy is happening. NOTE: function name is prefixed with 'z_' so that it runs after the 'password' post generation function. Raises: ValidationError: If there are any invalid fields in the final User object. """ if create: self.full_clean()
class UserFactory(BaseFactory): email = Sequence(lambda n: "user{0}@example.com".format(n)) password = PostGenerationMethodCall('set_password', 'example') active = True class Meta: model = User
class UserFactory(DjangoModelFactory): class Meta: model = User username = '******' email = '*****@*****.**' password = PostGenerationMethodCall('set_password', '123')
class UserFactory(BaseFactory): class Meta: model = User email = Sequence(lambda n: 'user{0}@example.com'.format(n)) password = PostGenerationMethodCall('set_password', 'password') first_name = "Joe" last_name = "Lock"
class UserFactory(DjangoModelFactory): class Meta: model = User username = Sequence(lambda n: u"User{0}".format(n, "%03d")) first_name = username last_name = u"Smith" password = PostGenerationMethodCall('set_password', 'frog')
class UserFactory(SQLAlchemyModelFactory): class Meta: model = User username = factory.LazyAttribute(lambda x: "sally" + faker.last_name()) #uuid = factory.LazyAttribute(lambda x: str(uuid.uuid4())) email = factory.LazyAttribute(lambda x: faker.email()) password = PostGenerationMethodCall('set_password', 'password') #
class UserFactory(BaseFactory): id = Sequence(lambda n: n) username = Sequence(lambda n: 'user{0}'.format(n)) email = Sequence(lambda n: 'user{0}@example.com'.format(n)) password = PostGenerationMethodCall('set_password', 'example') class Meta: model = User
class UserFactory(DjangoModelFactory): class Meta: model = User django_get_or_create = ('username', ) username = Sequence(lambda x: u'user %d' % x) is_superuser = True password = PostGenerationMethodCall('set_password', 'password')
class MeFactory(SQLAlchemyModelFactory): class Meta: model = User username = factory.LazyAttribute(lambda x: get_authable_username()) #uuid = factory.LazyAttribute(lambda x: str(uuid.uuid4())) email = factory.LazyAttribute(lambda x: get_authable_email()) password = PostGenerationMethodCall('set_password', 'password')
class UserFactory(DjangoModelFactory): class Meta: model = User username = Faker('email') password = PostGenerationMethodCall('set_password', 'qweqweqwe') email = LazyAttribute(lambda u: u.username) date_joined = LazyFunction(timezone.now)
class DemoUserFactory(DjangoModelFactory): username = Sequence(lambda n: "User %03d" % n) password = PostGenerationMethodCall("set_password", "password") is_staff = True is_active = True class Meta: model = get_user_model()
class UserFactory(SQLAlchemyModelFactory): FACTORY_SESSION = db.session FACTORY_FOR = User username = Sequence(lambda n: "user{0}".format(n)) email = Sequence(lambda n: "user{0}@example.com".format(n)) password = PostGenerationMethodCall("set_password", 'example') active = True
class UserFactory(DjangoModelFactory): username = Sequence(lambda n: "usr_%03d" % n) email = Sequence(lambda n: "*****@*****.**" % n) password = PostGenerationMethodCall('set_password', DEFAULT_USER_PASSWORD) is_active = True class Meta: model = 'auth.User'
class UserFactory(DjangoModelFactory): class Meta: model = User first_name = Faker('first_name') last_name = Faker('last_name') username = Faker('user_name') password = PostGenerationMethodCall('set_password', 'password') is_active = True
class UserFactory(DjangoModelFactory): name = Faker('name') email = Faker('email') password = PostGenerationMethodCall("set_password", "password") is_commerce = True id = str(uuid.uuid1()) class Meta: model = User
class VoucherFactory(BaseFactory): """Voucher factory.""" password = PostGenerationMethodCall("set_password", "example") class Meta: """Factory configuration.""" model = Voucher
class UserWebFactory(DjangoModelFactory): username = Sequence(lambda n: 'user_name_%d' % n) email = Sequence(lambda n: '*****@*****.**' % n) password = PostGenerationMethodCall('set_password', 'seed') is_active = True is_superuser = False class Meta: model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
class CommonUserFactory(django.DjangoModelFactory): class Meta: model = CommonUser first_name = Faker('first_name') last_name = Faker('last_name') email = Faker('email') password = PostGenerationMethodCall('set_password', 'password') phone_number = Faker('msisdn')
class UserFactory(DjangoModelFactory): email = '*****@*****.**' password = PostGenerationMethodCall('set_password', 'password') department = SubFactory(DepartmentFactory) is_active = True class Meta: model = User
class SimpleUserFactory(DjangoModelFactory): username = Faker("user_name") email = Faker("email") name = Faker("name") password = PostGenerationMethodCall('set_password', 'password') class Meta: model = get_user_model() django_get_or_create = ('username', )