Exemple #1
0
class CampaignFactory(DjangoModelFactory):
    class Meta:
        model = Campaign

    name = Faker('company')
    kind = Iterator(CampaignKind, getter=lambda c: c)
    status = Iterator(ActiveInactiveStatus, getter=lambda c: c)
Exemple #2
0
class TransactionFactory(DjangoModelFactory):
    class Meta:
        model = Transaction

    action = Iterator(Action, getter=lambda c: c)
    sender = SubFactory(WalletFactory)
    receiver = SubFactory(WalletFactory)
    status = Iterator(ProcessStatus, getter=lambda c: c)
Exemple #3
0
class PositionFactory(DjangoModelFactory):
    class Meta:
        model = Position

    number = FuzzyText(length=6, chars=string.digits)
    grade = Iterator(['NM-07', 'NM-09', 'NM-11', 'NM-12', 'NM-13'])
    type = Iterator(TENURE_TYPES, getter=lambda c: c[0])
    owner = None
Exemple #4
0
class CommentFactory(DjangoModelFactory):
    post = Iterator(Post.objects.all())
    author = Iterator(get_user_model().objects.all())

    text = Faker('paragraph')
    created = Faker('date_time_this_year')

    class Meta:
        model = Comment
class QuestionFactory(DjangoModelFactory):
    class Meta:
        model = Question

    approved = Iterator([True, False])
    viewed = Iterator([False, True])
    priority = LazyAttribute(lambda o: randint(1, 100))
    question = LazyAttribute(
        lambda x: faker.paragraph(nb_sentences=3, variable_nb_sentences=True))
    event = SubFactory(EventFactory)
Exemple #6
0
class OmicsUnitFactory(DjangoModelFactory):

    reference = SubFactory(EntryFactory)
    strain = Iterator(models.Strain.objects.all())
    type = Iterator(models.OmicsUnitType.objects.all())
    status = Iterator(s[0] for s in models.OmicsUnit.STATUS_CHOICES)

    class Meta:
        model = 'core.OmicsUnit'
        django_get_or_create = ('reference', 'strain')
Exemple #7
0
class BrokerFactory(DjangoModelFactory):
    class Meta:
        model = Broker

    # middle_name = LazyAttribute(lambda x: FuzzyText(length=60, chars=string.digits).fuzz())
    sex = Iterator((('M', 'Male'), ('F', 'Female')), getter=lambda x: x[0])
    national_id = LazyAttribute(
        lambda x: FuzzyText(length=50, chars=string.digits).fuzz())
    national_id_type = Iterator((('NATIONAL_ID', 'National Id'),
                                 ('DRIVERS_LICENSE', 'Drivers License'),
                                 ('PASSPORT', 'Passport'), ('OTHER', 'Other')),
                                getter=lambda x: x[0])
    country_for_id = Iterator([
        'PA',
        'US',
        'GB',
    ])
    # Field type ImageField for field picture is not currently supported
    date_of_birth = LazyAttribute(lambda x: faker.date_of_birth(
        tzinfo=timezone(settings.TIME_ZONE), minimum_age=18, maximum_age=90))
    # religion = Iterator(['Catolico', 'Protestante', 'Judio', ])
    broker_type = Iterator(
        (('N', 'Natural person'), ('J', 'Juridical person')),
        getter=lambda x: x[0])

    created_by = SubFactory(UserFactory)

    @lazy_attribute
    def modified_by(self):
        return self.created_by

    @lazy_attribute
    def first_name(self):
        if self.broker_type == 'N':
            if self.sex == 'M':
                return faker.first_name_male()
            else:
                return faker.first_name_female()
        else:
            return None

    @lazy_attribute
    def last_name(self):
        if self.broker_type == 'N':
            return faker.last_name()
        else:
            return None

    @lazy_attribute
    def full_name(self):
        if self.broker_type == 'N':
            return f'{self.last_name}, {self.first_name}'
        else:
            return faker.company()
class MessageModelFactory(DjangoModelFactory):
    class Meta:
        model = MessageModel

    # is_removed = Iterator([True, False])
    sender = Iterator(User.objects.all())
    recipient = Iterator(User.objects.all())
    text = LazyAttribute(
        lambda x: faker.paragraph(nb_sentences=3, variable_nb_sentences=True))
    file = LazyAttribute(lambda x: None)
    read = Iterator([True, False])
