예제 #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
예제 #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
예제 #3
0
def generate_article():
    instance = Article({
        "name": fake.pystr(),
        "description": fake.text(),
        "available_units": fake.pyint(),
        "price": fake.pyfloat(),
        "latitude": fake.pyfloat(),
        "longitude": fake.pyfloat(),
        "user": fake.pystr(),
    })
    instance.save()
    return instance
예제 #4
0
def setup_function():
    fake = Faker()
    teardown_function()
    Article({
        'name': fake.word(),
        'description': fake.sentence(),
        'available_units': fake.pyint(),
        'price': 20.0,
        'latitude': 0.0,
        'longitude': 0.0,
        'user': fake.word(),
    }).save()

    Article({
        'name': fake.word(),
        'description': fake.sentence(),
        'available_units': fake.pyint(),
        'price': 300.0,
        'latitude': 1.0,
        'longitude': 1.0,
        'user': fake.word(),
    }).save()
예제 #5
0
def test_shipment_cost_no_coordinates(client):
    article_id = Article({
        'name': fake.word(),
        'description': fake.sentence(),
        'available_units': fake.pyint(),
        'price': 20.0,
        'latitude': 0.0,
        'longitude': 0.0,
        'user': fake.word(),
    }).save()
    response = client.get(f'/article/{article_id}/shipment_cost/?'
                          f'payment_method=cash')
    assert response.status_code == 400
    assert not response.json['ok']
예제 #6
0
def test_shipment_cost(client):
    shared_server_response = {
        "success": True,
        "cost": {
            'cost': 12.0,
            'status': 'enabled'
        }
    }
    shared_server_response_json_data =\
        json.dumps(shared_server_response['cost'], sort_keys=True)
    article_id = Article({
        'name': fake.word(),
        'description': fake.sentence(),
        'available_units': fake.pyint(),
        'price': 20.0,
        'latitude': 0.0,
        'longitude': 0.0,
        'user': fake.word(),
    }).save()
    with requests_mock.Mocker() as _mock:
        _mock.post(f'{shared_server_url}shipment-cost',
                   json=shared_server_response)
        response = client.get(f'/article/{article_id}/shipment_cost/?'
                              f'payment_method=cash&'
                              f'my_lat=0&my_lon=0')
        my_response_json_data = json.dumps(response.json['data'],
                                           sort_keys=True)
        assert response.json['ok']
        assert my_response_json_data == json.dumps(
            {
                "cash": {
                    "cost": 12.0,
                    "status": "enabled"
                },
                "credit": {
                    "cost": 12.0,
                    "status": "enabled"
                },
                "debit": {
                    "cost": 12.0,
                    "status": "enabled"
                }
            },
            sort_keys=True)