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
cce00e69
Commit
cce00e69
authored
Mar 12, 2015
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7310 from edx/mobile/MA-125
MA-125 Mobile Enrollment API: add certificate info.
parents
3c4252e7
9f0d6c00
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
2 deletions
+40
-2
lms/djangoapps/mobile_api/users/serializers.py
+13
-1
lms/djangoapps/mobile_api/users/tests.py
+25
-1
lms/djangoapps/mobile_api/users/views.py
+2
-0
No files found.
lms/djangoapps/mobile_api/users/serializers.py
View file @
cce00e69
...
@@ -6,6 +6,7 @@ from rest_framework.reverse import reverse
...
@@ -6,6 +6,7 @@ from rest_framework.reverse import reverse
from
courseware.courses
import
course_image_url
from
courseware.courses
import
course_image_url
from
student.models
import
CourseEnrollment
,
User
from
student.models
import
CourseEnrollment
,
User
from
certificates.models
import
certificate_status_for_student
,
CertificateStatuses
class
CourseField
(
serializers
.
RelatedField
):
class
CourseField
(
serializers
.
RelatedField
):
...
@@ -64,10 +65,21 @@ class CourseEnrollmentSerializer(serializers.ModelSerializer):
...
@@ -64,10 +65,21 @@ class CourseEnrollmentSerializer(serializers.ModelSerializer):
Serializes CourseEnrollment models
Serializes CourseEnrollment models
"""
"""
course
=
CourseField
()
course
=
CourseField
()
certificate
=
serializers
.
SerializerMethodField
(
'get_certificate'
)
def
get_certificate
(
self
,
model
):
"""Returns the information about the user's certificate in the course."""
certificate_info
=
certificate_status_for_student
(
model
.
user
,
model
.
course_id
)
if
certificate_info
[
'status'
]
==
CertificateStatuses
.
downloadable
:
return
{
"url"
:
certificate_info
[
'download_url'
],
}
else
:
return
{}
class
Meta
:
# pylint: disable=missing-docstring
class
Meta
:
# pylint: disable=missing-docstring
model
=
CourseEnrollment
model
=
CourseEnrollment
fields
=
(
'created'
,
'mode'
,
'is_active'
,
'course'
)
fields
=
(
'created'
,
'mode'
,
'is_active'
,
'course'
,
'certificate'
)
lookup_field
=
'username'
lookup_field
=
'username'
...
...
lms/djangoapps/mobile_api/users/tests.py
View file @
cce00e69
"""
"""
Tests for users API
Tests for users API
"""
"""
import
datetime
import
datetime
from
django.utils
import
timezone
from
django.utils
import
timezone
from
xmodule.modulestore.tests.factories
import
ItemFactory
,
CourseFactory
from
xmodule.modulestore.tests.factories
import
ItemFactory
,
CourseFactory
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
student.models
import
CourseEnrollment
from
student.models
import
CourseEnrollment
from
certificates.models
import
CertificateStatuses
from
certificates.tests.factories
import
GeneratedCertificateFactory
from
..
import
errors
from
..
import
errors
from
..testutils
import
MobileAPITestCase
,
MobileAuthTestMixin
,
MobileAuthUserTestMixin
,
MobileEnrolledCourseAccessTestMixin
from
..testutils
import
MobileAPITestCase
,
MobileAuthTestMixin
,
MobileAuthUserTestMixin
,
MobileEnrolledCourseAccessTestMixin
...
@@ -83,6 +84,29 @@ class TestUserEnrollmentApi(MobileAPITestCase, MobileAuthUserTestMixin, MobileEn
...
@@ -83,6 +84,29 @@ class TestUserEnrollmentApi(MobileAPITestCase, MobileAuthUserTestMixin, MobileEn
unicode
(
courses
[
num_courses
-
course_num
-
1
]
.
id
)
unicode
(
courses
[
num_courses
-
course_num
-
1
]
.
id
)
)
)
def
test_no_certificate
(
self
):
self
.
login_and_enroll
()
response
=
self
.
api_response
()
certificate_data
=
response
.
data
[
0
][
'certificate'
]
# pylint: disable=no-member
self
.
assertDictEqual
(
certificate_data
,
{})
def
test_certificate
(
self
):
self
.
login_and_enroll
()
certificate_url
=
"http://test_certificate_url"
GeneratedCertificateFactory
.
create
(
user
=
self
.
user
,
course_id
=
self
.
course
.
id
,
status
=
CertificateStatuses
.
downloadable
,
mode
=
'verified'
,
download_url
=
certificate_url
,
)
response
=
self
.
api_response
()
certificate_data
=
response
.
data
[
0
][
'certificate'
]
# pylint: disable=no-member
self
.
assertEquals
(
certificate_data
[
'url'
],
certificate_url
)
class
CourseStatusAPITestCase
(
MobileAPITestCase
):
class
CourseStatusAPITestCase
(
MobileAPITestCase
):
"""
"""
...
...
lms/djangoapps/mobile_api/users/views.py
View file @
cce00e69
...
@@ -210,6 +210,8 @@ class UserCourseEnrollmentsList(generics.ListAPIView):
...
@@ -210,6 +210,8 @@ class UserCourseEnrollmentsList(generics.ListAPIView):
* mode: The type of certificate registration for this course: honor or
* mode: The type of certificate registration for this course: honor or
certified.
certified.
* is_active: Whether the course is currently active; true or false.
* is_active: Whether the course is currently active; true or false.
* certificate: Information about the user's earned certificate in the course.
* url: URL to the downloadable version of the certificate, if exists.
* course: A collection of data about the course:
* course: A collection of data about the course:
* course_about: The URI to get the data for the course About page.
* course_about: The URI to get the data for the course About page.
...
...
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