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
c303d2cc
Commit
c303d2cc
authored
Aug 16, 2016
by
Renzo Lucioni
Committed by
GitHub
Aug 16, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #250 from edx/renzo/uuid-list-filter
Allow programs to be filtered by comma-separated UUIDs
parents
a9c5877c
61a3e903
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
8 deletions
+21
-8
course_discovery/apps/api/filters.py
+2
-1
course_discovery/apps/api/v1/tests/test_views/test_programs.py
+19
-7
No files found.
course_discovery/apps/api/filters.py
View file @
c303d2cc
...
@@ -93,7 +93,8 @@ class CourseRunFilter(django_filters.FilterSet):
...
@@ -93,7 +93,8 @@ class CourseRunFilter(django_filters.FilterSet):
class
ProgramFilter
(
django_filters
.
FilterSet
):
class
ProgramFilter
(
django_filters
.
FilterSet
):
type
=
django_filters
.
CharFilter
(
name
=
'type__name'
,
lookup_expr
=
'iexact'
)
type
=
django_filters
.
CharFilter
(
name
=
'type__name'
,
lookup_expr
=
'iexact'
)
uuids
=
CharListFilter
(
name
=
'uuid'
,
lookup_type
=
'in'
)
class
Meta
:
class
Meta
:
model
=
Program
model
=
Program
fields
=
[
'type'
]
fields
=
[
'type'
,
'uuids'
]
course_discovery/apps/api/v1/tests/test_views/test_programs.py
View file @
c303d2cc
...
@@ -8,6 +8,8 @@ from course_discovery.apps.course_metadata.tests.factories import ProgramFactory
...
@@ -8,6 +8,8 @@ from course_discovery.apps.course_metadata.tests.factories import ProgramFactory
class
ProgramViewSetTests
(
APITestCase
):
class
ProgramViewSetTests
(
APITestCase
):
list_path
=
reverse
(
'api:v1:program-list'
)
def
setUp
(
self
):
def
setUp
(
self
):
super
(
ProgramViewSetTests
,
self
)
.
setUp
()
super
(
ProgramViewSetTests
,
self
)
.
setUp
()
self
.
user
=
UserFactory
(
is_staff
=
True
,
is_superuser
=
True
)
self
.
user
=
UserFactory
(
is_staff
=
True
,
is_superuser
=
True
)
...
@@ -16,13 +18,11 @@ class ProgramViewSetTests(APITestCase):
...
@@ -16,13 +18,11 @@ class ProgramViewSetTests(APITestCase):
def
test_authentication
(
self
):
def
test_authentication
(
self
):
""" Verify the endpoint requires the user to be authenticated. """
""" Verify the endpoint requires the user to be authenticated. """
url
=
reverse
(
'api:v1:program-list'
)
response
=
self
.
client
.
get
(
self
.
list_path
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
client
.
logout
()
self
.
client
.
logout
()
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
self
.
list_path
)
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_get
(
self
):
def
test_get
(
self
):
...
@@ -35,16 +35,15 @@ class ProgramViewSetTests(APITestCase):
...
@@ -35,16 +35,15 @@ class ProgramViewSetTests(APITestCase):
def
test_list
(
self
):
def
test_list
(
self
):
""" Verify the endpoint returns a list of all programs. """
""" Verify the endpoint returns a list of all programs. """
url
=
reverse
(
'api:v1:program-list'
)
ProgramFactory
.
create_batch
(
3
)
ProgramFactory
.
create_batch
(
3
)
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
self
.
list_path
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
[
'results'
],
ProgramSerializer
(
Program
.
objects
.
all
(),
many
=
True
)
.
data
)
self
.
assertEqual
(
response
.
data
[
'results'
],
ProgramSerializer
(
Program
.
objects
.
all
(),
many
=
True
)
.
data
)
def
test_filter_by_type
(
self
):
def
test_filter_by_type
(
self
):
""" Verify that the endpoint filters programs to those of a given type. """
""" Verify that the endpoint filters programs to those of a given type. """
url
=
reverse
(
'api:v1:program-list'
)
+
'?type='
url
=
self
.
list_path
+
'?type='
self
.
program
.
type
=
ProgramTypeFactory
(
name
=
'Foo'
)
self
.
program
.
type
=
ProgramTypeFactory
(
name
=
'Foo'
)
self
.
program
.
save
()
# pylint: disable=no-member
self
.
program
.
save
()
# pylint: disable=no-member
...
@@ -54,3 +53,16 @@ class ProgramViewSetTests(APITestCase):
...
@@ -54,3 +53,16 @@ class ProgramViewSetTests(APITestCase):
response
=
self
.
client
.
get
(
url
+
'bar'
)
response
=
self
.
client
.
get
(
url
+
'bar'
)
self
.
assertEqual
(
response
.
data
[
'results'
],
[])
self
.
assertEqual
(
response
.
data
[
'results'
],
[])
def
test_filter_by_uuids
(
self
):
""" Verify that the endpoint filters programs to those matching the provided UUIDs. """
url
=
self
.
list_path
+
'?uuids='
programs
=
[
ProgramFactory
(),
self
.
program
]
uuids
=
[
str
(
p
.
uuid
)
for
p
in
programs
]
# Create a third program, which should be filtered out.
ProgramFactory
()
response
=
self
.
client
.
get
(
url
+
','
.
join
(
uuids
))
self
.
assertEqual
(
response
.
data
[
'results'
],
ProgramSerializer
(
programs
,
many
=
True
)
.
data
)
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