class Appointment(DjangoModelFactory):
    class Meta:
        model = AppointmentM

    owner = uuid.uuid4()
    name = Iterator(['David', 'Nina'])
    start_date = datetime(2018, 1, 1, 12, 30, tzinfo=pytz.UTC)
    end_date = datetime(2018, 1, 1, 15, 15, tzinfo=pytz.UTC)
    type = ['Testtype1', 'Testtype2']
    address = "Teststreet 1"
    organization_uuid = uuid.uuid4()
    notes = Iterator(['Lorem', 'Ipsum'])
Exemple #10
0
class Bookings(DjangoModelFactory):
    class Meta:
        model = Bookings

    instructor = Iterator(Instructor.objects.all())
    learner = Iterator(Learner.objects.all())
    date = lazy_attribute(lambda x: faker.date_between_dates(
        datetime.date(2020, 6, 1),
        datetime.date(2020, 6, 30)
    ))
    startTime = lazy_attribute(lambda x: faker.start_time())
    endTime = lazy_attribute(lambda x: faker.start_time())
class Document(DjangoModelFactory):
    class Meta:
        model = DocumentM

    file_name = Iterator(['test.jpg', 'test.png', 'test.pdf'])
    file_type = Iterator(['jpg', 'png', 'pdf'])
    workflowlevel1_uuids = [str(uuid.uuid4())]
    workflowlevel2_uuids = [str(uuid.uuid4())]
    contact_uuid = str(uuid.uuid4())

    upload_date = datetime(2018, 1, 1, 12, 30, tzinfo=pytz.UTC)
    create_date = datetime(2018, 1, 1, 15, 15, tzinfo=pytz.UTC)
Exemple #12
0
class ExtendedUserProfileFactory(BasicUserProfileFactory):

    is_active = True
    enable_extended_information = True
    affiliation = Faker('company')
    user_bio = Faker('sentence', nb_words=4, variable_nb_words=True)
    user_bio_long = Faker('paragraph',
                          nb_sentences=15,
                          variable_nb_sentences=True)
    # Used default values from the database
    profile_type = Iterator(ProfileType.objects.all())
    program_type = Iterator(ProgramType.objects.all())
    program_year = Iterator(ProgramYear.objects.all())
class Contact(DjangoModelFactory):
    class Meta:
        model = ContactM

    user_uuid = uuid.uuid4()
    first_name = Iterator(['David', 'Nina'])
    last_name = Iterator(['Bowie', 'Simone'])
    title = Iterator(['mr', 'ms'])
    contact_type = Iterator(['customer', 'supplier'])
    customer_type = Iterator(['customer', 'public'])
    company = Iterator(['RCA', 'Motown'])
    addresses = []
    emails = Iterator([
        [
            {'type': 'private', 'email': '*****@*****.**'},
            {'type': 'office', 'email': '*****@*****.**'},
        ],
        [
            {'type': 'private', 'email': '*****@*****.**'},
            {'type': 'office', 'email': '*****@*****.**'},
        ],
    ])
    phones = []
    notes = Iterator(["Bowie's notes", "Nina's notes"])
    organization_uuid = str(uuid.uuid4())
    workflowlevel1_uuids = [str(uuid.uuid4())]
Exemple #14
0
class PlaceFactory(DjangoModelFactory):
    class Meta:
        model = Place

    place_type = Iterator(PlaceType.objects.all())
    name = Faker("city")
    description = Faker("bs")
    country = Iterator(Country.objects.filter(iso2__in=COUNTRIES))
    geom = LazyAttribute(
        lambda o: Faker("location", country=o.country.iso2).generate())
    altitude = Faker("random_int", min=0, max=4808)
    data_source = Faker("random_element",
                        elements=["geonames", "swissnames3d"])
    source_id = Sequence(lambda n: 1000 + n)
Exemple #15
0
class RealEstateSpaceFactory(DjangoModelFactory):
    class Meta:
        model = RealEstateSpace

    project = SubFactory(RealEstateProjectFactory)
    name = LazyAttribute(lambda x: faker.text(max_nb_chars=20))
    space_type = Iterator((('LIVING', 'Living space'), ('PARKING', 'Parking'),
                           ('STORAGE', 'Storage'), ('OTHER', 'Other')),
                          getter=lambda x: x[0])
    area = LazyAttribute(lambda x: faker.pydecimal(left_digits=4,
                                                   right_digits=2,
                                                   positive=True,
                                                   min_value=50.0,
                                                   max_value=500.0))
    contract = None  # SubFactory(ContractFactory)

    created_by = SubFactory(UserFactory)

    @lazy_attribute
    def modified_by(self):
        return self.created_by

    @lazy_attribute
    def price(self):
        return self.area * Decimal('1200.00')
