Example #1
0
class CarAutoFixture(AutoFixture):
    field_values = {
        'model_year': generators.DateGenerator(),
        'registered_day': generators.DateGenerator(),
        'color': generators.ChoicesGenerator(COLOR_CHOICES),
        'fuel': generators.ChoicesGenerator(Car.FUEL_CHOICES),
        'sub_model': generators.ChoicesGenerator(SUB_MODEL_CHOICES),
        'gear': generators.ChoicesGenerator(Car.GEAR_CHOICES),
        'kms': generators.PositiveIntegerGenerator(),
        'region': generators.ChoicesGenerator(REGION_CHOICE),
        'status': generators.ChoicesGenerator(Car.STATUS_CHOICES),
    }
Example #2
0
def create_many_leads(num, created_by, project):
    leads = []
    for i in range(num):
        lead = Lead()
        lead.title = generators.LoremGenerator(max_length=20).generate()
        lead.project = project
        lead.created_by = created_by
        lead.modified_by = created_by
        lead.status = random.choice(['pending', 'processed'])
        lead.condidentiality = random.choice([
            'unprotected',
            'protected',
            'restricted',
            'confidential',
        ])
        lead.published_on = generators.DateGenerator().generate()
        leads.append(lead)

    Lead.objects.bulk_create(leads)

    LeadAssigneeThrough = Lead.assignee.through
    assignee_throughs = []

    all_users = list(User.objects.all())
    count = len(all_users)
    for lead in leads:
        assignee_throughs.append(
            LeadAssigneeThrough(
                lead_id=lead.id,
                user_id=all_users[random.randint(0, count - 1)].id,
            )
        )

    LeadAssigneeThrough.objects.bulk_create(assignee_throughs)
Example #3
0
class BookFixture(AutoFixture):
    generate_fk = True
    generate_m2m = {'authors': (1, 2)}
    field_values = {
        'name':
        generators.StringGenerator(min_length=5, max_length=15),
        'pages':
        generators.PositiveIntegerGenerator(min_value=200, max_value=2000),
        'price':
        generators.PositiveDecimalGenerator(max_digits=10, decimal_places=2),
        'rating':
        generators.FloatGenerator(max_value=10, min_value=0, decimal_digits=2),
        'pubdate':
        generators.DateGenerator(min_date=date.today() - timedelta(days=36500),
                                 max_date=date.today())
    }

    def post_process_instance(self, instance, commit):
        Tag.objects.get_or_create(content_type=get_content_type(instance),
                                  object_pk=instance.pk,
                                  defaults={
                                      'tag':
                                      random.choice(
                                          ('sci-fi', 'drama', 'fantasy',
                                           'romance', 'self help', 'satire'))
                                  })
        return instance
Example #4
0
    def handle(self, *args, **options):

        # 1. Users
        AutoFixture(
            User,
            field_values={
                # Generates random birth dates between 7-77 yo
                'birth_date':
                generators.DateGenerator(
                    min_date=dt.date.today() - dt.timedelta(365 * 77),
                    max_date=dt.date.today() - dt.timedelta(365 * 7)),
                # We are a young company so just set join_date to 1-2 years
                'date_joined':
                generators.DateGenerator(
                    min_date=dt.date.today() - dt.timedelta(365 * 2),
                    max_date=dt.date.today() - dt.timedelta(365 * 1)),
                'email':
                generators.EmailGenerator(),
                'first_name':
                generators.FirstNameGenerator(),
                'img':
                generators.ImageGenerator(height=200, width=200,
                                          path='users/'),
                'last_name':
                generators.LastNameGenerator(),
                'oauth_id':
                generators.PositiveIntegerGenerator()
            }).create(10)

        # 2. Items
        AutoFixture(Item,
                    field_values={
                        'name':
                        ItemNameGenerator(),
                        'img':
                        generators.ImageGenerator(height=200,
                                                  width=200,
                                                  path='items/')
                    }).create(80)
