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
9d0f82dd
Commit
9d0f82dd
authored
May 09, 2014
by
chrisndodge
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #43 from edx-solutions/apply_group_type_fiter_1013
Apply group type fiter 1013
parents
00060b1f
7bb3d0ea
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
4 deletions
+118
-4
lms/djangoapps/api_manager/courses/tests.py
+44
-0
lms/djangoapps/api_manager/courses/views.py
+22
-2
lms/djangoapps/api_manager/groups/views.py
+1
-1
lms/djangoapps/api_manager/users/tests.py
+47
-0
lms/djangoapps/api_manager/users/views.py
+4
-1
No files found.
lms/djangoapps/api_manager/courses/tests.py
View file @
9d0f82dd
...
@@ -315,6 +315,50 @@ class CoursesApiTests(TestCase):
...
@@ -315,6 +315,50 @@ class CoursesApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'course_id'
],
str
(
self
.
test_course_id
))
self
.
assertEqual
(
response
.
data
[
'course_id'
],
str
(
self
.
test_course_id
))
self
.
assertEqual
(
response
.
data
[
'group_id'
],
str
(
group_id
))
self
.
assertEqual
(
response
.
data
[
'group_id'
],
str
(
group_id
))
def
test_courses_groups_list_get
(
self
):
test_uri
=
'{}/{}/groups'
.
format
(
self
.
base_courses_uri
,
self
.
test_course_id
)
course_fail_uri
=
'{}/{}/groups'
.
format
(
self
.
base_courses_uri
,
'/ed/Open_DemoX/edx_demo_course'
)
for
i
in
xrange
(
2
):
data_dict
=
{
'name'
:
'Alpha Group {}'
.
format
(
i
),
'group_type'
:
'Programming'
,
}
response
=
self
.
do_post
(
self
.
base_groups_uri
,
data_dict
)
group_id
=
response
.
data
[
'id'
]
data
=
{
'group_id'
:
group_id
}
self
.
assertEqual
(
response
.
status_code
,
201
)
response
=
self
.
do_post
(
test_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
data_dict
[
'group_type'
]
=
'Calculus'
response
=
self
.
do_post
(
self
.
base_groups_uri
,
data_dict
)
group_id
=
response
.
data
[
'id'
]
data
=
{
'group_id'
:
group_id
}
self
.
assertEqual
(
response
.
status_code
,
201
)
response
=
self
.
do_post
(
test_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
response
.
data
[
'groups'
]),
3
)
courses_groups_uri
=
'{}?type={}'
.
format
(
test_uri
,
'Programming'
)
response
=
self
.
do_get
(
courses_groups_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
response
.
data
[
'groups'
]),
2
)
group_type_uri
=
'{}?type={}'
.
format
(
test_uri
,
'Calculus'
)
response
=
self
.
do_get
(
group_type_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
response
.
data
[
'groups'
]),
1
)
error_group_type_uri
=
'{}?type={}'
.
format
(
test_uri
,
'error_type'
)
response
=
self
.
do_get
(
error_group_type_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
response
.
data
[
'groups'
]),
0
)
response
=
self
.
do_get
(
course_fail_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_courses_groups_list_post_duplicate
(
self
):
def
test_courses_groups_list_post_duplicate
(
self
):
data
=
{
'name'
:
self
.
test_group_name
}
data
=
{
'name'
:
self
.
test_group_name
}
response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
...
lms/djangoapps/api_manager/courses/views.py
View file @
9d0f82dd
...
@@ -10,12 +10,11 @@ from django.core.exceptions import ObjectDoesNotExist
...
@@ -10,12 +10,11 @@ from django.core.exceptions import ObjectDoesNotExist
from
django.http
import
Http404
from
django.http
import
Http404
from
rest_framework
import
status
from
rest_framework
import
status
from
rest_framework.decorators
import
api_view
,
permission_classes
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
api_manager.permissions
import
ApiKeyHeaderPermission
from
api_manager.permissions
import
ApiKeyHeaderPermission
from
api_manager.models
import
CourseGroupRelationship
from
api_manager.models
import
CourseGroupRelationship
,
GroupProfile
from
courseware
import
module_render
from
courseware
import
module_render
from
courseware.courses
import
get_course
,
get_course_about_section
,
get_course_info_section
from
courseware.courses
import
get_course
,
get_course_about_section
,
get_course_info_section
from
courseware.model_data
import
FieldDataCache
from
courseware.model_data
import
FieldDataCache
...
@@ -399,6 +398,27 @@ class CoursesGroupsList(APIView):
...
@@ -399,6 +398,27 @@ class CoursesGroupsList(APIView):
response_status
=
status
.
HTTP_404_NOT_FOUND
response_status
=
status
.
HTTP_404_NOT_FOUND
return
Response
(
response_data
,
status
=
response_status
)
return
Response
(
response_data
,
status
=
response_status
)
def
get
(
self
,
request
,
course_id
):
"""
GET retrieves the list of groups related to the specified course
"""
try
:
get_course
(
course_id
)
except
ValueError
:
return
Response
({},
status
=
status
.
HTTP_404_NOT_FOUND
)
group_type
=
request
.
QUERY_PARAMS
.
get
(
'type'
,
None
)
course_groups
=
CourseGroupRelationship
.
objects
.
filter
(
course_id
=
course_id
)
if
group_type
:
course_groups
=
course_groups
.
filter
(
group__groupprofile__group_type
=
group_type
)
response_data
=
{
'groups'
:
[]}
for
course_group
in
course_groups
:
group_profile
=
GroupProfile
.
objects
.
get
(
group_id
=
course_group
.
group_id
)
group_data
=
{
'id'
:
course_group
.
group_id
,
'name'
:
group_profile
.
name
}
response_data
[
'groups'
]
.
append
(
group_data
)
response_status
=
status
.
HTTP_200_OK
return
Response
(
response_data
,
status
=
response_status
)
class
CoursesGroupsDetail
(
APIView
):
class
CoursesGroupsDetail
(
APIView
):
permission_classes
=
(
ApiKeyHeaderPermission
,)
permission_classes
=
(
ApiKeyHeaderPermission
,)
...
...
lms/djangoapps/api_manager/groups/views.py
View file @
9d0f82dd
...
@@ -304,7 +304,7 @@ class GroupsGroupsList(APIView):
...
@@ -304,7 +304,7 @@ class GroupsGroupsList(APIView):
child_groups
=
GroupRelationship
.
objects
.
filter
(
parent_group_id
=
group_id
)
child_groups
=
GroupRelationship
.
objects
.
filter
(
parent_group_id
=
group_id
)
linked_groups
=
from_group_relationship
.
get_linked_group_relationships
()
linked_groups
=
from_group_relationship
.
get_linked_group_relationships
()
if
group_type
:
if
group_type
:
profiles
=
GroupProfile
.
objects
.
filter
(
group_type
=
request
.
GET
[
'type'
]
)
.
values_list
(
'group_id'
,
flat
=
True
)
profiles
=
GroupProfile
.
objects
.
filter
(
group_type
=
group_type
)
.
values_list
(
'group_id'
,
flat
=
True
)
if
profiles
:
if
profiles
:
child_groups
=
child_groups
.
filter
(
group_id__in
=
profiles
)
child_groups
=
child_groups
.
filter
(
group_id__in
=
profiles
)
linked_groups
=
linked_groups
.
filter
(
to_group_relationship__in
=
profiles
)
linked_groups
=
linked_groups
.
filter
(
to_group_relationship__in
=
profiles
)
...
...
lms/djangoapps/api_manager/users/tests.py
View file @
9d0f82dd
...
@@ -313,6 +313,53 @@ class UsersApiTests(TestCase):
...
@@ -313,6 +313,53 @@ class UsersApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'groups'
][
0
][
'id'
],
group_id
)
self
.
assertEqual
(
response
.
data
[
'groups'
][
0
][
'id'
],
group_id
)
self
.
assertEqual
(
response
.
data
[
'groups'
][
0
][
'name'
],
str
(
group_name
))
self
.
assertEqual
(
response
.
data
[
'groups'
][
0
][
'name'
],
str
(
group_name
))
def
test_user_groups_list_get_with_query_params
(
self
):
test_uri
=
'/api/users'
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
,
'first_name'
:
self
.
test_first_name
,
'last_name'
:
self
.
test_last_name
}
response
=
self
.
do_post
(
test_uri
,
data
)
user_id
=
response
.
data
[
'id'
]
test_uri
=
'{}/{}'
.
format
(
test_uri
,
str
(
user_id
))
fail_user_id_group_uri
=
'{}/{}/groups'
.
format
(
test_uri
,
'22'
)
group_url
=
'/api/groups'
group_name
=
'Alpha Group'
data
=
{
'name'
:
group_name
,
'group_type'
:
'Engineer'
}
response
=
self
.
do_post
(
group_url
,
data
)
group_id
=
response
.
data
[
'id'
]
user_groups_uri
=
'{}/groups'
.
format
(
test_uri
)
data
=
{
'group_id'
:
group_id
}
response
=
self
.
do_post
(
user_groups_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
group_name
=
'Beta Group'
data
=
{
'name'
:
group_name
,
'group_type'
:
'Architect'
}
response
=
self
.
do_post
(
group_url
,
data
)
group_id
=
response
.
data
[
'id'
]
data
=
{
'group_id'
:
group_id
}
response
=
self
.
do_post
(
user_groups_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
response
=
self
.
do_get
(
fail_user_id_group_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
response
=
self
.
do_get
(
user_groups_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
response
.
data
[
'groups'
]),
2
)
group_type_uri
=
'{}?type={}'
.
format
(
user_groups_uri
,
'Engineer'
)
response
=
self
.
do_get
(
group_type_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
response
.
data
[
'groups'
]),
1
)
error_type_uri
=
'{}?type={}'
.
format
(
user_groups_uri
,
'error_type'
)
response
=
self
.
do_get
(
error_type_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
response
.
data
[
'groups'
]),
0
)
def
test_user_groups_list_get_invalid_user
(
self
):
def
test_user_groups_list_get_invalid_user
(
self
):
test_uri
=
'/api/users/123124/groups'
test_uri
=
'/api/users/123124/groups'
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
...
...
lms/djangoapps/api_manager/users/views.py
View file @
9d0f82dd
...
@@ -408,11 +408,14 @@ class UsersGroupsList(APIView):
...
@@ -408,11 +408,14 @@ class UsersGroupsList(APIView):
try
:
try
:
existing_user
=
User
.
objects
.
get
(
id
=
user_id
)
existing_user
=
User
.
objects
.
get
(
id
=
user_id
)
except
ObjectDoesNotExist
:
except
ObjectDoesNotExist
:
return
Response
({},
status
.
HTTP_404_NOT_FOUND
)
return
Response
({},
status
=
status
.
HTTP_404_NOT_FOUND
)
group_type
=
request
.
QUERY_PARAMS
.
get
(
'type'
,
None
)
response_data
=
{}
response_data
=
{}
base_uri
=
_generate_base_uri
(
request
)
base_uri
=
_generate_base_uri
(
request
)
response_data
[
'uri'
]
=
base_uri
response_data
[
'uri'
]
=
base_uri
groups
=
existing_user
.
groups
.
all
()
groups
=
existing_user
.
groups
.
all
()
if
group_type
:
groups
=
groups
.
filter
(
groupprofile__group_type
=
group_type
)
response_data
[
'groups'
]
=
[]
response_data
[
'groups'
]
=
[]
for
group
in
groups
:
for
group
in
groups
:
group_profile
=
GroupProfile
.
objects
.
get
(
group_id
=
group
.
id
)
group_profile
=
GroupProfile
.
objects
.
get
(
group_id
=
group
.
id
)
...
...
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