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
05650856
Commit
05650856
authored
Dec 22, 2016
by
tasawernawaz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implementing Institution/Course admin widget ECOM-6090
parent
bbdeaa37
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
8 deletions
+92
-8
course_discovery/apps/publisher/api/serializers.py
+9
-0
course_discovery/apps/publisher/api/tests/test_serializers.py
+12
-1
course_discovery/apps/publisher/api/tests/test_views.py
+53
-0
course_discovery/apps/publisher/api/urls.py
+4
-4
course_discovery/apps/publisher/api/views.py
+14
-3
No files found.
course_discovery/apps/publisher/api/serializers.py
View file @
05650856
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
course_discovery.apps.core.models
import
User
from
course_discovery.apps.publisher.models
import
CourseUserRole
from
course_discovery.apps.publisher.models
import
CourseUserRole
...
@@ -21,3 +22,11 @@ class CourseUserRoleSerializer(serializers.ModelSerializer):
...
@@ -21,3 +22,11 @@ class CourseUserRoleSerializer(serializers.ModelSerializer):
validated_values
.
update
({
'changed_by'
:
request
.
user
})
validated_values
.
update
({
'changed_by'
:
request
.
user
})
return
validated_values
return
validated_values
class
GroupUserSerializer
(
serializers
.
ModelSerializer
):
"""Serializer for the `User` model used in OrganizationGroupUserView. """
class
Meta
:
model
=
User
fields
=
(
'id'
,
'full_name'
,
)
course_discovery/apps/publisher/api/tests/test_serializers.py
View file @
05650856
...
@@ -3,7 +3,8 @@ from unittest import TestCase
...
@@ -3,7 +3,8 @@ from unittest import TestCase
from
django.test
import
RequestFactory
from
django.test
import
RequestFactory
from
course_discovery.apps.publisher.api.serializers
import
CourseUserRoleSerializer
from
course_discovery.apps.core.tests.factories
import
UserFactory
from
course_discovery.apps.publisher.api.serializers
import
CourseUserRoleSerializer
,
GroupUserSerializer
from
course_discovery.apps.publisher.tests.factories
import
CourseUserRoleFactory
from
course_discovery.apps.publisher.tests.factories
import
CourseUserRoleFactory
...
@@ -28,3 +29,13 @@ class CourseUserRoleSerializerTests(TestCase):
...
@@ -28,3 +29,13 @@ class CourseUserRoleSerializerTests(TestCase):
serializer
=
self
.
serializer_class
(
self
.
course_user_role
,
context
=
{
'request'
:
self
.
request
})
serializer
=
self
.
serializer_class
(
self
.
course_user_role
,
context
=
{
'request'
:
self
.
request
})
validated_data
=
serializer
.
validate
(
serializer
.
data
)
validated_data
=
serializer
.
validate
(
serializer
.
data
)
self
.
assertEqual
(
validated_data
,
self
.
get_expected_data
())
self
.
assertEqual
(
validated_data
,
self
.
get_expected_data
())
class
GroupUserSerializerTests
(
TestCase
):
def
test_date
(
self
):
""" Verify that UserSerializer serialize the user object. """
user
=
UserFactory
(
full_name
=
"test user"
)
serializer
=
GroupUserSerializer
(
user
)
self
.
assertDictEqual
(
serializer
.
data
,
{
'id'
:
user
.
id
,
'full_name'
:
user
.
full_name
})
course_discovery/apps/publisher/api/tests/test_views.py
View file @
05650856
...
@@ -93,3 +93,56 @@ class CourseRoleAssignmentViewTests(TestCase):
...
@@ -93,3 +93,56 @@ class CourseRoleAssignmentViewTests(TestCase):
}
}
self
.
assertDictEqual
(
response
.
data
,
expected
)
self
.
assertDictEqual
(
response
.
data
,
expected
)
self
.
assertEqual
(
self
.
internal_user
,
self
.
course
.
course_user_roles
.
get
(
role
=
user_course_role
.
role
)
.
user
)
self
.
assertEqual
(
self
.
internal_user
,
self
.
course
.
course_user_roles
.
get
(
role
=
user_course_role
.
role
)
.
user
)
class
OrganizationGroupUserViewTests
(
TestCase
):
def
setUp
(
self
):
super
(
OrganizationGroupUserViewTests
,
self
)
.
setUp
()
user
=
UserFactory
.
create
(
username
=
"test_user"
,
password
=
USER_PASSWORD
)
self
.
client
.
login
(
username
=
user
.
username
,
password
=
USER_PASSWORD
)
# create group and add test users in the group
group
=
factories
.
GroupFactory
()
self
.
org_user1
=
UserFactory
.
create
(
full_name
=
"org user1"
)
self
.
org_user2
=
UserFactory
.
create
(
full_name
=
"org user2"
)
group
.
user_set
.
add
(
self
.
org_user1
)
group
.
user_set
.
add
(
self
.
org_user2
)
self
.
organization
=
OrganizationFactory
()
factories
.
OrganizationExtensionFactory
.
create
(
organization
=
self
.
organization
,
group
=
group
)
def
test_get_organization_user_group
(
self
):
""" Verify that view returns list of users associated with the group
related to given organization id.
"""
response
=
self
.
client
.
get
(
path
=
self
.
_get_organization_group_user_url
(
self
.
organization
.
id
),
content_type
=
JSON_CONTENT_TYPE
)
self
.
assertEqual
(
response
.
status_code
,
200
)
expected_results
=
[
{
"id"
:
self
.
org_user1
.
id
,
"full_name"
:
self
.
org_user1
.
full_name
},
{
"id"
:
self
.
org_user2
.
id
,
"full_name"
:
self
.
org_user2
.
full_name
}
]
self
.
assertEqual
(
json
.
loads
(
response
.
content
.
decode
(
"utf-8"
))[
"results"
],
expected_results
)
def
test_get_organization_not_found
(
self
):
""" Verify that view returns status=404 if organization is not found
in OrganizationExtension.
"""
response
=
self
.
client
.
get
(
path
=
self
.
_get_organization_group_user_url
(
org_id
=
0000
),
content_type
=
JSON_CONTENT_TYPE
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
_get_organization_group_user_url
(
self
,
org_id
):
return
reverse
(
'publisher:api:organization_group_users'
,
kwargs
=
{
'pk'
:
org_id
}
)
course_discovery/apps/publisher/api/urls.py
View file @
05650856
""" Publisher API URLs. """
""" Publisher API URLs. """
from
django.conf.urls
import
url
from
django.conf.urls
import
url
from
course_discovery.apps.publisher.api.views
import
CourseRoleAssignmentView
from
course_discovery.apps.publisher.api.views
import
CourseRoleAssignmentView
,
OrganizationGroupUserView
urlpatterns
=
[
urlpatterns
=
[
url
(
url
(
r'^course_role_assignments/(?P<pk>\d+)/$'
,
CourseRoleAssignmentView
.
as_view
(),
name
=
'course_role_assignments'
),
r'^course_role_assignments/(?P<pk>\d+)/$'
,
CourseRoleAssignmentView
.
as_view
(),
name
=
'course_role_assignments'
url
(
r'^admins/organizations/(?P<pk>\d+)/users/$'
,
OrganizationGroupUserView
.
as_view
(),
),
name
=
'organization_group_users'
),
]
]
course_discovery/apps/publisher/api/views.py
View file @
05650856
from
rest_framework.generics
import
UpdateAPIView
from
rest_framework.generics
import
UpdateAPIView
,
ListAPIView
,
get_object_or_404
from
rest_framework.permissions
import
IsAuthenticated
from
rest_framework.permissions
import
IsAuthenticated
from
course_discovery.apps.publisher.models
import
CourseUserRole
from
course_discovery.apps.core.models
import
User
from
course_discovery.apps.publisher.models
import
CourseUserRole
,
OrganizationExtension
from
course_discovery.apps.publisher.api.permissions
import
CanViewAssociatedCourse
,
InternalUserPermission
from
course_discovery.apps.publisher.api.permissions
import
CanViewAssociatedCourse
,
InternalUserPermission
from
course_discovery.apps.publisher.api.serializers
import
CourseUserRoleSerializer
from
course_discovery.apps.publisher.api.serializers
import
CourseUserRoleSerializer
,
GroupUserSerializer
class
CourseRoleAssignmentView
(
UpdateAPIView
):
class
CourseRoleAssignmentView
(
UpdateAPIView
):
permission_classes
=
(
IsAuthenticated
,
CanViewAssociatedCourse
,
InternalUserPermission
,)
permission_classes
=
(
IsAuthenticated
,
CanViewAssociatedCourse
,
InternalUserPermission
,)
queryset
=
CourseUserRole
.
objects
.
all
()
queryset
=
CourseUserRole
.
objects
.
all
()
serializer_class
=
CourseUserRoleSerializer
serializer_class
=
CourseUserRoleSerializer
class
OrganizationGroupUserView
(
ListAPIView
):
serializer_class
=
GroupUserSerializer
permission_classes
=
(
IsAuthenticated
,)
def
get_queryset
(
self
):
org_extension
=
get_object_or_404
(
OrganizationExtension
,
organization
=
self
.
kwargs
.
get
(
'pk'
))
queryset
=
User
.
objects
.
filter
(
groups__name
=
org_extension
.
group
)
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