-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit tests and rename subpackage services -> service
- Loading branch information
1 parent
5006b9f
commit 3b8fb14
Showing
7 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
60 changes: 60 additions & 0 deletions
60
tests/software_tests/database/service/test_abstract_service.py
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,60 @@ | ||
import pytest | ||
from mock import Mock | ||
|
||
|
||
from uds.database.service.abstract_service import AbstractService | ||
|
||
|
||
class TestAbstractService: | ||
"""Unit tests for Abstract Service.""" | ||
|
||
def setup_method(self): | ||
self.mock_abstract_service = Mock(spec=AbstractService) | ||
|
||
# encode | ||
|
||
@pytest.mark.parametrize("sid, request_sid, response_sid", [ | ||
(1, 1, 2), | ||
(0x11, 0x11, 0x51), | ||
]) | ||
@pytest.mark.parametrize("data_records_values", [ | ||
{}, | ||
{"a": 1, "b": 2, "c": 3, "xyz": None} | ||
]) | ||
def test_encode__request(self, sid, request_sid, response_sid, data_records_values): | ||
self.mock_abstract_service.request_sid = request_sid | ||
self.mock_abstract_service.response_sid = response_sid | ||
assert (AbstractService.encode(self=self.mock_abstract_service, sid=sid, **data_records_values) | ||
== self.mock_abstract_service.encode_request.return_value) | ||
self.mock_abstract_service.encode_request.assert_called_once_with(**data_records_values) | ||
|
||
@pytest.mark.parametrize("sid, request_sid, response_sid", [ | ||
(2, 1, 2), | ||
(0x51, 0x11, 0x51), | ||
]) | ||
@pytest.mark.parametrize("data_records_values", [ | ||
{}, | ||
{"a": 1, "b": 2, "c": 3, "xyz": None} | ||
]) | ||
def test_encode__response(self, sid, request_sid, response_sid, data_records_values): | ||
self.mock_abstract_service.request_sid = request_sid | ||
self.mock_abstract_service.response_sid = response_sid | ||
assert (AbstractService.encode(self=self.mock_abstract_service, sid=sid, **data_records_values) | ||
== self.mock_abstract_service.encode_response.return_value) | ||
self.mock_abstract_service.encode_response.assert_called_once_with(**data_records_values) | ||
|
||
@pytest.mark.parametrize("sid, request_sid, response_sid", [ | ||
(0, 1, 2), | ||
(0x11, 0x10, 0x50), | ||
]) | ||
@pytest.mark.parametrize("data_records_values", [ | ||
{}, | ||
{"a": 1, "b": 2, "c": 3, "xyz": None} | ||
]) | ||
def test_encode__value_error(self, sid, request_sid, response_sid, data_records_values): | ||
self.mock_abstract_service.request_sid = request_sid | ||
self.mock_abstract_service.response_sid = response_sid | ||
with pytest.raises(ValueError): | ||
AbstractService.encode(self=self.mock_abstract_service, sid=sid, **data_records_values) | ||
self.mock_abstract_service.encode_request.asseert_not_called() | ||
self.mock_abstract_service.encode_response.asseert_not_called() |
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
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
File renamed without changes.
File renamed without changes.