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
70053336
Commit
70053336
authored
Jul 31, 2017
by
muhammad-ammar
Committed by
Muhammad Ammar
Jul 31, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix serializer fields
parent
edec9391
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
8 deletions
+42
-8
course_discovery/apps/publisher/serializers.py
+14
-8
course_discovery/apps/publisher/tests/test_views.py
+28
-0
No files found.
course_discovery/apps/publisher/serializers.py
View file @
70053336
...
@@ -61,14 +61,17 @@ class CourseSerializer(serializers.Serializer): # pylint: disable=abstract-meth
...
@@ -61,14 +61,17 @@ class CourseSerializer(serializers.Serializer): # pylint: disable=abstract-meth
"""
"""
Returns a dict containing `status` and `date` for course team status.
Returns a dict containing `status` and `date` for course team status.
"""
"""
default_status
=
{
'status'
:
''
,
'date'
:
''
}
try
:
try
:
course_team_status
=
course
.
course_state
.
course_team_status
course_team_status
=
course
.
course_state
.
course_team_status
except
ObjectDoesNotExist
:
except
ObjectDoesNotExist
:
return
{
return
default_status
'status'
:
''
,
'date'
:
''
}
course_team_status
=
default_status
if
course_team_status
is
None
else
course_team_status
course_team_status_date
=
course_team_status
.
get
(
'date'
,
''
)
course_team_status_date
=
course_team_status
.
get
(
'date'
,
''
)
return
{
return
{
'status'
:
course_team_status
.
get
(
'status_text'
,
''
),
'status'
:
course_team_status
.
get
(
'status_text'
,
''
),
...
@@ -79,14 +82,17 @@ class CourseSerializer(serializers.Serializer): # pylint: disable=abstract-meth
...
@@ -79,14 +82,17 @@ class CourseSerializer(serializers.Serializer): # pylint: disable=abstract-meth
"""
"""
Returns a dict containing `status` and `date` for internal user status.
Returns a dict containing `status` and `date` for internal user status.
"""
"""
default_status
=
{
'status'
:
''
,
'date'
:
''
}
try
:
try
:
internal_user_status
=
course
.
course_state
.
internal_user_status
internal_user_status
=
course
.
course_state
.
internal_user_status
except
ObjectDoesNotExist
:
except
ObjectDoesNotExist
:
return
{
return
default_status
'status'
:
''
,
'date'
:
''
}
internal_user_status
=
default_status
if
internal_user_status
is
None
else
internal_user_status
internal_user_status_date
=
internal_user_status
.
get
(
'date'
,
''
)
internal_user_status_date
=
internal_user_status
.
get
(
'date'
,
''
)
return
{
return
{
'status'
:
internal_user_status
.
get
(
'status_text'
,
''
),
'status'
:
internal_user_status
.
get
(
'status_text'
,
''
),
...
...
course_discovery/apps/publisher/tests/test_views.py
View file @
70053336
...
@@ -11,6 +11,7 @@ from django.conf import settings
...
@@ -11,6 +11,7 @@ from django.conf import settings
from
django.contrib.auth.models
import
Group
from
django.contrib.auth.models
import
Group
from
django.contrib.sites.models
import
Site
from
django.contrib.sites.models
import
Site
from
django.core
import
mail
from
django.core
import
mail
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.db
import
IntegrityError
from
django.db
import
IntegrityError
from
django.forms
import
model_to_dict
from
django.forms
import
model_to_dict
from
django.test
import
TestCase
from
django.test
import
TestCase
...
@@ -1956,6 +1957,33 @@ class CourseListViewPaginationTests(PaginationMixin, TestCase):
...
@@ -1956,6 +1957,33 @@ class CourseListViewPaginationTests(PaginationMixin, TestCase):
self
.
assertEqual
(
response
.
context_data
[
'publisher_courses_url'
],
reverse
(
'publisher:publisher_courses'
))
self
.
assertEqual
(
response
.
context_data
[
'publisher_courses_url'
],
reverse
(
'publisher:publisher_courses'
))
self
.
assertEqual
(
response
.
context_data
[
'allowed_page_sizes'
],
json
.
dumps
(
COURSES_ALLOWED_PAGE_SIZES
))
self
.
assertEqual
(
response
.
context_data
[
'allowed_page_sizes'
],
json
.
dumps
(
COURSES_ALLOWED_PAGE_SIZES
))
@mock.patch
(
'course_discovery.apps.publisher.models.CourseState.course_team_status'
,
new_callable
=
mock
.
PropertyMock
)
@mock.patch
(
'course_discovery.apps.publisher.models.CourseState.internal_user_status'
,
new_callable
=
mock
.
PropertyMock
)
def
test_course_state_statuses
(
self
,
mocked_internal_user_status
,
mocked_course_team_status
):
""" Verify that course_state statuses raise no exception. """
mocked_internal_user_status
.
return_value
=
None
mocked_course_team_status
.
return_value
=
None
courses
=
self
.
get_courses
()
for
course
in
courses
:
self
.
assertEqual
(
course
[
'course_team_status'
],
{
'status'
:
''
,
'date'
:
''
})
self
.
assertEqual
(
course
[
'internal_user_status'
],
{
'status'
:
''
,
'date'
:
''
})
@mock.patch
(
'course_discovery.apps.publisher.models.CourseState.course_team_status'
,
new_callable
=
mock
.
PropertyMock
)
@mock.patch
(
'course_discovery.apps.publisher.models.CourseState.internal_user_status'
,
new_callable
=
mock
.
PropertyMock
)
def
test_course_state_exceptions
(
self
,
mocked_internal_user_status
,
mocked_course_team_status
):
"""
Verify that course_team_status and internal_user_status return
default status when course.course_status does not exist.
"""
mocked_internal_user_status
.
side_effect
=
ObjectDoesNotExist
mocked_course_team_status
.
side_effect
=
ObjectDoesNotExist
courses
=
self
.
get_courses
()
for
course
in
courses
:
self
.
assertEqual
(
course
[
'course_team_status'
],
{
'status'
:
''
,
'date'
:
''
})
self
.
assertEqual
(
course
[
'internal_user_status'
],
{
'status'
:
''
,
'date'
:
''
})
class
CourseDetailViewTests
(
TestCase
):
class
CourseDetailViewTests
(
TestCase
):
""" Tests for the course detail view. """
""" Tests for the course detail view. """
...
...
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