Exemple #16
0
def test_program_page(browser, base_test_data, logged_in_student):
    """
    Test viewing the program page
    """
    courses = list(base_test_data.program.course_set.all()) + \
        CourseFactory.create_batch(2, program=base_test_data.program)
    page = ProgramPageFactory.create(program=base_test_data.program,
                                     title="A Program Title")
    faculty = FacultyFactory.create_batch(3, program_page=page)
    info_links = InfoLinksFactory.create_batch(3, program_page=page)
    semester_dates = SemesterDateFactory.create_batch(3, program_page=page)
    program_courses = ProgramCourseFactory.create_batch(
        len(courses), program_page=page, course=Iterator(courses))

    browser.get("/a-program-title/")
    faculty_elements = browser.driver.find_elements_by_css_selector(
        ".faculty-tile")
    assert len(faculty) == len(faculty_elements)
    info_elements = browser.driver.find_elements_by_css_selector(
        ".program-contact-link")
    assert len(info_links) == len(info_elements)
    semester_elements = browser.driver.find_elements_by_css_selector(
        ".semester-date")
    assert len(semester_dates) == len(semester_elements)
    program_course_elements = browser.driver.find_elements_by_css_selector(
        ".program-course .title")
    assert len(program_courses) == len(program_course_elements)
class NetworkTransactionFactory(DjangoModelFactory):
    amount = Faker('pyint', max_value=MAX_POINT_VALUE, min_value=MIN_POINT_VALUE)
    fee = Iterator(ACCEPTED_FEE_LIST + [''])
    recipient = Faker('text', max_nb_chars=VERIFY_KEY_LENGTH)

    class Meta:
        model = NetworkTransaction
Exemple #18
0
class UserFactory(DjangoModelFactory):
    """
    User factory for easy model creation.

    This class will return a new user model instance
    based on fake data from faker's data lists.
    """
    class Meta:
        model = User

    email = Faker("email")
    group = Iterator(Group.objects.all())

    password = "******"

    @classmethod
    def _create(cls, model_class, *args, **kwargs):
        """
        Overridden to user the managers create_user() method.

        :param model_class: The class of the model to use
        :type model_class: type of accounts.models.User

        :param args: The additional arguments for field values
        :type args: str | int | bool | datetime.datetime

        :param args: The additional keyword arguments for field values
        :type args: str | int | bool | datetime.datetime

        :return: The newly created user
        :rtype: accounts.models.User
        """
        manager = cls._get_manager(model_class)
        return manager.create_user(*args, **kwargs)
Exemple #19
0
class BookFactory(DjangoModelFactory):
    class Meta:
        model = Book

    name = LazyAttribute(lambda x: faker.text(max_nb_chars=100))
    isbn_number = LazyAttribute(
        lambda x: FuzzyText(length=100, chars=string.digits).fuzz())
    published_year = LazyAttribute(lambda x: faker.date_time_between(
        start_date="-1y", end_date="now", tzinfo=timezone(settings.TIME_ZONE)))
    volume = LazyAttribute(lambda x: faker.text(max_nb_chars=100))
    author = SubFactory(AuthorFactory)
    publication = SubFactory(PublicationFactory)
    genre = SubFactory(GenreFactory)
    type = SubFactory(TypeFactory)
    category = SubFactory(CategoryFactory)
    shelf = SubFactory(ShelfFactory)
    #img = ImageField We do not support this field type
    desc = LazyAttribute(
        lambda x: faker.paragraph(nb_sentences=3, variable_nb_sentences=True))
    #quantity = PositiveIntegerField We do not support this field type
    price = LazyAttribute(lambda x: faker.pydecimal(
        left_digits=8, right_digits=2, positive=True))
    purchase_date = LazyAttribute(lambda x: faker.date_time_between(
        start_date="-1y", end_date="now", tzinfo=timezone(settings.TIME_ZONE)))
    status = Iterator([True, False])
    created_at = LazyAttribute(lambda x: faker.date_time_between(
        start_date="-1y", end_date="now", tzinfo=timezone(settings.TIME_ZONE)))
    updated_at = LazyAttribute(lambda x: faker.date_time_between(
        start_date="-1y", end_date="now", tzinfo=timezone(settings.TIME_ZONE)))
