Skip to content

Commit

Permalink
Validate URL accordingly (closes #155)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelpivato committed Nov 4, 2020
1 parent 734763f commit e3ac606
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion changelogs/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def find_repo_urls(session, name, candidates):
:return: str, URL to a repo
"""
for _url in candidates:
if validate_url(_url):
_url = validate_url(_url)
if _url:
try:
resp = session.get(_url)
if resp.status_code == 200:
Expand Down
22 changes: 19 additions & 3 deletions tests/test_finder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from changelogs.finder import contains_project_name
from unittest.mock import Mock

from changelogs.finder import contains_project_name, find_repo_urls


def test_contains_project_name():
Expand All @@ -19,5 +21,19 @@ def test_not_contains_project_name():
assert not call('dj-dashboard', 'https://github.com/pydanny/cookiecutter-djangopackage')


def test_find_repo_urls():
pass
def test_find_repo_urls_invalid_candidate():
session = Mock()
list(find_repo_urls(session, 'foobar', ['invalid-link']))
assert not session.get.called


def test_find_repo_urls_valid_candidate():
session = Mock()
list(find_repo_urls(session, 'foobar', ['http://example.com/link']))
session.get.assert_called_with('http://example.com/link')


def test_find_repo_urls_domain_candidate():
session = Mock()
list(find_repo_urls(session, 'foobar', ['example.com']))
session.get.assert_called_with('http://example.com')

0 comments on commit e3ac606

Please sign in to comment.