Files
edx-platform/openedx/features/enterprise_support/tests/factories.py
Feanil Patel 9cf2f9f298 Run 2to3 -f future . -w
This will remove imports from __future__ that are no longer needed.

https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
2019-12-30 10:35:30 -05:00

76 lines
2.3 KiB
Python

"""
Factoryboy factories.
"""
from uuid import UUID
import factory
from faker import Factory as FakerFactory
from enterprise.models import EnterpriseCourseEnrollment, EnterpriseCustomer, EnterpriseCustomerUser
from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory
FAKER = FakerFactory.create()
class EnterpriseCustomerFactory(factory.django.DjangoModelFactory):
"""
EnterpriseCustomer factory.
Creates an instance of EnterpriseCustomer with minimal boilerplate - uses this class' attributes as default
parameters for EnterpriseCustomer constructor.
"""
class Meta(object):
"""
Meta for EnterpriseCustomerFactory.
"""
model = EnterpriseCustomer
uuid = factory.LazyAttribute(lambda x: UUID(FAKER.uuid4())) # pylint: disable=no-member
name = factory.LazyAttribute(lambda x: FAKER.company()) # pylint: disable=no-member
active = True
site = factory.SubFactory(SiteFactory)
enable_data_sharing_consent = True
enforce_data_sharing_consent = EnterpriseCustomer.AT_ENROLLMENT
class EnterpriseCustomerUserFactory(factory.django.DjangoModelFactory):
"""
EnterpriseCustomer factory.
Creates an instance of EnterpriseCustomerUser with minimal boilerplate - uses this class' attributes as default
parameters for EnterpriseCustomerUser constructor.
"""
class Meta(object):
"""
Meta for EnterpriseCustomerFactory.
"""
model = EnterpriseCustomerUser
enterprise_customer = factory.SubFactory(EnterpriseCustomerFactory)
user_id = factory.LazyAttribute(lambda x: FAKER.pyint()) # pylint: disable=no-member
class EnterpriseCourseEnrollmentFactory(factory.django.DjangoModelFactory):
"""
EnterpriseCourseEnrollment factory.
Creates an instance of EnterpriseCourseEnrollment with minimal boilerplate.
"""
class Meta(object):
"""
Meta for EnterpriseCourseEnrollmentFactory.
"""
model = EnterpriseCourseEnrollment
id = factory.LazyAttribute(lambda x: FAKER.random_int(min=1)) # pylint: disable=no-member
course_id = factory.LazyAttribute(lambda x: FAKER.slug()) # pylint: disable=no-member
enterprise_customer_user = factory.SubFactory(EnterpriseCustomerUserFactory)