Beispiel #1
0
def test_first_save_registers_purchase():
    for account in Account.get_many():
        account.delete()
    for article in Article.get_many():
        article.delete()
    for purchase in Purchase.get_many():
        purchase.delete()
    score = random.randint(0, 100)
    purchaser_id = Account({
        'user_id': user_id,
        'email': fake.email(),
        'name': fake.sentence(),
        'score': score
    }).save()
    article_id = Article({
        'name': fake.word(),
        'description': fake.sentence(),
        'available_units': fake.pyint(),
        'price': 20.0,
        'latitude': 0.0,
        'longitude': 0.0,
        'user': '******',
    }).save()
    purchase_id = Purchase({
        'user_id': purchaser_id,
        'article_id': article_id,
        'units': 1
    }).save()
    assert Account.get_one(purchaser_id).score() == score + 5
    Purchase.get_one(purchase_id).save()
    assert Account.get_one(purchaser_id).score() == score + 5
Beispiel #2
0
def test_first_save_registers_publication():
    for account in Account.get_many():
        account.delete()
    for article in Article.get_many():
        article.delete()
    user_id = 'user_id'
    score = random.randint(0, 100)
    account_id = Account({
        'user_id': user_id,
        'email': fake.email(),
        'name': fake.sentence(),
        'score': score
    }).save()
    article_id = Article({
        'name': fake.word(),
        'description': fake.sentence(),
        'available_units': fake.pyint(),
        'price': 20.0,
        'latitude': 0.0,
        'longitude': 0.0,
        'user': user_id,
    }).save()
    assert Account.get_one(account_id).score() == score + 1
    Article.get_one(article_id).save()
    assert Account.get_one(account_id).score() == score + 1
Beispiel #3
0
def get_or_create_account(claims):
    if Account.get_many(user_id=claims['user_id']):
        return
    default_attrs = ['user_id', 'email', 'name']
    Account({attr: claims[attr] for attr in default_attrs}).save()
Beispiel #4
0
 def account(self) -> Optional[Account]:
     accounts = Account.get_many(user_id=self['user'])
     return accounts[0] if accounts else None