class FairsharingRecordAutoFixture(AutoFixture):
    field_values = {
        'name': generators.StringGenerator(max_length=10, min_length=8),
        'abbreviation': generators.StringGenerator(max_length=3, min_length=2),
        'homepage': generators.URLGenerator(),
        'description': generators.LoremGenerator(),
        'doi': generators.StaticGenerator(generate_doi(DATACITE_PREFIX))
    }
示例#2
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
示例#3
0
class ProductAutoFixture(AutoFixture):
    """Fixture for Product generation."""

    field_values = {
        'article':
        generators.StringGenerator(
            chars=string.ascii_letters + string.digits + ' -',
            max_length=Product._meta.get_field('article').max_length,
        ),
        'cost':
        generators.PositiveDecimalGenerator(
            max_digits=Product._meta.get_field('cost').max_digits,
            decimal_places=Product._meta.get_field('cost').decimal_places,
        ),
        'price':
        generators.PositiveDecimalGenerator(
            max_digits=Product._meta.get_field('price').max_digits,
            decimal_places=Product._meta.get_field('price').decimal_places,
        ),
        'count':
        generators.PositiveDecimalGenerator(
            max_digits=Product._meta.get_field('count').max_digits,
            decimal_places=Product._meta.get_field('count').decimal_places,
        ),
    }
示例#4
0
class ContactoAutoFixture(AutoFixture):
    field_values = {
        'nombre': generators.FirstNameGenerator(),
        'apellidos': generators.LastNameGenerator(),
        'direccion': generators.StringGenerator(),
        'telefono': '+' + str(randint(100000000000, 1000000000000))
    }
class CarAutoFixture(AutoFixture):
    field_values = {
        'name':
        generators.StringGenerator(min_length=3, max_length=12),
        'launched':
        generators.DateTimeGenerator(min_date=datetime(1950, 1, 1),
                                     max_date=datetime(2015, 12, 31)),
        'type':
        generators.ChoicesGenerator(values=('se', '4x', 'co', 'br')),
    }
class ManufacturerAutoFixture(AutoFixture):
    field_values = {
        'name':
        generators.StringGenerator(min_length=3, max_length=12),
        'created':
        generators.DateTimeGenerator(min_date=datetime(1900, 1, 1),
                                     max_date=datetime(2015, 12, 31)),
        'country_code':
        generators.ChoicesGenerator(values=(COUNTRIES.keys())),
    }
示例#7
0
 class Values(object):
     username = generators.StringGenerator(chars=string.ascii_letters +
                                           string.digits + '_')
     first_name = generators.LoremWordGenerator(1)
     last_name = generators.LoremWordGenerator(1)
     password = staticmethod(lambda: make_password(None))
     is_active = True
     # don't generate admin users
     is_staff = False
     is_superuser = False
     date_joined = generators.DateTimeGenerator(max_date=timezone.now())
     last_login = generators.DateTimeGenerator(max_date=timezone.now())
示例#8
0
 class Values(object):
     username = generators.StringGenerator(chars=string.ascii_letters +
                                           string.digits + '_')
     first_name = generators.LoremWordGenerator(1)
     last_name = generators.LoremWordGenerator(1)
     password = UNUSABLE_PASSWORD
     is_active = True
     # don't generate admin users
     is_staff = False
     is_superuser = False
     date_joined = generators.DateTimeGenerator(max_date=datetime.now())
     last_login = generators.DateTimeGenerator(max_date=datetime.now())
示例#9
0
class StoreFixture(AutoFixture):
    generate_fk = True
    generate_m2m = {'books': (2, 4)}
    field_values = {
        'name': generators.StringGenerator(min_length=5, max_length=15),
        'registered_users': generators.PositiveSmallIntegerGenerator(10, 1000)
    }

    def post_process_instance(self, instance, commit):
        # Make sure the bestseller is in the store!
        if instance.bestseller:
            instance.books.add(instance.bestseller)
        return instance
示例#10
0
 class RoleAutoFixture(AutoFixture):
     field_values = {
         'name': RoleNameGenerator(),
         'github_user': generators.FirstNameGenerator(),
         'github_repo': generators.StringGenerator(min_length=6, max_length=10),
         'description': generators.LoremGenerator(max_length=250),
         'readme': generators.LoremHTMLGenerator(),
         'min_ansible_version': generators.StaticGenerator('1.3'),
         'issue_tracker_url': generators.URLGenerator(),
         'license': generators.StaticGenerator(''),
         'company': generators.StaticGenerator(''),
         'is_valid': generators.StaticGenerator(True),
     }
示例#11
0
    def test_record(self):
        record = FairsharingRecord.objects.first()

        # Is it a FairsharingRecord with the correct fields?
        self.assertTrue(isinstance(record, FairsharingRecord))
        self.assertEqual(record.__unicode__(), record.name)

        # Does it fail to save if the abbreviation is too long?
        record.abbreviation = generators.StringGenerator(max_length=130,
                                                         min_length=129)
        try:
            record.save()
        except DataError:
            pass
示例#12
0
    def handle(self, *args, **options):

        fixture = AutoFixture(User,
                              field_values={
                                  'username':
                                  generators.StringGenerator(max_length=10),
                                  'first_name':
                                  generators.FirstNameGenerator(),
                                  'last_name':
                                  generators.LastNameGenerator(),
                                  'email':
                                  generators.EmailGenerator(),
                                  'password':
                                  UNUSABLE_PASSWORD
                              })
        entries = fixture.create(50)

        for us in User.objects.all():
            if us.username != 'alberto':
                us.set_password('pass')
                us.save()

        fixture = AutoFixture(
            auction,
            field_values={
                'min_price':
                generators.PositiveSmallIntegerGenerator(max_value=1000),
                'lock':
                False
            })
        entries = fixture.create(50)

        fixture = AutoFixture(bid,
                              field_values={
                                  'amount':
                                  generators.IntegerGenerator(min_value=0),
                                  'status':
                                  'W'
                              })
        entries = fixture.create(20)

        auct = auction.objects.all()
        for auc in auct:
            if (auc.deadline > timezone.make_aware(
                    datetime.now(), timezone.get_default_timezone())):
                auc.lifecycle = 'A'
                auc.save()
            if (auc.deadline < timezone.make_aware(
                    datetime.now(), timezone.get_default_timezone())
                    and auc.lifecycle == 'A'):
                auc.lifecycle = 'D'
                auc.save()

        bids = bid.objects.all()
        for b in bids:
            for a in bids:
                if (b.auct == a.auct and a != b):
                    if (b.status == 'W' and a.status == 'W'):
                        if (b.amount > a.amount):
                            a.status = 'L'
                            a.save()
                        else:
                            b.status = 'L'
                            b.save()
            if (b.amount < b.auct.min_price):
                b.amount = b.auct.min_price + 1
                b.save()
            if (b.user == b.auct.seller):
                b.delete()