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
6a10861b
Commit
6a10861b
authored
Oct 26, 2015
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10346 from edx/clintonb/credit-api-update
Updated CreditCourse update endpoint
parents
e726d01d
98a39b92
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
9 deletions
+35
-9
openedx/core/djangoapps/credit/tests/test_views.py
+29
-5
openedx/core/djangoapps/credit/views.py
+6
-4
No files found.
openedx/core/djangoapps/credit/tests/test_views.py
View file @
6a10861b
...
@@ -469,24 +469,48 @@ class CreditCourseViewSetTests(TestCase):
...
@@ -469,24 +469,48 @@ class CreditCourseViewSetTests(TestCase):
response
=
self
.
client
.
get
(
self
.
path
,
**
headers
)
response
=
self
.
client
.
get
(
self
.
path
,
**
headers
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_create
(
self
):
def
assert_course_created
(
self
,
course_id
,
response
):
""" Verify the endpoint supports creating new CreditCourse objects. """
""" Verify an API request created a new CreditCourse object. """
course_key
=
CourseKey
.
from_string
(
'a/b/c'
)
enabled
=
True
enabled
=
True
data
=
{
data
=
{
'course_key'
:
unicode
(
course_
key
),
'course_key'
:
unicode
(
course_
id
),
'enabled'
:
enabled
'enabled'
:
enabled
}
}
response
=
self
.
client
.
post
(
self
.
path
,
data
=
json
.
dumps
(
data
),
content_type
=
JSON
)
self
.
assertEqual
(
response
.
status_code
,
201
)
self
.
assertEqual
(
response
.
status_code
,
201
)
# Verify the API returns the serialized CreditCourse
# Verify the API returns the serialized CreditCourse
self
.
assertDictEqual
(
json
.
loads
(
response
.
content
),
data
)
self
.
assertDictEqual
(
json
.
loads
(
response
.
content
),
data
)
# Verify the CreditCourse was actually created
# Verify the CreditCourse was actually created
course_key
=
CourseKey
.
from_string
(
course_id
)
self
.
assertTrue
(
CreditCourse
.
objects
.
filter
(
course_key
=
course_key
,
enabled
=
enabled
)
.
exists
())
self
.
assertTrue
(
CreditCourse
.
objects
.
filter
(
course_key
=
course_key
,
enabled
=
enabled
)
.
exists
())
def
test_create
(
self
):
""" Verify the endpoint supports creating new CreditCourse objects. """
course_id
=
'a/b/c'
enabled
=
True
data
=
{
'course_key'
:
unicode
(
course_id
),
'enabled'
:
enabled
}
response
=
self
.
client
.
post
(
self
.
path
,
data
=
json
.
dumps
(
data
),
content_type
=
JSON
)
self
.
assert_course_created
(
course_id
,
response
)
def
test_put_as_create
(
self
):
""" Verify the update endpoint supports creating a new CreditCourse object. """
course_id
=
'd/e/f'
enabled
=
True
data
=
{
'course_key'
:
unicode
(
course_id
),
'enabled'
:
enabled
}
path
=
reverse
(
'credit:creditcourse-detail'
,
args
=
[
course_id
])
response
=
self
.
client
.
put
(
path
,
data
=
json
.
dumps
(
data
),
content_type
=
JSON
)
self
.
assert_course_created
(
course_id
,
response
)
def
test_get
(
self
):
def
test_get
(
self
):
""" Verify the endpoint supports retrieving CreditCourse objects. """
""" Verify the endpoint supports retrieving CreditCourse objects. """
course_id
=
'a/b/c'
course_id
=
'a/b/c'
...
...
openedx/core/djangoapps/credit/views.py
View file @
6a10861b
"""
"""
Views for the credit Django app.
Views for the credit Django app.
"""
"""
import
json
import
datetime
import
datetime
import
json
import
logging
import
logging
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -21,13 +21,15 @@ import pytz
...
@@ -21,13 +21,15 @@ import pytz
from
rest_framework
import
viewsets
,
mixins
,
permissions
from
rest_framework
import
viewsets
,
mixins
,
permissions
from
rest_framework.authentication
import
SessionAuthentication
from
rest_framework.authentication
import
SessionAuthentication
from
rest_framework_oauth.authentication
import
OAuth2Authentication
from
rest_framework_oauth.authentication
import
OAuth2Authentication
from
util.json_request
import
JsonResponse
from
util.date_utils
import
from_timestamp
from
openedx.core.djangoapps.credit
import
api
from
openedx.core.djangoapps.credit
import
api
from
openedx.core.djangoapps.credit.exceptions
import
CreditApiBadRequest
,
CreditRequestNotFound
from
openedx.core.djangoapps.credit.exceptions
import
CreditApiBadRequest
,
CreditRequestNotFound
from
openedx.core.djangoapps.credit.models
import
CreditCourse
from
openedx.core.djangoapps.credit.models
import
CreditCourse
from
openedx.core.djangoapps.credit.serializers
import
CreditCourseSerializer
from
openedx.core.djangoapps.credit.serializers
import
CreditCourseSerializer
from
openedx.core.djangoapps.credit.signature
import
signature
,
get_shared_secret_key
from
openedx.core.djangoapps.credit.signature
import
signature
,
get_shared_secret_key
from
openedx.core.lib.api.mixins
import
PutAsCreateMixin
from
util.date_utils
import
from_timestamp
from
util.json_request
import
JsonResponse
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -371,7 +373,7 @@ def _validate_timestamp(timestamp_value, provider_id):
...
@@ -371,7 +373,7 @@ def _validate_timestamp(timestamp_value, provider_id):
return
HttpResponseForbidden
(
u"Timestamp is too far in the past."
)
return
HttpResponseForbidden
(
u"Timestamp is too far in the past."
)
class
CreditCourseViewSet
(
mixins
.
CreateModel
Mixin
,
mixins
.
UpdateModelMixin
,
viewsets
.
ReadOnlyModelViewSet
):
class
CreditCourseViewSet
(
PutAsCreate
Mixin
,
mixins
.
UpdateModelMixin
,
viewsets
.
ReadOnlyModelViewSet
):
""" CreditCourse endpoints. """
""" CreditCourse endpoints. """
lookup_field
=
'course_key'
lookup_field
=
'course_key'
...
...
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