Skip to content

Commit 424b110

Browse files
committed
time to mock the dependencies
1 parent 2460f25 commit 424b110

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

apps/py/ch09_testing/test_fixtures.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import List
2+
import pytest
3+
import lib
4+
5+
6+
@pytest.fixture
7+
def guitar_data() -> List[lib.Guitar]:
8+
# This guitar data simulates our mock data to avoid DB calls and dependencies.
9+
guitars = [
10+
lib.Guitar('Jet Black Electric', 599, '/static/img/guitars/jet-black-electric.jpg', style='electric'),
11+
lib.Guitar('Weezer Classic', 1499, '/static/img/guitars/weezer-classic.jpg', style='electric'),
12+
lib.Guitar('Acoustic Black', 1299, '/static/img/guitars/black-acoustic.jpg', style='acoustic'),
13+
lib.Guitar('Brush Riffs', 599, '/static/img/guitars/brushed-black-electric.jpg', style='electric'),
14+
lib.Guitar('Electric Wood Grain', 399, '/static/img/guitars/woodgrain-electric.jpg', style='electric'),
15+
]
16+
guitars.sort(key=lambda g: g.price, reverse=True)
17+
return guitars

apps/py/ch09_testing/test_lib.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1+
import lib
2+
from test_fixtures import guitar_data
13

24

35
def test_something():
46
assert 7 == 7
7+
8+
9+
# def test_electric_guitars_wrong():
10+
# style = 'electric'
11+
# guitars = lib.all_guitars(style)
12+
# # sweet little generator expression
13+
# assert all(g.style == style for g in guitars)
14+
15+
16+
def test_electric_guitars(guitar_data):
17+
style = 'electric'
18+
guitars = lib.all_guitars(style)
19+
# sweet little generator expression
20+
assert all(g.style == style for g in guitars)

0 commit comments

Comments
 (0)