Skip to content

Commit 8ee0a93

Browse files
committed
Test for our external events [redis_e2e_test]
1 parent c69661d commit 8ee0a93

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ flask
44
psycopg2-binary
55
redis
66

7-
# tests
7+
# dev/tests
88
pytest
99
pytest-icdiff
1010
mypy
11+
pylint
1112
requests
1213
tenacity

tests/e2e/test_external_events.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import json
2+
import pytest
3+
from tenacity import Retrying, RetryError, stop_after_delay
4+
from . import api_client, redis_client
5+
from ..random_refs import random_batchref, random_orderid, random_sku
6+
7+
8+
@pytest.mark.usefixtures("postgres_db")
9+
@pytest.mark.usefixtures("restart_api")
10+
@pytest.mark.usefixtures("restart_redis_pubsub")
11+
def test_change_batch_quantity_leading_to_reallocation():
12+
# start with two batches and an order allocated to one of them
13+
orderid, sku = random_orderid(), random_sku()
14+
earlier_batch, later_batch = random_batchref("old"), random_batchref("newer")
15+
api_client.post_to_add_batch(earlier_batch, sku, qty=10, eta="2011-01-01")
16+
api_client.post_to_add_batch(later_batch, sku, qty=10, eta="2011-01-02")
17+
response = api_client.post_to_allocate(orderid, sku, 10)
18+
assert response.json()["batchref"] == earlier_batch
19+
20+
subscription = redis_client.subscribe_to("line_allocated")
21+
22+
# change quantity on allocated batch so it's less than our order
23+
redis_client.publish_message(
24+
"change_batch_quantity",
25+
{"batchref": earlier_batch, "qty": 5},
26+
)
27+
28+
# wait until we see a message saying the order has been reallocated
29+
messages = []
30+
for attempt in Retrying(stop=stop_after_delay(3), reraise=True):
31+
with attempt:
32+
message = subscription.get_message(timeout=1)
33+
if message:
34+
messages.append(message)
35+
print(messages)
36+
data = json.loads(messages[-1]["data"])
37+
assert data["orderid"] == orderid
38+
assert data["batchref"] == later_batch

tests/pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[pytest]
22
addopts = --tb=short
3+
filterwarnings =
4+
ignore::DeprecationWarning

0 commit comments

Comments
 (0)