Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
ff9e5f3f
Commit
ff9e5f3f
authored
8 years ago
by
Renzo Lucioni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make program details page 404 if no program data found
parent
efdb84ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
5 deletions
+30
-5
lms/djangoapps/learner_dashboard/tests/test_programs.py
+26
-5
lms/djangoapps/learner_dashboard/views.py
+4
-0
No files found.
lms/djangoapps/learner_dashboard/tests/test_programs.py
View file @
ff9e5f3f
...
@@ -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
)
This diff is collapsed.
Click to expand it.
lms/djangoapps/learner_dashboard/views.py
View file @
ff9e5f3f
...
@@ -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
=
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment