-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: enhance coverage + refactoring on unit tests
Signed-off-by: ATTY Lionel <[email protected]>
- Loading branch information
ATTY Lionel
committed
Aug 20, 2024
1 parent
5a2d858
commit e359e12
Showing
7 changed files
with
141 additions
and
9 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
from cruft_helloworld import __project_name__ | ||
from cruft_helloworld.services.globe_emoji_with_geoip import ( | ||
URI_TO_DDG_API, | ||
get_external_ipv4, | ||
) | ||
|
||
|
||
def test_cant_extract_ip_address_error(requests_mock, caplog): | ||
mock_external_ipv4 = "Your IP address is dummy_ip in" | ||
mock_request_response = f'{{"Answer": "{mock_external_ipv4}"}}' | ||
requests_mock.get(URI_TO_DDG_API, text=mock_request_response) | ||
|
||
with caplog.at_level(logging.ERROR): | ||
assert get_external_ipv4() is None | ||
|
||
records = [record for record in caplog.records if __project_name__ in record.name] | ||
assert len(records) == 1, records | ||
assert records[0].levelname == "ERROR" | ||
assert records[0].message == f"Can't extract ip_address from: {mock_external_ipv4}" | ||
|
||
|
||
def test_not_valid_json_request_response_error(requests_mock, caplog): | ||
mock_request_response = "" | ||
requests_mock.get(URI_TO_DDG_API, text=mock_request_response) | ||
|
||
with caplog.at_level(logging.ERROR): | ||
assert get_external_ipv4() is None | ||
|
||
records = [record for record in caplog.records if __project_name__ in record.name] | ||
assert len(records) == 1, records | ||
assert records[0].levelname == "ERROR" | ||
expected_msg_error = ( | ||
f"Can't perform internet request: requests.get({URI_TO_DDG_API})!" | ||
) | ||
assert records[0].message == expected_msg_error |
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