Exemple #20
0
class UserFactory(DjangoModelFactory):
    class Meta:
        model = User

    password = LazyAttribute(lambda x: faker.text(max_nb_chars=128))
    last_login = LazyAttribute(lambda x: faker.date_time_between(
        start_date="-1y", end_date="now", tzinfo=timezone(settings.TIME_ZONE)))
    is_superuser = Iterator([True, False])
    username = LazyAttribute(lambda x: faker.text(max_nb_chars=150))
    first_name = LazyAttribute(lambda x: faker.text(max_nb_chars=150))
    last_name = LazyAttribute(lambda x: faker.text(max_nb_chars=150))
    #email = EmailField We do not support this field type
    is_staff = Iterator([True, False])
    is_active = Iterator([True, False])
    date_joined = LazyAttribute(lambda x: faker.date_time_between(
        start_date="-1y", end_date="now", tzinfo=timezone(settings.TIME_ZONE)))
Exemple #21
0
class ReadType(DjangoModelFactory):
    class Meta:
        model = ReadTypeM
        django_get_or_create = ('read_type',)

    read_type = Iterator(['CustomForm', 'OneDrive', 'CommCare', 'JSON',
                          'GSheet Import', 'CSV', 'ONA'])
class UserFactory(DjangoModelFactory):
    class Meta:
        model = User

    password = LazyAttribute(lambda x: faker.text(max_nb_chars=128))
    last_login = LazyAttribute(lambda x: faker.date_time_between(
        start_date="-1y", end_date="now", tzinfo=timezone(settings.TIME_ZONE)))
    is_superuser = Iterator([True, False])
    username = Sequence(lambda n: "user_%03d" % n)
    first_name = LazyAttribute(lambda x: faker.text(max_nb_chars=150))
    last_name = LazyAttribute(lambda x: faker.text(max_nb_chars=150))
    email = faker.email()
    is_staff = Iterator([True, False])
    is_active = Iterator([True, False])
    date_joined = LazyAttribute(lambda x: faker.date_time_between(
        start_date="-1y", end_date="now", tzinfo=timezone(settings.TIME_ZONE)))
Exemple #23
0
class MonthlyPaymentFrequencyFactory(DjangoModelFactory):
    class Meta:
        model = PaymentFrequency

    frequency_values = Iterator(['30', '15, 30', '5'])
    frequency = LazyAttribute(lambda x: PaymentFrequency.FREQ_MONTHLY)
    start_date = timezone.now()
Exemple #24
0
 def create_transaction_last(self):
     # Membership fee booking for last month
     TransactionFactory.create(valid_on=self.membership_fee_last.ends_on,
                               splits__account=Iterator([
                                   self.user.account,
                                   AccountFactory.create()
                               ]))
Exemple #25
0
 def setUpClass(cls):  # noqa
     SecretFactory.create_batch(
         5, text=Iterator([None, None, 'foo', 'bar', None]))
     cls.request = RequestFactory().get('/admin/testapp/secret')
     cls.field = Secret._meta.get_field('text')
     cls.field_path = 'text'
     cls.qs = Secret.objects.all()
class LinkFactory(DjangoModelFactory):
    class Meta:
        model = Link
        django_get_or_create = ["url"]

    link_type = Iterator(
        ['WebSite', 'MeetUp', 'FaceBook', 'Twitter', 'GitHub'])
    url = Sequence(lambda n: "https://example.com/%d" % n)
class SiteProfile(DjangoModelFactory):
    profiletype = SubFactory(ProfileType)
    country = Iterator(['ES', 'GB', 'DE'])
    organization_uuid = str(uuid.uuid4())
    workflowlevel2_uuid = [str(uuid.uuid4())]

    class Meta:
        model = SiteProfileM
Exemple #28
0
class EmployeeFactory(DjangoModelFactory):
    class Meta:
        model = Employee

    user = SubFactory(UserFactory)
    middle_name = LazyAttribute(lambda x: faker.first_name())
    company_id = FuzzyText(length=7, chars=string.digits)
    tenure = Iterator(TENURE_TYPES, getter=lambda c: c[0])
Exemple #29
0
class PetFactory(DjangoModelFactory):
    class Meta(object):
        model = Pet

    name = fuzzy.FuzzyText('')
    gender = fuzzy.FuzzyChoice(['male', 'female'])
    breed = Iterator(Breed.objects.all())
    owner = SubFactory(UserFactory)
Exemple #30
0
class CardFactory(DjangoModelFactory):
    name = Faker("name")
    expansion = SubFactory(ExpansionFactory)
    cost = Faker("random_int", min=0, max=15)
    standard = True
    card_type = Iterator((c[0] for c in TypeCard.choices))

    class Meta:
        model = Card