Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
898db2e3
Commit
898db2e3
authored
7 years ago
by
Tasawer Nawaz
Browse files
Options
Downloads
Patches
Plain Diff
update CourseGoalViewSet to return status=400 if no goal key is provided LEARNER-3342
parent
fb5ca89f
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/course_goals/tests/test_api.py
+19
-8
19 additions, 8 deletions
lms/djangoapps/course_goals/tests/test_api.py
lms/djangoapps/course_goals/views.py
+9
-2
9 additions, 2 deletions
lms/djangoapps/course_goals/views.py
with
28 additions
and
10 deletions
lms/djangoapps/course_goals/tests/test_api.py
+
19
−
8
View file @
898db2e3
...
...
@@ -55,6 +55,17 @@ class TestCourseGoalsAPI(EventTrackingTestCase, SharedModuleStoreTestCase):
self
.
assertEqual
(
response
.
status_code
,
400
)
self
.
assertEqual
(
len
(
CourseGoal
.
objects
.
filter
(
user
=
self
.
user
,
course_key
=
self
.
course
.
id
)),
0
)
def
test_add_without_goal_key
(
self
):
"""
Ensures if no goal key provided, post does not succeed.
"""
response
=
self
.
post_course_goal
(
goal_key
=
None
)
self
.
assertEqual
(
len
(
CourseGoal
.
objects
.
filter
(
user
=
self
.
user
,
course_key
=
self
.
course
.
id
)),
0
)
self
.
assertContains
(
response
=
response
,
text
=
'
Please provide a valid goal key from following options.
'
,
status_code
=
400
)
@mock.patch
(
'
lms.djangoapps.course_goals.views.update_google_analytics
'
)
@override_settings
(
LMS_SEGMENT_KEY
=
"
foobar
"
)
def
test_update_goal
(
self
,
ga_call
):
...
...
@@ -74,12 +85,12 @@ class TestCourseGoalsAPI(EventTrackingTestCase, SharedModuleStoreTestCase):
Sends a post request to set a course goal and returns the response.
"""
goal_key
=
goal_key
if
valid
else
'
invalid
'
response
=
self
.
client
.
post
(
self
.
apiUrl
,
{
'
goal_key
'
:
goal_key
,
'
course_key
'
:
self
.
course
.
id
,
'
user
'
:
self
.
user
.
username
,
},
)
post_data
=
{
'
course_key
'
:
self
.
course
.
id
,
'
user
'
:
self
.
user
.
username
,
}
if
goal_key
:
post_data
[
'
goal_key
'
]
=
goal_key
response
=
self
.
client
.
post
(
self
.
apiUrl
,
post_data
)
return
response
This diff is collapsed.
Click to expand it.
lms/djangoapps/course_goals/views.py
+
9
−
2
View file @
898db2e3
...
...
@@ -61,8 +61,15 @@ class CourseGoalViewSet(viewsets.ModelViewSet):
"""
Create a new goal if one does not exist, otherwise update the existing goal.
"""
# Ensure goal_key is valid
goal_options
=
get_course_goal_options
()
goal_key
=
post_data
.
data
[
'
goal_key
'
]
if
goal_key
not
in
goal_options
:
goal_key
=
post_data
.
data
.
get
(
'
goal_key
'
)
if
not
goal_key
:
return
Response
(
'
Please provide a valid goal key from following options. (options= {goal_options}).
'
.
format
(
goal_options
=
goal_options
,
),
status
=
status
.
HTTP_400_BAD_REQUEST
,
)
elif
goal_key
not
in
goal_options
:
return
Response
(
'
Provided goal key, {goal_key}, is not a valid goal key (options= {goal_options}).
'
.
format
(
goal_key
=
goal_key
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment