-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add templates for unit test; chore: update dependencies
- Loading branch information
1 parent
d85e227
commit b78d3ad
Showing
5 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
Service unit testing best practice. | ||
""" | ||
|
||
import pytest | ||
from nameko.testing.services import worker_factory | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'value, expected', | ||
[ | ||
('John Doe', 'Hello, John Doe!'), | ||
('', 'Hello, !'), | ||
('Bryant', 'Hello, Bryant!'), | ||
], | ||
) | ||
def test_example_service(value, expected): | ||
""" | ||
Test example service. | ||
""" | ||
# create worker with mock dependencies | ||
service = worker_factory(ServiceName) # TODO replace ServiceName with the name of the service and import it | ||
|
||
# add side effects to the mock rpc dependency on the "remote" service | ||
service.remote.hello.side_effect = lambda name: "Hello, {}!".format(name) | ||
|
||
# test remote_hello business logic | ||
assert service.remote_hello(value) == expected | ||
service.remote.hello.assert_called_once_with(value) |