/
woodpecker86
/
cosmic-python-code
Обзор
Документация
Войти
/
woodpecker86
/
cosmic-python-code
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/e2e/test_api.py
39 строк
1 KB
Harry
modify api tests to try and do a get after a post [get_after_post]
01 мар 2024, 18:05
01 мар 2024, 18:05
f6833ff
Код
Авторство
О чём код?
import pytest from ..random_refs import random_batchref, random_orderid, random_sku from . import api_client @pytest.mark.usefixtures("postgres_db") @pytest.mark.usefixtures("restart_api") def test_happy_path_returns_202_and_batch_is_allocated(): orderid = random_orderid() sku, othersku = random_sku(), random_sku("other") earlybatch = random_batchref(1) laterbatch = random_batchref(2) otherbatch = random_batchref(3) api_client.post_to_add_batch(laterbatch, sku, 100, "2011-01-02") api_client.post_to_add_batch(earlybatch, sku, 100, "2011-01-01") api_client.post_to_add_batch(otherbatch, othersku, 100, None) r = api_client.post_to_allocate(orderid, sku, qty=3) assert r.status_code == 202 r = api_client.get_allocation(orderid) assert r.ok assert r.json() == [ {"sku": sku, "batchref": earlybatch}, ] @pytest.mark.usefixtures("postgres_db") @pytest.mark.usefixtures("restart_api") def test_unhappy_path_returns_400_and_error_message(): unknown_sku, orderid = random_sku(), random_orderid() r = api_client.post_to_allocate( orderid, unknown_sku, qty=20, expect_success=False ) assert r.status_code == 400 assert r.json()["message"] == f"Invalid sku {unknown_sku}" r = api_client.get_allocation(orderid) assert r.status_code == 404