Commit ff9e5f3f by Renzo Lucioni

Make program details page 404 if no program data found

parent efdb84ca
...@@ -261,7 +261,7 @@ class TestProgramDetails(ProgramsApiConfigMixin, SharedModuleStoreTestCase): ...@@ -261,7 +261,7 @@ class TestProgramDetails(ProgramsApiConfigMixin, SharedModuleStoreTestCase):
course_codes=[self.course_code] course_codes=[self.course_code]
) )
def _mock_programs_api(self): def _mock_programs_api(self, data, status=200):
"""Helper for mocking out Programs API URLs.""" """Helper for mocking out Programs API URLs."""
self.assertTrue(httpretty.is_enabled(), msg='httpretty must be enabled to mock Programs API calls.') self.assertTrue(httpretty.is_enabled(), msg='httpretty must be enabled to mock Programs API calls.')
...@@ -269,9 +269,16 @@ class TestProgramDetails(ProgramsApiConfigMixin, SharedModuleStoreTestCase): ...@@ -269,9 +269,16 @@ class TestProgramDetails(ProgramsApiConfigMixin, SharedModuleStoreTestCase):
api_root=ProgramsApiConfig.current().internal_api_url.strip('/'), api_root=ProgramsApiConfig.current().internal_api_url.strip('/'),
id=self.program_id id=self.program_id
) )
body = json.dumps(self.data)
httpretty.register_uri(httpretty.GET, url, body=body, content_type='application/json') body = json.dumps(data)
httpretty.register_uri(
httpretty.GET,
url,
body=body,
status=status,
content_type='application/json',
)
def _assert_program_data_present(self, response): def _assert_program_data_present(self, response):
"""Verify that program data is present.""" """Verify that program data is present."""
...@@ -283,7 +290,7 @@ class TestProgramDetails(ProgramsApiConfigMixin, SharedModuleStoreTestCase): ...@@ -283,7 +290,7 @@ class TestProgramDetails(ProgramsApiConfigMixin, SharedModuleStoreTestCase):
Verify that login is required to access the page. Verify that login is required to access the page.
""" """
self.create_programs_config() self.create_programs_config()
self._mock_programs_api() self._mock_programs_api(self.data)
self.client.logout() self.client.logout()
...@@ -310,7 +317,7 @@ class TestProgramDetails(ProgramsApiConfigMixin, SharedModuleStoreTestCase): ...@@ -310,7 +317,7 @@ class TestProgramDetails(ProgramsApiConfigMixin, SharedModuleStoreTestCase):
def test_page_routing(self): def test_page_routing(self):
"""Verify that the page can be hit with or without a program name in the URL.""" """Verify that the page can be hit with or without a program name in the URL."""
self.create_programs_config() self.create_programs_config()
self._mock_programs_api() self._mock_programs_api(self.data)
response = self.client.get(self.details_page) response = self.client.get(self.details_page)
self._assert_program_data_present(response) self._assert_program_data_present(response)
...@@ -320,3 +327,17 @@ class TestProgramDetails(ProgramsApiConfigMixin, SharedModuleStoreTestCase): ...@@ -320,3 +327,17 @@ class TestProgramDetails(ProgramsApiConfigMixin, SharedModuleStoreTestCase):
response = self.client.get(self.details_page + 'program_name/invalid/') response = self.client.get(self.details_page + 'program_name/invalid/')
self.assertEquals(response.status_code, 404) self.assertEquals(response.status_code, 404)
def test_404_if_no_data(self):
"""Verify that the page 404s if no program data is found."""
self.create_programs_config()
self._mock_programs_api(self.data, status=404)
response = self.client.get(self.details_page)
self.assertEquals(response.status_code, 404)
httpretty.reset()
self._mock_programs_api({})
response = self.client.get(self.details_page)
self.assertEquals(response.status_code, 404)
...@@ -57,6 +57,10 @@ def program_details(request, program_id): ...@@ -57,6 +57,10 @@ def program_details(request, program_id):
raise Http404 raise Http404
program_data = utils.get_programs(request.user, program_id=program_id) program_data = utils.get_programs(request.user, program_id=program_id)
if not program_data:
raise Http404
program_data = utils.supplement_program_data(program_data, request.user) program_data = utils.supplement_program_data(program_data, request.user)
context = { context = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment