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
6994d2d5
Commit
6994d2d5
authored
Jun 18, 2014
by
Zia Fazal
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added organisation to users api
added id, name and created fields Added display_name to basic serializer
parent
0d463688
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
3 deletions
+35
-3
lms/djangoapps/api_manager/organizations/serializers.py
+11
-0
lms/djangoapps/api_manager/users/serializers.py
+4
-1
lms/djangoapps/api_manager/users/tests.py
+20
-2
No files found.
lms/djangoapps/api_manager/organizations/serializers.py
View file @
6994d2d5
...
...
@@ -25,3 +25,14 @@ class OrganizationSerializer(serializers.ModelSerializer):
fields
=
(
'url'
,
'id'
,
'name'
,
'display_name'
,
'contact_name'
,
'contact_email'
,
'contact_phone'
,
'workgroups'
,
'users'
,
'groups'
,
'created'
,
'modified'
)
read_only
=
(
'url'
,
'id'
,
'created'
)
class
BasicOrganizationSerializer
(
serializers
.
ModelSerializer
):
""" Serializer for Basic Organization fields """
url
=
serializers
.
HyperlinkedIdentityField
(
view_name
=
'organization-detail'
)
class
Meta
:
""" Serializer/field specification """
model
=
Organization
fields
=
(
'url'
,
'id'
,
'name'
,
'created'
,
'display_name'
)
read_only
=
(
'url'
,
'id'
,
'created'
,)
lms/djangoapps/api_manager/users/serializers.py
View file @
6994d2d5
...
...
@@ -2,12 +2,15 @@
from
api_manager.models
import
APIUser
from
rest_framework
import
serializers
from
api_manager.organizations.serializers
import
BasicOrganizationSerializer
class
UserSerializer
(
serializers
.
ModelSerializer
):
""" Serializer for User model interactions """
organizations
=
BasicOrganizationSerializer
(
many
=
True
,
required
=
False
)
class
Meta
:
""" Serializer/field specification """
model
=
APIUser
fields
=
(
"id"
,
"email"
,
"username"
,
"first_name"
,
"last_name"
)
fields
=
(
"id"
,
"email"
,
"username"
,
"first_name"
,
"last_name"
,
"organizations"
)
read_only_fields
=
(
"id"
,
"email"
,
"username"
)
lms/djangoapps/api_manager/users/tests.py
View file @
6994d2d5
...
...
@@ -50,6 +50,7 @@ class UsersApiTests(TestCase):
self
.
test_first_name
=
str
(
uuid
.
uuid4
())
self
.
test_last_name
=
str
(
uuid
.
uuid4
())
self
.
test_city
=
str
(
uuid
.
uuid4
())
self
.
org_base_uri
=
'/api/organizations/'
self
.
test_course_data
=
'<html>{}</html>'
.
format
(
str
(
uuid
.
uuid4
()))
self
.
course
=
CourseFactory
.
create
()
...
...
@@ -115,7 +116,7 @@ class UsersApiTests(TestCase):
def
test_user_list_get
(
self
):
test_uri
=
'/api/users'
users
=
[]
# create a 25 new users
for
i
in
xrange
(
1
,
26
):
data
=
{
...
...
@@ -128,6 +129,19 @@ class UsersApiTests(TestCase):
response
=
self
.
do_post
(
test_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
users
.
append
(
response
.
data
[
'id'
])
# create organizations and add users to them
total_orgs
=
30
for
i
in
xrange
(
0
,
total_orgs
):
data
=
{
'name'
:
'{} {}'
.
format
(
'Org'
,
i
),
'display_name'
:
'{} {}'
.
format
(
'Org display name'
,
i
),
'users'
:
users
}
response
=
self
.
do_post
(
self
.
org_base_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
# fetch data without any filters applied
response
=
self
.
do_get
(
'{}?page=1'
.
format
(
test_uri
))
self
.
assertEqual
(
response
.
status_code
,
400
)
...
...
@@ -138,6 +152,10 @@ class UsersApiTests(TestCase):
response
=
self
.
do_get
(
'{}?ids={}'
.
format
(
test_uri
,
'3'
))
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
response
.
data
[
'results'
]),
1
)
self
.
assertEqual
(
len
(
response
.
data
[
'results'
][
0
][
'organizations'
]),
total_orgs
)
self
.
assertIsNotNone
(
response
.
data
[
'results'
][
0
][
'organizations'
][
0
][
'name'
])
self
.
assertIsNotNone
(
response
.
data
[
'results'
][
0
][
'organizations'
][
0
][
'id'
])
self
.
assertIsNotNone
(
response
.
data
[
'results'
][
0
][
'organizations'
][
0
][
'url'
])
# fetch user data by multiple ids
response
=
self
.
do_get
(
'{}?page_size=5&ids={}'
.
format
(
test_uri
,
'2,3,7,11,6,21,34'
))
self
.
assertEqual
(
response
.
status_code
,
200
)
...
...
@@ -961,7 +979,7 @@ class UsersApiTests(TestCase):
'display_name'
:
'Org display name'
+
str
(
i
),
'users'
:
[
user_id
]
}
response
=
self
.
do_post
(
'/api/organizations/'
,
data
)
response
=
self
.
do_post
(
self
.
org_base_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
test_uri
=
'/api/users/{}/organizations/'
.
format
(
user_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