Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
    def get_by_seller(cls, seller: Account):
        article_ids = [
            a.get_id() for a in Article.get_many(user=seller['user_id'])
        ]
        if not article_ids:
            return []

        purchases = cls.get_many(article_id=article_ids)
        return cls.expand(purchases)
Exemplo n.º 4
0
 def get_by_owner(self):
     account = Account.get_one(self.owner)
     article_ids = [a.get_id()
                    for a in Article.get_many(user=account['user_id'])]
     questions = []
     for article_id in article_ids:
         questions.extend(
             Question.get_many(article_id=article_id)
         )
     return self.append_article_to_questions(questions)
Exemplo n.º 5
0
def teardown_function():
    for a in Article.get_many():
        a.delete()