diff --git a/regulations/settings/base.py b/regulations/settings/base.py index f2e24d349..feaab905c 100644 --- a/regulations/settings/base.py +++ b/regulations/settings/base.py @@ -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 diff --git a/regulations/tests/views_chrome_tests.py b/regulations/tests/views_chrome_tests.py index 10915d254..16b925905 100644 --- a/regulations/tests/views_chrome_tests.py +++ b/regulations/tests/views_chrome_tests.py @@ -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""" diff --git a/regulations/views/chrome.py b/regulations/views/chrome.py index fca0a887a..b7c3e6f7b 100644 --- a/regulations/views/chrome.py +++ b/regulations/views/chrome.py @@ -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