-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed problem with not failing when status code != 200 during getting…
… config to be extended
- Loading branch information
pz2
committed
Jun 5, 2024
1 parent
c3ad3c3
commit eb4b124
Showing
3 changed files
with
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import unittest | ||
from unittest.mock import patch, Mock | ||
|
||
from valhalla.extends.valhalla_extends import get_from_url | ||
|
||
|
||
class TestGetFromUrl(unittest.TestCase): | ||
|
||
@patch('requests.get') | ||
def test_get_from_url_success(self, mock_get): | ||
# given: | ||
mock_response = Mock() | ||
mock_response.status_code = 200 | ||
mock_response.text = "Success" | ||
mock_get.return_value = mock_response | ||
|
||
# when: | ||
result = get_from_url('http://example.com') | ||
|
||
# then: | ||
self.assertEqual(result, "Success") | ||
|
||
@patch('requests.get') | ||
@patch('valhalla.extends.valhalla_extends.exit') | ||
def test_get_from_url_failure(self, mock_exit, mock_get): | ||
# given: | ||
mock_response = Mock() | ||
mock_response.status_code = 404 | ||
mock_response.text = "Not Found" | ||
mock_get.return_value = mock_response | ||
|
||
# when: | ||
get_from_url('http://example.com') | ||
|
||
# then: | ||
mock_exit.assert_called_with(1) |
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