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
64a976ab
Commit
64a976ab
authored
Jun 25, 2014
by
Zia Fazal
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new api to get list of workgroups by group
parent
e9d2731d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
4 deletions
+84
-4
lms/djangoapps/api_manager/groups/tests.py
+54
-3
lms/djangoapps/api_manager/groups/urls.py
+1
-0
lms/djangoapps/api_manager/groups/views.py
+29
-1
No files found.
lms/djangoapps/api_manager/groups/tests.py
View file @
64a976ab
...
...
@@ -9,13 +9,13 @@ import uuid
import
json
from
django.core.cache
import
cache
from
django.test
import
TestCase
,
Client
from
django.test
import
Client
from
django.test.utils
import
override_settings
from
api_manager.models
import
GroupRelationship
,
GroupProfile
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
api_manager.models
import
GroupRelationship
,
GroupProfile
,
Organization
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
projects.models
import
Project
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
TEST_API_KEY
=
str
(
uuid
.
uuid4
())
...
...
@@ -43,8 +43,16 @@ class GroupsApiTests(ModuleStoreTestCase):
self
.
base_users_uri
=
'/api/users'
self
.
base_groups_uri
=
'/api/groups'
self
.
test_course_data
=
'<html>{}</html>'
.
format
(
str
(
uuid
.
uuid4
()))
self
.
course
=
CourseFactory
.
create
()
self
.
test_course_id
=
self
.
course
.
id
self
.
course_content
=
ItemFactory
.
create
(
category
=
"videosequence"
,
parent_location
=
self
.
course
.
location
,
data
=
self
.
test_course_data
,
due
=
"2016-05-16T14:30:00Z"
,
display_name
=
"View_Sequence"
)
self
.
test_organization
=
Organization
.
objects
.
create
(
name
=
"Test Organization"
,
...
...
@@ -54,6 +62,11 @@ class GroupsApiTests(ModuleStoreTestCase):
contact_phone
=
'+1 332 232 24234'
)
self
.
test_project
=
Project
.
objects
.
create
(
course_id
=
self
.
course
.
id
,
content_id
=
self
.
course_content
.
id
)
self
.
client
=
SecureClient
()
cache
.
clear
()
...
...
@@ -939,3 +952,41 @@ class GroupsApiTests(ModuleStoreTestCase):
test_uri
=
self
.
base_groups_uri
+
'/1231241/organizations/'
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_groups_workgroups_list
(
self
):
data
=
{
'name'
:
self
.
test_group_name
,
'type'
:
'test'
}
response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
group_id
=
response
.
data
[
'id'
]
test_workgroups_uri
=
'/api/workgroups/'
for
i
in
xrange
(
1
,
12
):
project_id
=
self
.
test_project
.
id
data
=
{
'name'
:
'Workgroup '
+
str
(
i
),
'project'
:
project_id
}
response
=
self
.
do_post
(
test_workgroups_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
test_uri
=
'{}{}/'
.
format
(
test_workgroups_uri
,
str
(
response
.
data
[
'id'
]))
users_uri
=
'{}groups/'
.
format
(
test_uri
)
data
=
{
"id"
:
group_id
}
response
=
self
.
do_post
(
users_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
# test to get list of workgroups
test_uri
=
'/api/groups/{}/workgroups/?page_size=10'
.
format
(
group_id
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
data
[
'count'
],
11
)
self
.
assertEqual
(
len
(
response
.
data
[
'results'
]),
10
)
self
.
assertEqual
(
response
.
data
[
'num_pages'
],
2
)
# test with course_id filter
response
=
self
.
do_get
(
'/api/groups/{}/workgroups/?course_id={}'
.
format
(
group_id
,
self
.
course
.
id
))
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
[
'count'
],
11
)
self
.
assertIsNotNone
(
response
.
data
[
'results'
][
0
][
'name'
])
self
.
assertIsNotNone
(
response
.
data
[
'results'
][
0
][
'project'
])
# test with invalid group id
response
=
self
.
do_get
(
'/api/groups/4356340/workgroups/'
)
self
.
assertEqual
(
response
.
status_code
,
404
)
lms/djangoapps/api_manager/groups/urls.py
View file @
64a976ab
...
...
@@ -12,6 +12,7 @@ urlpatterns = patterns(
url
(
r'^(?P<group_id>[0-9]+)/courses/*$'
,
groups_views
.
GroupsCoursesList
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/courses/(?P<course_id>[a-zA-Z0-9/_:]+)$'
,
groups_views
.
GroupsCoursesDetail
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/organizations/*$'
,
groups_views
.
GroupsOrganizationsList
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/workgroups/*$'
,
groups_views
.
GroupsWorkgroupsList
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/users/*$'
,
groups_views
.
GroupsUsersList
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/users/(?P<user_id>[0-9]+)$'
,
groups_views
.
GroupsUsersDetail
.
as_view
()),
url
(
r'^(?P<group_id>[0-9]+)/groups/*$'
,
groups_views
.
GroupsGroupsList
.
as_view
()),
...
...
lms/djangoapps/api_manager/groups/views.py
View file @
64a976ab
...
...
@@ -5,15 +5,17 @@ from collections import OrderedDict
from
django.contrib.auth.models
import
Group
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.http
import
Http404
from
django.utils
import
timezone
from
rest_framework
import
status
from
rest_framework.response
import
Response
from
api_manager.models
import
GroupRelationship
,
CourseGroupRelationship
,
GroupProfile
,
APIUser
as
User
from
api_manager.permissions
import
SecureAPIView
from
api_manager.permissions
import
SecureAPIView
,
SecureListAPIView
from
api_manager.utils
import
str2bool
,
generate_base_uri
from
api_manager.organizations
import
serializers
from
projects.serializers
import
BasicWorkgroupSerializer
from
xmodule.modulestore
import
Location
,
InvalidLocationError
from
xmodule.modulestore.django
import
modulestore
...
...
@@ -642,3 +644,29 @@ class GroupsOrganizationsList(SecureAPIView):
serializer
=
serializers
.
OrganizationSerializer
(
org
)
response_data
.
append
(
serializer
.
data
)
return
Response
(
response_data
,
status
=
status
.
HTTP_200_OK
)
class
GroupsWorkgroupsList
(
SecureListAPIView
):
"""
### The GroupsWorkgroupsList view allows clients to retrieve a list of workgroups a group has
- URI: ```/api/groups/{group_id}/workgroups/```
- GET: Provides paginated list of workgroups for a group
To filter the group's workgroup set by course
GET ```/api/groups/{group_id}/workgroups/?course_id={course_id}```
"""
serializer_class
=
BasicWorkgroupSerializer
def
get_queryset
(
self
):
group_id
=
self
.
kwargs
[
'group_id'
]
course_id
=
self
.
request
.
QUERY_PARAMS
.
get
(
'course_id'
,
None
)
try
:
group
=
Group
.
objects
.
get
(
id
=
group_id
)
except
ObjectDoesNotExist
:
raise
Http404
queryset
=
group
.
workgroups
.
all
()
if
course_id
:
queryset
=
queryset
.
filter
(
project__course_id
=
course_id
)
return
queryset
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