Skip to content

Commit

Permalink
Web API: eregs#307 add port 443 as a “hidden” post for retrieving cur…
Browse files Browse the repository at this point in the history
…rent host.
  • Loading branch information
tadhg-ohiggins committed Sep 9, 2016
1 parent 56066c4 commit d2f10d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions regparser/web/jobs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def get_host():
"""
hostname = getattr(settings, "CANONICAL_HOSTNAME", "")
hostport = getattr(settings, "CANONICAL_PORT", "")
if hostport and hostport is not "80":
if hostport and hostport not in ("80", "443"):
hostport = ":%s" % hostport
elif hostport is "80":
elif hostport in ("80", "443"):
hostport = ""
return "%s%s" % (hostname, hostport)

Expand Down
19 changes: 7 additions & 12 deletions tests/test_web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,9 @@ def _check(port=None):
with patch.object(settings, "CANONICAL_PORT", "2323"):
_check(port=2323)

with patch.object(settings, "CANONICAL_PORT", "80"):
_check()

with patch.object(settings, "CANONICAL_PORT", ""):
_check()
for port in ("80", "443", ""):
with patch.object(settings, "CANONICAL_PORT", port):
_check()

with pytest.raises(ValueError) as err:
status_url("something", "something-without-a-slash")
Expand All @@ -353,10 +351,7 @@ def test_file_url():
for hx in hexes:
assert file_url(hx) == "%s:2323%s%s/" % (domain, urlpath, hx)

with patch.object(settings, "CANONICAL_PORT", "80"):
for hx in hexes:
assert file_url(hx) == "%s%s%s/" % (domain, urlpath, hx)

with patch.object(settings, "CANONICAL_PORT", ""):
for hx in hexes:
assert file_url(hx) == "%s%s%s/" % (domain, urlpath, hx)
for port in ("80", "443", ""):
with patch.object(settings, "CANONICAL_PORT", port):
for hx in hexes:
assert file_url(hx) == "%s%s%s/" % (domain, urlpath, hx)

0 comments on commit d2f10d1

Please sign in to comment.