Skip to content

Commit 974ec85

Browse files
committed
Define smoke tests & add tests manual
1 parent 2ba76a5 commit 974ec85

File tree

9 files changed

+54
-1
lines changed

9 files changed

+54
-1
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ test-integration:
2828
test-unit:
2929
docker-compose run --rm --no-deps --entrypoint=pytest app /tests/unit -v -s
3030

31+
test-smoke:
32+
docker-compose run --rm --no-deps --entrypoint=pytest app /tests -vv -s -m smoke
33+
3134
check-black:
3235
black --line-length 80 --diff --check .
3336

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,31 @@ Example application code for the [Architecture Patterns with Python](https://www
55
[![DeepSource](https://deepsource.io/gh/heykarimoff/cosmicpython-code.svg/?label=active+issues&show_trend=true&token=Q8CoowvMEAg9gbFgHrXaVOmX)](https://deepsource.io/gh/heykarimoff/cosmicpython-code/?ref=repository-badge)
66

77
Visit [API documentation](https://documenter.getpostman.com/view/14594760/Tz5iA1Vc) to see available endpoints.
8+
9+
### Installation
10+
Install dependencies:
11+
```sh
12+
pip install -r requirements.txt
13+
```
14+
15+
### Tests
16+
Run all tests:
17+
```sh
18+
make test
19+
```
20+
Run only unit tests:
21+
```sh
22+
make test-unit
23+
```
24+
Run only integration tests:
25+
```sh
26+
make test-integration
27+
```
28+
Run only end-to-end tests:
29+
```sh
30+
make test-e2e
31+
```
32+
Run only smoke tests:
33+
```sh
34+
make test-smoke
35+
```

tests/e2e/test_api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
pytestmark = pytest.mark.e2e
88

99

10+
@pytest.mark.smoke
1011
@pytest.mark.usefixtures("postgres_db")
1112
@pytest.mark.usefixtures("restart_api")
1213
def test_add_batch(url, random_sku, random_batchref):
@@ -38,6 +39,7 @@ def test_add_batch(url, random_sku, random_batchref):
3839
assert response.json()["message"] == "OK"
3940

4041

42+
@pytest.mark.smoke
4143
@pytest.mark.usefixtures("restart_api")
4244
def test_allocate_returns_200_and_allocated_batchref(
4345
url,
@@ -113,6 +115,7 @@ def test_allocate_returns_400_invalid_sku_message(
113115
assert response.status_code == 404, response.text
114116

115117

118+
@pytest.mark.smoke
116119
@pytest.mark.usefixtures("restart_api")
117120
def test_deallocate(
118121
url,
@@ -155,6 +158,7 @@ def test_deallocate(
155158
assert response.status_code == 200, response.text
156159

157160

161+
@pytest.mark.smoke
158162
@pytest.mark.usefixtures("restart_api")
159163
def test_change_batch_quantity_leading_to_reallocation(
160164
post_to_add_batch,

tests/integration/test_orm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import date
22

3+
import pytest
34
from allocation.domain import model
45

56

@@ -27,6 +28,7 @@ def test_orderline_mapper_can_save_lines(session):
2728
assert rows == [("order1", "DECORATIVE-WIDGET", 12)]
2829

2930

31+
@pytest.mark.smoke
3032
def test_retrieving_products(session):
3133
session.execute(
3234
"INSERT INTO products (sku) VALUES ('RED-CHAIR'), ('RED-TABLE')"
@@ -39,6 +41,7 @@ def test_retrieving_products(session):
3941
assert session.query(model.Product).all() == expected
4042

4143

44+
@pytest.mark.smoke
4245
def test_saving_products(session):
4346
product = model.Product("sku1", [])
4447
session.add(product)

tests/integration/test_views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def messagebus(session_factory):
1919
return bus
2020

2121

22+
@pytest.mark.smoke
2223
def test_allocations_view(messagebus, random_orderid):
2324
orderid = random_orderid()
2425
messagebus.handle(commands.CreateBatch("sku1batch", "sku1", 50, None))

tests/pytest.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
addopts = --tb=short
33
markers =
44
e2e: end-to-end tests.
5-
unit: fast-running tests.
5+
unit: fast-running tests.
6+
smoke: thorough tests.

tests/unit/test_batches.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import date, timedelta
22

3+
import pytest
34
from allocation.domain.model import Batch, OrderLine
45

56
today = date.today()
@@ -14,6 +15,7 @@ def make_batch_and_line(sku, batch_qty, line_qty):
1415
)
1516

1617

18+
@pytest.mark.smoke
1719
def test_allocating_to_a_batch_reduces_the_available_quantity():
1820
batch, line = make_batch_and_line("SMALL-TABLE", 20, 10)
1921

@@ -22,18 +24,21 @@ def test_allocating_to_a_batch_reduces_the_available_quantity():
2224
assert batch.available_quantity == 10
2325

2426

27+
@pytest.mark.smoke
2528
def test_can_allocate_if_available_greater_than_required():
2629
large_batch, small_line = make_batch_and_line("SMALL-TABLE", 20, 2)
2730

2831
assert large_batch.can_allocate(small_line)
2932

3033

34+
@pytest.mark.smoke
3135
def test_cannot_allocate_if_available_smaller_than_required():
3236
small_batch, large_line = make_batch_and_line("SMALL-TABLE", 10, 20)
3337

3438
assert not small_batch.can_allocate(large_line)
3539

3640

41+
@pytest.mark.smoke
3742
def test_can_allocate_if_available_equal_to_required():
3843
batch, line = make_batch_and_line("SMALL-TABLE", 20, 20)
3944

tests/unit/test_handlers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def messagebus():
6363
return bus
6464

6565

66+
@pytest.mark.smoke
6667
def test_add_batch_for_new_product(messagebus):
6768
message = commands.CreateBatch(
6869
reference="batch1", sku="COMPLICATED-LAMP", qty=100
@@ -76,6 +77,7 @@ def test_add_batch_for_new_product(messagebus):
7677
assert messagebus.uow.committed
7778

7879

80+
@pytest.mark.smoke
7981
def test_add_batch_for_existing_product(messagebus):
8082
history = [
8183
commands.CreateBatch(
@@ -96,6 +98,7 @@ def test_add_batch_for_existing_product(messagebus):
9698
assert messagebus.uow.committed
9799

98100

101+
@pytest.mark.smoke
99102
def test_allocate_returns_allocation(messagebus):
100103
message = commands.CreateBatch(
101104
reference="batch1", sku="COMPLICATED-LAMP", qty=100
@@ -124,6 +127,7 @@ def test_allocate_errors_for_invalid_sku(messagebus):
124127
messagebus.handle(message)
125128

126129

130+
@pytest.mark.smoke
127131
def test_deallocate(messagebus):
128132
message = commands.CreateBatch(
129133
reference="batch1", sku="COMPLICATED-LAMP", qty=100
@@ -149,6 +153,7 @@ def test_deallocate(messagebus):
149153
assert messagebus.uow.committed
150154

151155

156+
@pytest.mark.smoke
152157
def test_changes_available_quantity(messagebus):
153158
message = commands.CreateBatch(
154159
reference="batch1", sku="ADORABLE-SETTEE", qty=100

tests/unit/test_product.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import date, timedelta
22

3+
import pytest
34
from allocation.domain.events import OutOfStock
45
from allocation.domain.model import Batch, OrderLine, Product
56

@@ -8,6 +9,7 @@
89
later = tomorrow + timedelta(days=10)
910

1011

12+
@pytest.mark.smoke
1113
def test_prefers_warehouse_batches_to_shipments():
1214
in_stock_batch = Batch("batch-001", "BIG-SOFA", qty=20, eta=None)
1315
shipment_batch = Batch("batch-002", "BIG-SOFA", qty=20, eta=today)
@@ -31,6 +33,7 @@ def test_returns_allocated_batch_reference():
3133
assert allocation == in_stock_batch.reference
3234

3335

36+
@pytest.mark.smoke
3437
def test_prefers_earlier_batches():
3538
tomorrows_batch = Batch("batch-001", "MINI-SPOON", qty=20, eta=tomorrow)
3639
upcoming_batch = Batch("batch-001", "MINI-SPOON", qty=20, eta=later)

0 commit comments

Comments
 (0)