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

Fixed problem with not failing when status code != 200 during getting… #22

Merged
merged 1 commit into from
Jun 5, 2024
Merged
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
36 changes: 36 additions & 0 deletions test/extends/valhalla_extends_test.py
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)
2 changes: 1 addition & 1 deletion valhalla/common/get_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from yaml import safe_load

from valhalla.common.logger import info, error, warn
from valhalla.extends.ValhallaExtends import ValhallaExtends
from valhalla.extends.valhalla_extends import ValhallaExtends


class MergeRequestConfig:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@

from valhalla.common.logger import info, error
from valhalla.extends.merge_dicts import merge
from valhalla.common.resolver import resolve


def get_from_url(url):
result = ""
data = requests.get(resolve(url)).text
response = requests.get(url)

if response.status_code != 200:
info(f"Error: Received status code {response.status_code} from url: {url}")
exit(1)

data = response.text
for line in data:
result += line
info("Loaded from ULR")

info("Loaded from URL")
info("===========================================")
print(result)
info(result)
info("===========================================")
return result

Expand Down
Loading