Skip to content

Commit 2f707da

Browse files
committed
Test for our external events [redis_e2e_test]
1 parent 780a9d0 commit 2f707da

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

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 .wait_for import wait_for
4+
from . import api_client, redis_client
5+
from ..random_refs import random_batchref, random_orderid, random_sku
6+
7+
8+
9+
@pytest.mark.usefixtures('postgres_db')
10+
@pytest.mark.usefixtures('restart_api')
11+
@pytest.mark.usefixtures('restart_redis_pubsub')
12+
def test_change_batch_quantity_leading_to_reallocation():
13+
# start with two batches and an order allocated to one of them
14+
orderid, sku = random_orderid(), random_sku()
15+
earlier_batch, later_batch = random_batchref('old'), random_batchref('newer')
16+
api_client.post_to_add_batch(earlier_batch, sku, qty=10, eta='2011-01-02')
17+
api_client.post_to_add_batch(later_batch, sku, qty=10, eta='2011-01-02')
18+
response = api_client.post_to_allocate(orderid, sku, 10)
19+
assert response.json()['batchref'] == earlier_batch
20+
21+
subscription = redis_client.subscribe_to('line_allocated')
22+
23+
# change quantity on allocated batch so it's less than our order
24+
redis_client.publish_message('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+
def assert_new_allocation_published():
31+
messages.append(wait_for(subscription.get_message))
32+
print(messages)
33+
data = json.loads(messages[-1]['data'])
34+
assert data['orderid'] == orderid
35+
assert data['batchref'] == later_batch
36+
return True
37+
38+
wait_for(assert_new_allocation_published)

0 commit comments

Comments
 (0)