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
29b83b3d
Commit
29b83b3d
authored
Dec 01, 2015
by
Eugeny Kolpakov
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #568 from edx-solutions/group_project_v2
Group Project updates to API
parents
a277d748
0ed2d9ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
1 deletions
+87
-1
lms/djangoapps/projects/tests/test_projects.py
+57
-1
lms/djangoapps/projects/views.py
+30
-0
No files found.
lms/djangoapps/projects/tests/test_projects.py
View file @
29b83b3d
...
@@ -11,10 +11,12 @@ from django.contrib.auth.models import User
...
@@ -11,10 +11,12 @@ from django.contrib.auth.models import User
from
django.core.cache
import
cache
from
django.core.cache
import
cache
from
django.test
import
TestCase
,
Client
from
django.test
import
TestCase
,
Client
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
from
django.utils.http
import
urlencode
from
projects.models
import
Project
,
Workgroup
from
projects.models
import
Project
,
Workgroup
from
projects.scope_resolver
import
GroupProjectParticipantsScopeResolver
from
projects.scope_resolver
import
GroupProjectParticipantsScopeResolver
TEST_API_KEY
=
str
(
uuid
.
uuid4
())
TEST_API_KEY
=
str
(
uuid
.
uuid4
())
...
@@ -43,6 +45,7 @@ class ProjectsApiTests(TestCase):
...
@@ -43,6 +45,7 @@ class ProjectsApiTests(TestCase):
self
.
test_course_id
=
'edx/demo/course'
self
.
test_course_id
=
'edx/demo/course'
self
.
test_bogus_course_id
=
'foo/bar/baz'
self
.
test_bogus_course_id
=
'foo/bar/baz'
self
.
test_course_content_id
=
"i4x://blah"
self
.
test_course_content_id
=
"i4x://blah"
self
.
test_course_content_id2
=
"i4x://blah2"
self
.
test_bogus_course_content_id
=
"14x://foo/bar/baz"
self
.
test_bogus_course_content_id
=
"14x://foo/bar/baz"
self
.
test_user
=
User
.
objects
.
create
(
self
.
test_user
=
User
.
objects
.
create
(
...
@@ -62,6 +65,11 @@ class ProjectsApiTests(TestCase):
...
@@ -62,6 +65,11 @@ class ProjectsApiTests(TestCase):
content_id
=
self
.
test_course_content_id
,
content_id
=
self
.
test_course_content_id
,
)
)
self
.
test_project2
=
Project
.
objects
.
create
(
course_id
=
self
.
test_course_id
,
content_id
=
self
.
test_course_content_id2
,
)
self
.
test_workgroup
=
Workgroup
.
objects
.
create
(
self
.
test_workgroup
=
Workgroup
.
objects
.
create
(
name
=
"Test Workgroup"
,
name
=
"Test Workgroup"
,
project
=
self
.
test_project
,
project
=
self
.
test_project
,
...
@@ -90,12 +98,14 @@ class ProjectsApiTests(TestCase):
...
@@ -90,12 +98,14 @@ class ProjectsApiTests(TestCase):
uri
,
headers
=
headers
,
content_type
=
'application/json'
,
data
=
json_data
)
uri
,
headers
=
headers
,
content_type
=
'application/json'
,
data
=
json_data
)
return
response
return
response
def
do_get
(
self
,
uri
):
def
do_get
(
self
,
uri
,
query_parameters
=
None
):
"""Submit an HTTP GET request"""
"""Submit an HTTP GET request"""
headers
=
{
headers
=
{
'Content-Type'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
'X-Edx-Api-Key'
:
str
(
TEST_API_KEY
),
'X-Edx-Api-Key'
:
str
(
TEST_API_KEY
),
}
}
if
query_parameters
:
uri
+=
"?"
+
urlencode
(
query_parameters
)
response
=
self
.
client
.
get
(
uri
,
headers
=
headers
)
response
=
self
.
client
.
get
(
uri
,
headers
=
headers
)
return
response
return
response
...
@@ -108,6 +118,52 @@ class ProjectsApiTests(TestCase):
...
@@ -108,6 +118,52 @@ class ProjectsApiTests(TestCase):
response
=
self
.
client
.
delete
(
uri
,
headers
=
headers
)
response
=
self
.
client
.
delete
(
uri
,
headers
=
headers
)
return
response
return
response
def
test_projects_list_get
(
self
):
""" Tests simple GET request - should return all projects """
response
=
self
.
do_get
(
self
.
test_projects_uri
)
projects
=
response
.
data
self
.
assertEqual
(
len
(
projects
),
2
)
project1
,
project2
=
projects
[
0
],
projects
[
1
]
self
.
assertEqual
(
project1
[
'id'
],
self
.
test_project
.
id
)
self
.
assertEqual
(
project1
[
'course_id'
],
self
.
test_project
.
course_id
)
self
.
assertEqual
(
project1
[
'content_id'
],
self
.
test_project
.
content_id
)
self
.
assertEqual
(
project2
[
'id'
],
self
.
test_project2
.
id
)
self
.
assertEqual
(
project2
[
'course_id'
],
self
.
test_project2
.
course_id
)
self
.
assertEqual
(
project2
[
'content_id'
],
self
.
test_project2
.
content_id
)
def
test_projects_list_get_filter_by_content_id
(
self
):
""" Tests GET request with specified content_id - should return single project with matching content_id """
filter1
=
{
'course_id'
:
self
.
test_project
.
course_id
,
'content_id'
:
self
.
test_project
.
content_id
}
response
=
self
.
do_get
(
self
.
test_projects_uri
,
filter1
)
self
.
assertEqual
(
len
(
response
.
data
),
1
)
self
.
assertEqual
(
response
.
data
[
0
][
'id'
],
self
.
test_project
.
id
)
self
.
assertEqual
(
response
.
data
[
0
][
'content_id'
],
self
.
test_project
.
content_id
)
self
.
assertEqual
(
response
.
data
[
0
][
'course_id'
],
self
.
test_project
.
course_id
)
filter2
=
{
'course_id'
:
self
.
test_project2
.
course_id
,
'content_id'
:
self
.
test_project2
.
content_id
}
response
=
self
.
do_get
(
self
.
test_projects_uri
,
filter2
)
self
.
assertEqual
(
len
(
response
.
data
),
1
)
self
.
assertEqual
(
response
.
data
[
0
][
'id'
],
self
.
test_project2
.
id
)
self
.
assertEqual
(
response
.
data
[
0
][
'content_id'
],
self
.
test_project2
.
content_id
)
self
.
assertEqual
(
response
.
data
[
0
][
'course_id'
],
self
.
test_project2
.
course_id
)
def
test_projects_list_incorrect_filter_request
(
self
):
""" Tests that GET requests with invalid filter returns BAD REQUEST response """
def
assert_request_failed
(
response
):
""" Assertion helper """
self
.
assertEqual
(
response
.
status_code
,
400
)
self
.
assertIn
(
"detail"
,
response
.
data
)
assert_request_failed
(
self
.
do_get
(
self
.
test_projects_uri
,
{
'course_id'
:
self
.
test_project
.
course_id
}))
assert_request_failed
(
self
.
do_get
(
self
.
test_projects_uri
,
{
'content_id'
:
self
.
test_project
.
content_id
}))
assert_request_failed
(
self
.
do_get
(
self
.
test_projects_uri
,
{
'content_id'
:
""
,
'course_id'
:
self
.
test_project
.
course_id
})
)
assert_request_failed
(
self
.
do_get
(
self
.
test_projects_uri
,
{
'content_id'
:
self
.
test_project
.
content_id
,
'course_id'
:
""
})
)
def
test_projects_list_post
(
self
):
def
test_projects_list_post
(
self
):
data
=
{
data
=
{
'name'
:
'Test Organization'
'name'
:
'Test Organization'
...
...
lms/djangoapps/projects/views.py
View file @
29b83b3d
...
@@ -317,9 +317,39 @@ class ProjectsViewSet(viewsets.ModelViewSet):
...
@@ -317,9 +317,39 @@ class ProjectsViewSet(viewsets.ModelViewSet):
"""
"""
Django Rest Framework ViewSet for the Project model.
Django Rest Framework ViewSet for the Project model.
"""
"""
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
"""
GET /api/projects/
Returns list of projects, optionally filtered by course ID and content ID (simultaneously)
"""
target_course_id
=
self
.
request
.
QUERY_PARAMS
.
get
(
'course_id'
)
target_content_id
=
self
.
request
.
QUERY_PARAMS
.
get
(
'content_id'
)
has_target_course
,
has_target_content
=
bool
(
target_course_id
),
bool
(
target_content_id
)
if
has_target_course
!=
has_target_content
:
message
=
"Both course_id and content_id should be present for filtering"
return
Response
({
"detail"
:
message
},
status
.
HTTP_400_BAD_REQUEST
)
return
super
(
ProjectsViewSet
,
self
)
.
list
(
request
,
*
args
,
**
kwargs
)
serializer_class
=
ProjectSerializer
serializer_class
=
ProjectSerializer
model
=
Project
model
=
Project
def
get_queryset
(
self
):
"""
Returns queryset optionally filtered by course_id and content_id
"""
target_course_id
=
self
.
request
.
QUERY_PARAMS
.
get
(
'course_id'
)
target_content_id
=
self
.
request
.
QUERY_PARAMS
.
get
(
'content_id'
)
queryset
=
self
.
model
.
objects
.
all
()
if
target_content_id
:
queryset
=
queryset
.
filter
(
content_id
=
target_content_id
,
course_id
=
target_course_id
)
return
queryset
@action
(
methods
=
[
'get'
,
'post'
])
@action
(
methods
=
[
'get'
,
'post'
])
def
workgroups
(
self
,
request
,
pk
):
def
workgroups
(
self
,
request
,
pk
):
"""
"""
...
...
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