Ejemplo n.º 1
0
class ProductFactory(factories.ModelFactory):
    # Factory data for Product model.
    name = factories.Sequence(lambda n: 'Product name %03d' % n)
    price = factories.FuzzyFloat(1, 1000.0)
    quantity = factories.FuzzyInteger(50, 100)
    sold_quantity = factories.FuzzyInteger(10, 100)
    category = factories.SubFactory(CategoryFactory)
    gender = factories.SubFactory(GenderFactory)
    base_colour = factories.SubFactory(BaseColourFactory)
    season = factories.SubFactory(SeasonFactory)
    usage = factories.SubFactory(UsageFactory)
    is_published = factories.FuzzyChoice([True, False])

    class Meta:
        model = Product
        django_get_or_create = (
            'name',
            'price',
            'quantity',
            'sold_quantity',
            'category',
            'gender',
            'base_colour',
            'season',
            'usage',
            'is_published',
        )
Ejemplo n.º 2
0
class ArticleTypeFactory(factories.ModelFactory):
    # Factory data for ArticleType model.
    name = factories.Sequence(lambda n: 'ArticleType name %03d' % n)

    class Meta:
        model = ArticleType
        django_get_or_create = ('name', )
Ejemplo n.º 3
0
class GenderFactory(factories.ModelFactory):
    # Factory data for Gender model.
    name = factories.Sequence(lambda n: 'Gender name %03d' % n)

    class Meta:
        model = Gender
        django_get_or_create = ('name', )
Ejemplo n.º 4
0
class UsageFactory(factories.ModelFactory):
    # Factory data for Usage model.
    name = factories.Sequence(lambda n: 'Usage name %03d' % n)

    class Meta:
        model = Usage
        django_get_or_create = ('name', )
Ejemplo n.º 5
0
class BaseColourFactory(factories.ModelFactory):
    # Factory data for BaseColour model.
    name = factories.Sequence(lambda n: 'BaseColour name %03d' % n)

    class Meta:
        model = BaseColour
        django_get_or_create = ('name', )
Ejemplo n.º 6
0
class SeasonFactory(factories.ModelFactory):
    # Factory data for Season model.
    name = factories.Sequence(lambda n: 'Season name %03d' % n)

    class Meta:
        model = Season
        django_get_or_create = ('name', )
Ejemplo n.º 7
0
class UserFactory(factories.ModelFactory):
    """
    Faker for User model.

    See https://docs.djangoproject.com/en/dev/ref/contrib/auth/#user
    for details.
    """

    first_name = factories.Sequence(lambda n: 'User_%d' % n)
    last_name = 'Doe'
    password = test_password

    @factories.lazy_attribute
    def username(self):
        # Makes the first user in the sequence makes more beautiful.
        # For example, admin_0 becomes just admin.
        username = self.first_name.lower()
        if username.endswith('_0'):
            username = username[:-2]

        return username

    email = factories.LazyAttribute(
        lambda user: '******' % (
            user.username,
            DOMAIN
        )
    )

    class Meta:
        """Meta"""

        model = User
        django_get_or_create = ('username',)
Ejemplo n.º 8
0
class SuperUserFactory(UserFactory):
    """SuperUserFactory"""

    first_name = factories.Sequence(lambda n: 'Admin_%d' % n)
    last_name = 'User'
    is_staff = True
    is_superuser = True
    password = test_password
Ejemplo n.º 9
0
class SuperUserFactory(UserFactory):
    """SuperUserFactory"""

    first_name = factories.Sequence(lambda n: 'Admin_%d' % n)
    last_name = 'User'
    is_staff = True
    is_superuser = True
    password = test_password
    role = UserRolesEnum.ADMIN_ROLE.value
Ejemplo n.º 10
0
class CategoryFactory(factories.ModelFactory):
    # Factory data for Category model.
    name = factories.Sequence(lambda n: 'Category name %03d' % n)
    parent = None

    class Meta:
        model = Category
        django_get_or_create = (
            'name',
            'parent',
        )