Skip to content

Commit

Permalink
Merge pull request eregs#515 from lbeaufort/404-for-missing-data
Browse files Browse the repository at this point in the history
Throw 404 for missing data
  • Loading branch information
cmc333333 authored May 14, 2018
2 parents 575226b + 6265e2e commit bcbe66e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion regulations/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
ALLOWED_HOSTS = ["*"]

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
Expand Down
14 changes: 14 additions & 0 deletions regulations/tests/views_chrome_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ class FakeView(chrome.ChromeView):
assert response.status_code == 404


def test_chrome_empty_meta(monkeypatch, rf):
"""Return 404 when trying to access missing regulation.
In this situation, `regulation_meta` returns {} """

chrome_view = chrome.ChromeView()

monkeypatch.setattr(chrome, 'fetch_grouped_history', Mock())
monkeypatch.setattr(chrome, 'fetch_toc', Mock(return_value=[]))
monkeypatch.setattr(chrome.utils, 'regulation_meta', Mock(return_value={}))

with pytest.raises(error_handling.MissingContentException):
chrome_view.set_chrome_context({}, '2', 'version')


def test_chrome_error_propagation(monkeypatch, rf):
"""While we don't rely on this sort of propagation for the main content
(much), test it in the sidebar"""
Expand Down
5 changes: 5 additions & 0 deletions regulations/views/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ def set_chrome_context(self, context, reg_part, version):
context['TOC'] = toc

context['meta'] = utils.regulation_meta(reg_part, version)

# Throw 404 if regulation doesn't exist
if not context['meta']:
raise error_handling.MissingContentException()

context['version_span'] = version_span(
context['history'], context['meta']['effective_date'])
context['version_switch_view'] = self.version_switch_view
Expand Down

0 comments on commit bcbe66e

Please sign in to comment.