def test_update(test_client: FlaskClient, admin_headers: dict):
    first_ingredient, second_ingredient, first_step, second_step = prepare_create_receipt(
    )

    receipt = Receipt(
        name='Name',
        description='Cool',
        calories=200,
        ingredients=[first_ingredient, second_ingredient],
        steps=[first_step, second_step],
    )

    session.add(receipt)
    session.commit()

    data = ({
        "name": 'Name1',
        "description": 'Cool1',
        "calories": 201,
        "ingredients": [second_ingredient.id],
        "steps": [first_step],
    })

    response = test_client.put(f"/api/admin/v1/receipts/{receipt.id}/",
                               json=data,
                               headers=admin_headers)
    actual = response.json['result']
    expected = ReceiptClientSchema().dump(receipt)

    assert actual == expected
def test_get_saved_receipts(test_client: FlaskClient, client_headers: dict,
                            client: User):
    first_ingredient, second_ingredient, first_step, second_step = prepare_create_receipt(
    )

    receipt = Receipt(
        name='Name',
        description='Cool',
        calories=200,
        ingredients=[first_ingredient, second_ingredient],
        steps=[first_step, second_step],
    )

    session.add(receipt)
    session.commit()

    test_client.post(f'/api/client/v1/receipts/{receipt.id}/save/',
                     headers=client_headers)

    response = test_client.get(f'/api/client/v1/receipts/?user_id={client.id}',
                               headers=client_headers)

    result = response.json['result']

    actual = len(result)
    expected = 1

    assert actual == expected

    actual = result[0]
    expected = ReceiptClientSchema().dump(receipt)

    assert actual == expected
Esempio n. 3
0
def test_created_receipt():
    first_ingredient, second_ingredient, first_step, second_step = prepare_create_receipt()

    receipt = Receipt(
        name='Name',
        description='Cool',
        calories=200,
        ingredients=[first_ingredient, second_ingredient],
        steps=[first_step, second_step],
    )

    session.add(receipt)
    session.commit()

    actual = session.query(Receipt).one()
    expected = receipt

    assert actual == expected
def test_show(test_client: FlaskClient, admin_headers: dict):
    first_ingredient, second_ingredient, first_step, second_step = prepare_create_receipt(
    )

    receipt = Receipt(
        name='Name',
        description='Cool',
        calories=200,
        ingredients=[first_ingredient, second_ingredient],
        steps=[first_step, second_step],
    )

    session.add(receipt)
    session.commit()

    response = test_client.get(f"/api/admin/v1/receipts/{receipt.id}/",
                               headers=admin_headers)
    actual = response.json['result']
    expected = ReceiptClientSchema().dump(receipt)

    assert actual == expected
def test_count(test_client: FlaskClient, admin_headers: dict):
    first_ingredient, second_ingredient, first_step, second_step = prepare_create_receipt(
    )

    receipt = Receipt(
        name='Name',
        description='Cool',
        calories=200,
        ingredients=[first_ingredient, second_ingredient],
        steps=[first_step, second_step],
    )

    session.add(receipt)
    session.commit()

    response = test_client.get('/api/admin/v1/receipts/',
                               headers=admin_headers)
    actual = len(response.json['result'])
    expected = 1

    assert actual == expected
def test_delete(test_client: FlaskClient, admin_headers: dict):
    first_ingredient, second_ingredient, first_step, second_step = prepare_create_receipt(
    )

    receipt = Receipt(
        name='Name',
        description='Cool',
        calories=200,
        ingredients=[first_ingredient, second_ingredient],
        steps=[first_step, second_step],
    )

    session.add(receipt)
    session.commit()

    test_client.delete(f"/api/admin/v1/receipts/{receipt.id}/",
                       headers=admin_headers)
    actual = session.query(Receipt).count()
    expected = 0

    assert actual == expected
def test_save_receipt(test_client: FlaskClient, client_headers: dict):
    first_ingredient, second_ingredient, first_step, second_step = prepare_create_receipt(
    )

    receipt = Receipt(
        name='Name',
        description='Cool',
        calories=200,
        ingredients=[first_ingredient, second_ingredient],
        steps=[first_step, second_step],
    )

    session.add(receipt)
    session.commit()

    response = test_client.post(f'/api/client/v1/receipts/{receipt.id}/save/',
                                headers=client_headers)
    actual = response.status_code
    expected = 200

    assert actual == expected
Esempio n. 8
0
 def on_receipt(self, entity):
     self.toLower(entity.ack())
     signals.receipt.send(Receipt(entity))
Esempio n. 9
0
def execute_before_any_test():
    IngredientsReceipts.truncate()
    UsersReceipts.truncate()
    Receipt.truncate()
    Ingredient.truncate()
    User.truncate()