Example #5
0
    def handle(self, *args, **options):

        AutoFixture(
            Metric,
            field_values={
                'name':
                generators.StaticGenerator('user_registration'),
                'datetime':
                generators.DateTimeGenerator(min_date=datetime(2018, 1, 1),
                                             max_date=datetime(2018, 4, 24)),
                'increment':
                generators.ChoicesGenerator(values=(-1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 1, 1, 1, 1)),
                'data':
                generators.StaticGenerator({'dummy': True}),
            }).create(160)

        AutoFixture(Metric,
                    field_values={
                        'name':
                        generators.StaticGenerator('event_registration'),
                        'datetime':
                        generators.DateGenerator(min_date=datetime(2018, 1, 1),
                                                 max_date=datetime(
                                                     2018, 4, 24)),
                        'increment':
                        generators.ChoicesGenerator(values=(2, )),
                        'data':
                        generators.StaticGenerator({
                            'dummy': True,
                            'group_id': 1,
                            'event_id': 1
                        }),
                    }).create(int(114 * 3))

        AutoFixture(Metric,
                    field_values={
                        'name':
                        generators.StaticGenerator('event_attendance'),
                        'datetime':
                        generators.DateGenerator(min_date=datetime(2018, 1, 1),
                                                 max_date=datetime(
                                                     2018, 4, 24)),
                        'increment':
                        generators.ChoicesGenerator(values=(1, )),
                        'data':
                        generators.StaticGenerator({
                            'dummy': True,
                            'group_id': 1,
                            'event_id': 1
                        }),
                    }).create(int(114 * 3))

        AutoFixture(
            Metric,
            field_values={
                'name':
                generators.StaticGenerator('group_join'),
                'datetime':
                generators.DateTimeGenerator(min_date=datetime(2018, 1, 1),
                                             max_date=datetime(2018, 4, 24)),
                'increment':
                generators.ChoicesGenerator(values=(-1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1)),
                'data':
                generators.StaticGenerator({
                    'dummy': True,
                    'group_id': 1,
                    'event_id': 1
                }),
            }).create(140)

        AutoFixture(
            Metric,
            field_values={
                'name':
                generators.StaticGenerator('create_event'),
                'datetime':
                generators.DateTimeGenerator(min_date=datetime(2018, 1, 1),
                                             max_date=datetime(2018, 4, 24)),
                'increment':
                generators.ChoicesGenerator(values=(-1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1)),
                'data':
                generators.StaticGenerator({
                    'dummy': True,
                    'group_id': 1,
                    'event_id': 1
                }),
            }).create(140)

        AutoFixture(Metric,
                    field_values={
                        'name':
                        generators.StaticGenerator('event_registration'),
                        'datetime':
                        generators.DateGenerator(min_date=datetime(2018, 1, 1),
                                                 max_date=datetime(
                                                     2018, 4, 24)),
                        'increment':
                        generators.ChoicesGenerator(values=(2, )),
                        'data':
                        generators.StaticGenerator({
                            'dummy': True,
                            'group_id': 2
                        }),
                    }).create(int(114 * 3))

        AutoFixture(Metric,
                    field_values={
                        'name':
                        generators.StaticGenerator('event_attendance'),
                        'datetime':
                        generators.DateGenerator(min_date=datetime(2018, 1, 1),
                                                 max_date=datetime(
                                                     2018, 4, 24)),
                        'increment':
                        generators.ChoicesGenerator(values=(1, )),
                        'data':
                        generators.StaticGenerator({
                            'dummy': True,
                            'group_id': 2
                        }),
                    }).create(int(114 * 3))

        AutoFixture(
            Metric,
            field_values={
                'name':
                generators.StaticGenerator('group_join'),
                'datetime':
                generators.DateTimeGenerator(min_date=datetime(2018, 1, 1),
                                             max_date=datetime(2018, 4, 24)),
                'increment':
                generators.ChoicesGenerator(values=(-1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1)),
                'data':
                generators.StaticGenerator({
                    'dummy': True,
                    'group_id': 2
                }),
            }).create(140)

        AutoFixture(
            Metric,
            field_values={
                'name':
                generators.StaticGenerator('create_event'),
                'datetime':
                generators.DateTimeGenerator(min_date=datetime(2018, 1, 1),
                                             max_date=datetime(2018, 4, 24)),
                'increment':
                generators.ChoicesGenerator(values=(-1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1)),
                'data':
                generators.StaticGenerator({
                    'dummy': True,
                    'group_id': 2
                }),
            }).create(140)