Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
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
course-discovery
Commits
c2abe452
Commit
c2abe452
authored
Apr 19, 2018
by
zubair-arbi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENT-960 Fix catalogs creation bug due to request data format
parent
31ac8f5c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
course_discovery/apps/api/v1/tests/test_views/test_catalogs.py
+4
-5
course_discovery/apps/api/v1/views/catalogs.py
+4
-3
No files found.
course_discovery/apps/api/v1/tests/test_views/test_catalogs.py
View file @
c2abe452
...
@@ -129,11 +129,10 @@ class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixi
...
@@ -129,11 +129,10 @@ class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixi
data
=
{
data
=
{
'name'
:
'Test Catalog'
,
'name'
:
'Test Catalog'
,
'query'
:
'*:*'
,
'query'
:
'*:*'
,
'viewers'
:
','
.
join
(
viewers
)
'viewers'
:
str
(
viewers
),
}
}
# NOTE: We explicitly avoid using the JSON data type so that we properly test string parsing.
response
=
self
.
client
.
post
(
self
.
catalog_list_url
,
data
,
format
=
'json'
)
response
=
self
.
client
.
post
(
self
.
catalog_list_url
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
self
.
assertEqual
(
response
.
status_code
,
201
)
catalog
=
Catalog
.
objects
.
latest
()
catalog
=
Catalog
.
objects
.
latest
()
...
@@ -145,10 +144,10 @@ class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixi
...
@@ -145,10 +144,10 @@ class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixi
""" Verify no users are created if an error occurs while processing a create request. """
""" Verify no users are created if an error occurs while processing a create request. """
# The missing name and query fields should trigger an error
# The missing name and query fields should trigger an error
data
=
{
data
=
{
'viewers'
:
[
'new-guy'
]
'viewers'
:
str
([
'new-guy'
])
}
}
original_user_count
=
User
.
objects
.
count
()
original_user_count
=
User
.
objects
.
count
()
response
=
self
.
client
.
post
(
self
.
catalog_list_url
,
data
)
response
=
self
.
client
.
post
(
self
.
catalog_list_url
,
data
,
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
400
)
self
.
assertEqual
(
response
.
status_code
,
400
)
self
.
assertEqual
(
User
.
objects
.
count
(),
original_user_count
)
self
.
assertEqual
(
User
.
objects
.
count
(),
original_user_count
)
...
...
course_discovery/apps/api/v1/views/catalogs.py
View file @
c2abe452
import
ast
import
datetime
import
datetime
from
django.db
import
transaction
from
django.db
import
transaction
...
@@ -32,13 +33,13 @@ class CatalogViewSet(viewsets.ModelViewSet):
...
@@ -32,13 +33,13 @@ class CatalogViewSet(viewsets.ModelViewSet):
@transaction.atomic
@transaction.atomic
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
""" Create a new catalog. """
""" Create a new catalog. """
data
=
request
.
data
.
copy
(
)
data
=
dict
(
request
.
data
.
copy
()
)
usernames
=
request
.
data
.
get
(
'viewers'
,
())
usernames
=
request
.
data
.
get
(
'viewers'
,
())
# Add support for parsing a comma-separated list from Swagger
# Add support for parsing a comma-separated list from Swagger
if
isinstance
(
usernames
,
str
):
if
isinstance
(
usernames
,
str
):
usernames
=
usernames
.
split
(
','
)
usernames
=
ast
.
literal_eval
(
usernames
)
data
.
setlist
(
'viewers'
,
usernames
)
data
[
'viewers'
]
=
usernames
# Ensure the users exist
# Ensure the users exist
for
username
in
usernames
:
for
username
in
usernames
:
...
...
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