def post_to_add_batch(ref, sku, qty, eta): url = config.get_api_url() r = requests.post(f'{url}/add_batch', json={ 'ref': ref, 'sku': sku, 'qty': qty, 'eta': eta }) assert r.status_code == 201
def post_to_allocate(order_id, sku, qty, expect_success=True): url = config.get_api_url() data = {'orderid': order_id, 'sku': sku, 'qty': qty} r = requests.post(f'{url}/allocations', json=data) if expect_success: assert r.status_code == 202 return r
def wait_for_webapp_to_come_up(): # deadline = time.time() + 5 # url = config.get_api_url() # while time.time() < deadline: # try: # return requests.get(url) # except ConnectionError: # time.sleep(0.5) # pytest.fail('API never came up') return requests.get(config.get_api_url())
def post_to_add_batch(ref, sku, qty, eta): url = config.get_api_url() r = requests.post(f"{url}/add_batch", json={ "ref": ref, "sku": sku, "qty": qty, "eta": eta }) assert r.status_code == 201
def post_to_allocate(orderid, sku, qty, expect_success=True): url = config.get_api_url() r = requests.post(f"{url}/allocate", json={ "orderid": orderid, "sku": sku, "qty": qty, }) if expect_success: assert r.status_code == 202 return r
def post_to_add_batch(ref, sku, qty, eta): url = config.get_api_url() r = requests.post( <<<<<<< HEAD f'{url}/add_batch', json={'ref': ref, 'sku': sku, 'qty': qty, 'eta': eta} ======= f"{url}/add_batch", json={"ref": ref, "sku": sku, "qty": qty, "eta": eta} >>>>>>> upstream/master ) assert r.status_code == 201
def test_happy_path_returns_201_and_allocated_batch(): sku, othersku = random_sku(), random_sku('other') earlybatch = random_batchref("1") laterbatch = random_batchref("2") otherbatch = random_batchref("3") post_to_add_batch(laterbatch, sku, 100, '2011-01-02') post_to_add_batch(earlybatch, sku, 100, '2011-01-01') post_to_add_batch(otherbatch, othersku, 100, None) data = {'orderid': random_orderid(), 'sku': sku, 'qty': 3} url = config.get_api_url() r = requests.post(f'{url}/allocate', json=data) assert r.status_code == 201 assert r.json()['batchref'] == earlybatch
def test_happy_path_returns_201_and_allocated_batch(): sku, othersku = random_sku(), random_sku("other") earlybatch = random_batchref(1) laterbatch = random_batchref(2) otherbatch = random_batchref(3) post_to_add_batch(laterbatch, sku, 100, "2011-01-02") post_to_add_batch(earlybatch, sku, 100, "2011-01-01") post_to_add_batch(otherbatch, othersku, 100, None) data = {"orderid": random_orderid(), "sku": sku, "qty": 3} url = config.get_api_url() r = requests.post(f"{url}/allocate", json=data) assert r.status_code == 201 assert r.json()["batchref"] == earlybatch
def test_happy_path_returns_202_and_batch_is_allocated(): orderid = random_orderid() sku, othersku = random_sku(), random_sku('other') batch1, batch2, batch3 = random_batchref(1), random_batchref( 2), random_batchref(3) post_to_add_batch(batch1, sku, 100, '2011-01-02') post_to_add_batch(batch2, sku, 100, '2011-01-01') post_to_add_batch(batch3, othersku, 100, None) data = {'orderid': orderid, 'sku': sku, 'qty': 3} url = config.get_api_url() r = requests.post(f'{url}/allocate', json=data) assert r.status_code == 202 r = get_allocation(orderid) assert r.ok assert r.json() == [ { 'sku': sku, 'batchref': batch2 }, ]
def wait_for_webapp_to_come_up(): return requests.get(config.get_api_url())
def get_allocation(orderid): url = config.get_api_url() return requests.get(f"{url}/allocations/{orderid}")
def post_to_allocate(orderid, sku, qty, expect_success=True): url = config.get_api_url()