Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[movie-lister] Added test fixture and updated documentation #747

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions docs/tutorials/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ Create ``tests.py`` in the ``movies`` package:
and put next into it:

.. code-block:: python
:emphasize-lines: 36,51
:emphasize-lines: 41,50

"""Tests module."""

Expand Down Expand Up @@ -941,13 +941,18 @@ and put next into it:
return container


def test_movies_directed_by(container):
@pytest.fixture
def finder_mock(container):
finder_mock = mock.Mock()
finder_mock.find_all.return_value = [
container.movie("The 33", 2015, "Patricia Riggen"),
container.movie("The Jungle Book", 2016, "Jon Favreau"),
]

return finder_mock


def test_movies_directed_by(container, finder_mock):
with container.finder.override(finder_mock):
lister = container.lister()
movies = lister.movies_directed_by("Jon Favreau")
Expand All @@ -956,13 +961,7 @@ and put next into it:
assert movies[0].title == "The Jungle Book"


def test_movies_released_in(container):
finder_mock = mock.Mock()
finder_mock.find_all.return_value = [
container.movie("The 33", 2015, "Patricia Riggen"),
container.movie("The Jungle Book", 2016, "Jon Favreau"),
]

def test_movies_released_in(container, finder_mock):
with container.finder.override(finder_mock):
lister = container.lister()
movies = lister.movies_released_in(2015)
Expand Down Expand Up @@ -995,9 +994,9 @@ You should see:
movies/entities.py 7 1 86%
movies/finders.py 26 13 50%
movies/listers.py 8 0 100%
movies/tests.py 23 0 100%
movies/tests.py 24 0 100%
------------------------------------------
TOTAL 89 30 66%
TOTAL 90 30 67%

.. note::

Expand Down
15 changes: 7 additions & 8 deletions examples/miniapps/movie-lister/movies/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ def container():
return container


def test_movies_directed_by(container):
@pytest.fixture
def finder_mock(container):
finder_mock = mock.Mock()
finder_mock.find_all.return_value = [
container.movie("The 33", 2015, "Patricia Riggen"),
container.movie("The Jungle Book", 2016, "Jon Favreau"),
]

return finder_mock


def test_movies_directed_by(container, finder_mock):
with container.finder.override(finder_mock):
lister = container.lister()
movies = lister.movies_directed_by("Jon Favreau")
Expand All @@ -41,13 +46,7 @@ def test_movies_directed_by(container):
assert movies[0].title == "The Jungle Book"


def test_movies_released_in(container):
finder_mock = mock.Mock()
finder_mock.find_all.return_value = [
container.movie("The 33", 2015, "Patricia Riggen"),
container.movie("The Jungle Book", 2016, "Jon Favreau"),
]

def test_movies_released_in(container, finder_mock):
with container.finder.override(finder_mock):
lister = container.lister()
movies = lister.movies_released_in(2015)
Expand Down