示例#1
0
def test_load_products(client, app):
    with app.app_context():
        product = Product.select().where(Product.code == '4').get()
        assert product.code == '4'

    request = load_products(client, [{'code': '4', 'quantity': 5}])

    assert request.status_code == 200
    assert json.loads(request.data) == True

    with app.app_context():
        product_after = Product.select().where(Product.code == '4').get()
        assert product_after.quantity == product.quantity + 5
示例#2
0
def test_buy(client, app):
    with app.app_context():
        product = Product.select().where(Product.code == '4').get()
        assert product.code == '4'

    request = buy_product(client, product.code, ['50p', '£1', '50p'])
    assert request.status_code == 200
    reply = json.loads(request.data)
    assert reply['product'] == 'milk'

    with app.app_context():
        product_after_buy = Product.select().where(Product.code == '4').get()
        assert product_after_buy.quantity + 1 == product.quantity
示例#3
0
def test_get_products(app):
    with app.app_context():
        store = Store()
        store_products = store.get_products()

        products = [p for p in Product.select()]

        assert len(products) == len(store_products)
示例#4
0
def test_list_products(client):
    request = client.get('/api/machine/list')

    assert request.status_code == 200

    request_products = json.loads(request.data)
    machine_products = [p for p in Product.select()]

    assert len(request_products) == len(machine_products)
示例#5
0
def test_get_products(client, app):
    with app.app_context():
        db_products = [p for p in Product.select()]

    request = client.get('/api/service/get_products')

    assert request.status_code == 200

    products = json.loads(request.data)

    assert len(products) == len(db_products)
示例#6
0
def test_product_model(app):
    expected_prod = Product(id=1, code='1', name='soda', quantity=5, price=200)
    expected_dict = {
        'id': 1,
        'code': '1',
        'name': 'soda',
        'price': 200,
        'quantity': 5
    }

    with app.app_context():
        product = Product.select().where(Product.code == '1').get()

        assert product is not None
        assert product == expected_prod
        assert product.to_dict() == expected_dict
        assert str(product) == json.dumps(expected_dict)
示例#7
0
def test_load_new_products(client, app):
    request = load_products(client, [{
        'code': 'NEW',
        'name': 'new product',
        'quantity': 5,
        'price': 10
    }])

    assert request.status_code == 200
    assert json.loads(request.data) == True

    with app.app_context():
        product = Product.select().where(Product.code == 'NEW').get()
        assert product.code == 'NEW'
        assert product.name == 'new product'
        assert product.quantity == 5
        assert product.price == 10