Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
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
dd0ea544
Commit
dd0ea544
authored
7 years ago
by
Simon Chen
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #16018 from edx/clintonb/studio-api-partial-update
Fixed bug for partial updates for Studio API course runs endpoint
parents
386b1fc2
4b9f017d
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cms/djangoapps/api/v1/serializers/course_runs.py
+3
-1
3 additions, 1 deletion
cms/djangoapps/api/v1/serializers/course_runs.py
cms/djangoapps/api/v1/tests/test_views/test_course_runs.py
+11
-4
11 additions, 4 deletions
cms/djangoapps/api/v1/tests/test_views/test_course_runs.py
with
14 additions
and
5 deletions
cms/djangoapps/api/v1/serializers/course_runs.py
+
3
−
1
View file @
dd0ea544
...
...
@@ -112,7 +112,9 @@ class CourseRunSerializer(CourseRunTeamSerializerMixin, serializers.Serializer):
return
instance
def
update_team
(
self
,
instance
,
team
):
CourseAccessRole
.
objects
.
filter
(
course_id
=
instance
.
id
).
delete
()
# Existing data should remain intact when performing a partial update.
if
not
self
.
partial
:
CourseAccessRole
.
objects
.
filter
(
course_id
=
instance
.
id
).
delete
()
# TODO In the future we can optimize by getting users in a single query.
CourseAccessRole
.
objects
.
bulk_create
([
...
...
This diff is collapsed.
Click to expand it.
cms/djangoapps/api/v1/tests/test_views/test_course_runs.py
+
11
−
4
View file @
dd0ea544
...
...
@@ -36,9 +36,11 @@ class CourseRunViewSetTests(ModuleStoreTestCase):
assert
course_run
.
enrollment_end
==
enrollment_end
def
assert_access_role
(
self
,
course_run
,
user
,
role
):
# An error will be raised if the endpoint d
oesn'
t create the role
# An error will be raised if the endpoint d
id no
t create the role
CourseAccessRole
.
objects
.
get
(
course_id
=
course_run
.
id
,
user
=
user
,
role
=
role
)
assert
CourseAccessRole
.
objects
.
filter
(
course_id
=
course_run
.
id
).
count
()
==
1
def
assert_course_access_role_count
(
self
,
course_run
,
expected
):
assert
CourseAccessRole
.
objects
.
filter
(
course_id
=
course_run
.
id
).
count
()
==
expected
def
get_serializer_context
(
self
):
return
{
'
request
'
:
RequestFactory
().
get
(
''
)}
...
...
@@ -111,6 +113,7 @@ class CourseRunViewSetTests(ModuleStoreTestCase):
response
=
self
.
client
.
put
(
url
,
data
,
format
=
'
json
'
)
assert
response
.
status_code
==
200
self
.
assert_access_role
(
course_run
,
user
,
role
)
self
.
assert_course_access_role_count
(
course_run
,
1
)
course_run
=
modulestore
().
get_course
(
course_run
.
id
)
assert
response
.
data
==
CourseRunSerializer
(
course_run
,
context
=
self
.
get_serializer_context
()).
data
...
...
@@ -134,12 +137,13 @@ class CourseRunViewSetTests(ModuleStoreTestCase):
assert
response
.
data
==
{
'
team
'
:
[{
'
user
'
:
[
'
Object with username=test-user does not exist.
'
]}]}
def
test_partial_update
(
self
):
role
=
'
staff
'
start
=
datetime
.
datetime
.
now
(
pytz
.
UTC
).
replace
(
microsecond
=
0
)
course_run
=
CourseFactory
(
start
=
start
,
end
=
None
,
enrollment_start
=
None
,
enrollment_end
=
None
)
assert
CourseAccessRole
.
objects
.
filter
(
course_id
=
course_run
.
id
).
count
()
==
0
CourseAccessRole
.
objects
.
create
(
course_id
=
course_run
.
id
,
role
=
role
,
user
=
UserFactory
())
assert
CourseAccessRole
.
objects
.
filter
(
course_id
=
course_run
.
id
).
count
()
==
1
user
=
UserFactory
()
role
=
'
staff
'
data
=
{
'
team
'
:
[
{
...
...
@@ -153,6 +157,7 @@ class CourseRunViewSetTests(ModuleStoreTestCase):
response
=
self
.
client
.
patch
(
url
,
data
,
format
=
'
json
'
)
assert
response
.
status_code
==
200
self
.
assert_access_role
(
course_run
,
user
,
role
)
self
.
assert_course_access_role_count
(
course_run
,
2
)
course_run
=
modulestore
().
get_course
(
course_run
.
id
)
self
.
assert_course_run_schedule
(
course_run
,
start
,
None
,
None
,
None
)
...
...
@@ -193,6 +198,7 @@ class CourseRunViewSetTests(ModuleStoreTestCase):
assert
course_run
.
id
.
run
==
data
[
'
run
'
]
self
.
assert_course_run_schedule
(
course_run
,
start
,
end
,
enrollment_start
,
enrollment_end
)
self
.
assert_access_role
(
course_run
,
user
,
role
)
self
.
assert_course_access_role_count
(
course_run
,
1
)
def
test_images_upload
(
self
):
# http://www.django-rest-framework.org/api-guide/parsers/#fileuploadparser
...
...
@@ -260,6 +266,7 @@ class CourseRunViewSetTests(ModuleStoreTestCase):
assert
course_run
.
id
.
run
==
run
self
.
assert_course_run_schedule
(
course_run
,
start
,
end
,
enrollment_start
,
enrollment_end
)
self
.
assert_access_role
(
course_run
,
user
,
role
)
self
.
assert_course_access_role_count
(
course_run
,
1
)
def
test_rerun_duplicate_run
(
self
):
course_run
=
ToyCourseFactory
()
...
...
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