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
837b9baf
Commit
837b9baf
authored
Jul 13, 2016
by
Clinton Blackburn
Committed by
GitHub
Jul 13, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added program endpoint to API (#161)
ECOM-4897
parent
a4bed7bd
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
3 deletions
+79
-3
course_discovery/apps/api/serializers.py
+8
-1
course_discovery/apps/api/tests/test_serializers.py
+18
-2
course_discovery/apps/api/v1/tests/test_views/test_programs.py
+43
-0
course_discovery/apps/api/v1/urls.py
+1
-0
course_discovery/apps/api/v1/views.py
+9
-0
No files found.
course_discovery/apps/api/serializers.py
View file @
837b9baf
...
@@ -10,7 +10,7 @@ from rest_framework.fields import DictField
...
@@ -10,7 +10,7 @@ from rest_framework.fields import DictField
from
course_discovery.apps.catalogs.models
import
Catalog
from
course_discovery.apps.catalogs.models
import
Catalog
from
course_discovery.apps.course_metadata.models
import
(
from
course_discovery.apps.course_metadata.models
import
(
Course
,
CourseRun
,
Image
,
Organization
,
Person
,
Prerequisite
,
Seat
,
Subject
,
Video
Course
,
CourseRun
,
Image
,
Organization
,
Person
,
Prerequisite
,
Seat
,
Subject
,
Video
,
Program
)
)
from
course_discovery.apps.course_metadata.search_indexes
import
CourseIndex
,
CourseRunIndex
,
ProgramIndex
from
course_discovery.apps.course_metadata.search_indexes
import
CourseIndex
,
CourseRunIndex
,
ProgramIndex
...
@@ -250,6 +250,13 @@ class ContainedCoursesSerializer(serializers.Serializer):
...
@@ -250,6 +250,13 @@ class ContainedCoursesSerializer(serializers.Serializer):
)
)
class
ProgramSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Program
fields
=
(
'uuid'
,
'name'
,
'subtitle'
,
'category'
,
'marketing_slug'
,
'marketing_url'
,)
read_only_fields
=
(
'uuid'
,
'marketing_url'
,)
class
AffiliateWindowSerializer
(
serializers
.
ModelSerializer
):
class
AffiliateWindowSerializer
(
serializers
.
ModelSerializer
):
""" Serializer for Affiliate Window product feeds. """
""" Serializer for Affiliate Window product feeds. """
...
...
course_discovery/apps/api/tests/test_serializers.py
View file @
837b9baf
...
@@ -10,8 +10,8 @@ from rest_framework.test import APIRequestFactory
...
@@ -10,8 +10,8 @@ from rest_framework.test import APIRequestFactory
from
course_discovery.apps.api.serializers
import
(
from
course_discovery.apps.api.serializers
import
(
CatalogSerializer
,
CourseSerializer
,
CourseRunSerializer
,
ContainedCoursesSerializer
,
ImageSerializer
,
CatalogSerializer
,
CourseSerializer
,
CourseRunSerializer
,
ContainedCoursesSerializer
,
ImageSerializer
,
SubjectSerializer
,
PrerequisiteSerializer
,
VideoSerializer
,
OrganizationSerializer
,
SeatSerializer
,
SubjectSerializer
,
PrerequisiteSerializer
,
VideoSerializer
,
OrganizationSerializer
,
SeatSerializer
,
PersonSerializer
,
AffiliateWindowSerializer
,
ContainedCourseRunsSerializer
,
PersonSerializer
,
AffiliateWindowSerializer
,
ContainedCourseRunsSerializer
,
CourseRunSearchSerializer
,
CourseRunSearch
Serializer
,
ProgramSearchSerializer
Program
Serializer
,
ProgramSearchSerializer
)
)
from
course_discovery.apps.catalogs.tests.factories
import
CatalogFactory
from
course_discovery.apps.catalogs.tests.factories
import
CatalogFactory
from
course_discovery.apps.core.models
import
User
from
course_discovery.apps.core.models
import
User
...
@@ -167,6 +167,22 @@ class CourseRunSerializerTests(TestCase):
...
@@ -167,6 +167,22 @@ class CourseRunSerializerTests(TestCase):
self
.
assertEqual
(
serializer
.
data
[
'marketing_url'
],
None
)
self
.
assertEqual
(
serializer
.
data
[
'marketing_url'
],
None
)
class
ProgramSerializerTests
(
TestCase
):
def
test_data
(
self
):
program
=
ProgramFactory
()
serializer
=
ProgramSerializer
(
program
)
expected
=
{
'uuid'
:
str
(
program
.
uuid
),
'name'
:
program
.
name
,
'subtitle'
:
program
.
subtitle
,
'category'
:
program
.
category
,
'marketing_slug'
:
program
.
marketing_slug
,
'marketing_url'
:
program
.
marketing_url
,
}
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
class
ContainedCourseRunsSerializerTests
(
TestCase
):
class
ContainedCourseRunsSerializerTests
(
TestCase
):
def
test_data
(
self
):
def
test_data
(
self
):
instance
=
{
instance
=
{
...
...
course_discovery/apps/api/v1/tests/test_views/test_programs.py
0 → 100644
View file @
837b9baf
from
django.core.urlresolvers
import
reverse
from
rest_framework.test
import
APITestCase
from
course_discovery.apps.api.serializers
import
ProgramSerializer
from
course_discovery.apps.core.tests.factories
import
USER_PASSWORD
,
UserFactory
from
course_discovery.apps.course_metadata.models
import
Program
from
course_discovery.apps.course_metadata.tests.factories
import
ProgramFactory
class
ProgramViewSetTests
(
APITestCase
):
def
setUp
(
self
):
super
(
ProgramViewSetTests
,
self
)
.
setUp
()
self
.
user
=
UserFactory
(
is_staff
=
True
,
is_superuser
=
True
)
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
USER_PASSWORD
)
self
.
program
=
ProgramFactory
()
def
test_authentication
(
self
):
""" Verify the endpoint requires the user to be authenticated. """
url
=
reverse
(
'api:v1:program-list'
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
client
.
logout
()
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_get
(
self
):
""" Verify the endpoint returns the details for a single program. """
url
=
reverse
(
'api:v1:program-detail'
,
kwargs
=
{
'uuid'
:
self
.
program
.
uuid
})
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
,
ProgramSerializer
(
self
.
program
)
.
data
)
def
test_list
(
self
):
""" Verify the endpoint returns a list of all programs. """
url
=
reverse
(
'api:v1:program-list'
)
ProgramFactory
.
create_batch
(
3
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
[
'results'
],
ProgramSerializer
(
Program
.
objects
.
all
(),
many
=
True
)
.
data
)
course_discovery/apps/api/v1/urls.py
View file @
837b9baf
...
@@ -16,6 +16,7 @@ router.register(r'catalogs', views.CatalogViewSet)
...
@@ -16,6 +16,7 @@ router.register(r'catalogs', views.CatalogViewSet)
router
.
register
(
r'courses'
,
views
.
CourseViewSet
,
base_name
=
'course'
)
router
.
register
(
r'courses'
,
views
.
CourseViewSet
,
base_name
=
'course'
)
router
.
register
(
r'course_runs'
,
views
.
CourseRunViewSet
,
base_name
=
'course_run'
)
router
.
register
(
r'course_runs'
,
views
.
CourseRunViewSet
,
base_name
=
'course_run'
)
router
.
register
(
r'management'
,
views
.
ManagementViewSet
,
base_name
=
'management'
)
router
.
register
(
r'management'
,
views
.
ManagementViewSet
,
base_name
=
'management'
)
router
.
register
(
r'programs'
,
views
.
ProgramViewSet
,
base_name
=
'program'
)
router
.
register
(
r'search/all'
,
views
.
AggregateSearchViewSet
,
base_name
=
'search-all'
)
router
.
register
(
r'search/all'
,
views
.
AggregateSearchViewSet
,
base_name
=
'search-all'
)
router
.
register
(
r'search/courses'
,
views
.
CourseSearchViewSet
,
base_name
=
'search-courses'
)
router
.
register
(
r'search/courses'
,
views
.
CourseSearchViewSet
,
base_name
=
'search-courses'
)
router
.
register
(
r'search/course_runs'
,
views
.
CourseRunSearchViewSet
,
base_name
=
'search-course_runs'
)
router
.
register
(
r'search/course_runs'
,
views
.
CourseRunSearchViewSet
,
base_name
=
'search-course_runs'
)
...
...
course_discovery/apps/api/v1/views.py
View file @
837b9baf
...
@@ -275,6 +275,15 @@ class CourseRunViewSet(viewsets.ReadOnlyModelViewSet):
...
@@ -275,6 +275,15 @@ class CourseRunViewSet(viewsets.ReadOnlyModelViewSet):
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
class
ProgramViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
""" Program resource. """
lookup_field
=
'uuid'
lookup_value_regex
=
'[0-9a-f-]+'
queryset
=
Program
.
objects
.
all
()
permission_classes
=
(
IsAuthenticated
,)
serializer_class
=
serializers
.
ProgramSerializer
class
ManagementViewSet
(
viewsets
.
ViewSet
):
class
ManagementViewSet
(
viewsets
.
ViewSet
):
permission_classes
=
(
IsSuperuser
,)
permission_classes
=
(
IsSuperuser
,)
...
...
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