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

Only check status_code if call_url returns response #833

Merged
merged 2 commits into from
Sep 6, 2019
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
6 changes: 3 additions & 3 deletions anitya/lib/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@ def get_versions_by_regex(url, regex, project, insecure=False):
'Could not call : "%s" of "%s", with error: %s'
% (url, project.name, str(err))
)
# Not modified
if req.status_code == 304:
return []

if not isinstance(req, six.string_types):
# Not modified
if req.status_code == 304:
return []
req = req.text

return get_versions_by_regex_for_text(req, url, regex, project)
Expand Down
16 changes: 15 additions & 1 deletion anitya/tests/lib/backends/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class GetVersionsByRegexTests(unittest.TestCase):
@mock.patch("anitya.lib.backends.BaseBackend.call_url")
def test_get_versions_by_regex_not_modified(self, mock_call_url):
"""Assert that not modified response is handled correctly."""
mock_response = mock.Mock()
mock_response = mock.Mock(spec=object)
mock_response.status_code = 304
mock_call_url.return_value = mock_response
mock_project = mock.Mock()
Expand All @@ -168,6 +168,20 @@ def test_get_versions_by_regex_not_modified(self, mock_call_url):

self.assertEqual(versions, [])

@mock.patch("anitya.lib.backends.BaseBackend.call_url")
def test_get_versions_by_regex_string_response(self, mock_call_url):
"""Assert that string response is handled correctly."""
mock_call_url.return_value = ""
mock_project = mock.Mock()

self.assertRaises(
AnityaPluginException,
backends.get_versions_by_regex,
"url",
"regex",
mock_project,
)


class GetVersionsByRegexTextTests(unittest.TestCase):
"""
Expand Down
1 change: 1 addition & 0 deletions news/PR833.bug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Crash when calling FTP url