Example #1
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 #2
0
class PublisherFixture(AutoFixture):
    field_values = {
        'name':
        PublisherGenerator(),
        'num_awards':
        generators.PositiveIntegerGenerator(min_value=0, max_value=10)
    }
Example #3
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 #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
class AuthorFixture(AutoFixture):
    field_values = {
        'user': UserGenerator(),
        'name': generators.FirstNameGenerator(),
        'age': generators.PositiveIntegerGenerator(min_value=20, max_value=80)
    }