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
232af6ed
Commit
232af6ed
authored
Jul 22, 2014
by
Zia Fazal
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added course_count
parent
bf5bf27b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
9 deletions
+47
-9
lms/djangoapps/api_manager/organizations/tests.py
+32
-2
lms/djangoapps/api_manager/organizations/views.py
+8
-1
lms/djangoapps/api_manager/users/tests.py
+3
-5
lms/djangoapps/api_manager/utils.py
+4
-1
No files found.
lms/djangoapps/api_manager/organizations/tests.py
View file @
232af6ed
...
...
@@ -9,9 +9,12 @@ import uuid
from
django.contrib.auth.models
import
User
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
student.tests.factories
import
CourseEnrollmentFactory
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
TEST_API_KEY
=
str
(
uuid
.
uuid4
())
...
...
@@ -26,7 +29,7 @@ class SecureClient(Client):
@override_settings
(
EDX_API_KEY
=
TEST_API_KEY
)
class
OrganizationsApiTests
(
TestCase
):
class
OrganizationsApiTests
(
ModuleStore
TestCase
):
""" Test suite for Users API views """
...
...
@@ -47,6 +50,10 @@ class OrganizationsApiTests(TestCase):
email
=
self
.
test_user_email
,
username
=
self
.
test_user_username
)
self
.
course
=
CourseFactory
.
create
()
self
.
second_course
=
CourseFactory
.
create
(
number
=
"899"
)
self
.
client
=
SecureClient
()
cache
.
clear
()
...
...
@@ -252,3 +259,26 @@ class OrganizationsApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
0
][
'id'
],
self
.
test_user
.
id
)
self
.
assertEqual
(
response
.
data
[
0
][
'username'
],
self
.
test_user
.
username
)
self
.
assertEqual
(
response
.
data
[
0
][
'email'
],
self
.
test_user
.
email
)
def
test_organizations_users_get_with_course_count
(
self
):
CourseEnrollmentFactory
.
create
(
user
=
self
.
test_user
,
course_id
=
self
.
course
.
id
)
CourseEnrollmentFactory
.
create
(
user
=
self
.
test_user
,
course_id
=
self
.
second_course
.
id
)
data
=
{
'name'
:
self
.
test_organization_name
,
'display_name'
:
self
.
test_organization_display_name
,
'contact_name'
:
self
.
test_organization_contact_name
,
'contact_email'
:
self
.
test_organization_contact_email
,
'contact_phone'
:
self
.
test_organization_contact_phone
}
response
=
self
.
do_post
(
self
.
test_organizations_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
test_uri
=
'{}{}/'
.
format
(
self
.
test_organizations_uri
,
str
(
response
.
data
[
'id'
]))
users_uri
=
'{}users/'
.
format
(
test_uri
)
data
=
{
"id"
:
self
.
test_user
.
id
}
response
=
self
.
do_post
(
users_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
201
)
response
=
self
.
do_get
(
'{}{}'
.
format
(
users_uri
,
'?include_course_counts=True'
))
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
[
0
][
'id'
],
self
.
test_user
.
id
)
self
.
assertEqual
(
response
.
data
[
0
][
'course_count'
],
2
)
lms/djangoapps/api_manager/organizations/views.py
View file @
232af6ed
...
...
@@ -9,6 +9,8 @@ from rest_framework.decorators import action
from
rest_framework.response
import
Response
from
api_manager.models
import
Organization
from
api_manager.utils
import
str2bool
from
student.models
import
CourseEnrollment
from
.serializers
import
OrganizationSerializer
,
UserSerializer
...
...
@@ -26,12 +28,17 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
Add a User to an Organization
"""
if
request
.
method
==
'GET'
:
include_course_counts
=
request
.
QUERY_PARAMS
.
get
(
'include_course_counts'
,
None
)
users
=
User
.
objects
.
filter
(
organizations
=
pk
)
response_data
=
[]
if
users
:
for
user
in
users
:
serializer
=
UserSerializer
(
user
)
response_data
.
append
(
serializer
.
data
)
# pylint: disable=E1101
user_data
=
serializer
.
data
if
str2bool
(
include_course_counts
):
enrollments
=
CourseEnrollment
.
enrollments_for_user
(
user
)
.
count
()
user_data
[
'course_count'
]
=
enrollments
response_data
.
append
(
user_data
)
return
Response
(
response_data
,
status
=
status
.
HTTP_200_OK
)
else
:
user_id
=
request
.
DATA
.
get
(
'id'
)
...
...
lms/djangoapps/api_manager/users/tests.py
View file @
232af6ed
...
...
@@ -14,17 +14,16 @@ from mock import patch
from
django.utils.translation
import
ugettext
as
_
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
capa.tests.response_xml_factory
import
StringResponseXMLFactory
from
courseware.tests.factories
import
StudentModuleFactory
from
courseware.tests.modulestore_config
import
TEST_DATA_MIXED_MODULESTORE
from
projects.models
import
Project
from
student.tests.factories
import
UserFactory
from
student.models
import
anonymous_id_for_user
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
from
xmodule.modulestore
import
Location
TEST_API_KEY
=
str
(
uuid
.
uuid4
())
...
...
@@ -39,12 +38,11 @@ class SecureClient(Client):
super
(
SecureClient
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@override_settings
(
EDX_API_KEY
=
TEST_API_KEY
)
@override_settings
(
PASSWORD_MIN_LENGTH
=
4
)
@override_settings
(
API_PAGE_SIZE
=
10
)
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
'ENFORCE_PASSWORD_POLICY'
:
True
})
class
UsersApiTests
(
TestCase
):
class
UsersApiTests
(
ModuleStore
TestCase
):
""" Test suite for Users API views """
...
...
lms/djangoapps/api_manager/utils.py
View file @
232af6ed
...
...
@@ -32,7 +32,10 @@ def str2bool(value):
"""
convert string to bool
"""
return
value
.
lower
()
in
(
"true"
,)
if
value
:
return
value
.
lower
()
in
(
"true"
,)
else
:
return
False
def
generate_base_uri
(
request
,
strip_qs
=
False
):
...
...
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