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
3de3238b
Commit
3de3238b
authored
Apr 21, 2014
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
75942770
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
33 deletions
+62
-33
lms/djangoapps/api_manager/groups_views.py
+25
-1
lms/djangoapps/api_manager/models.py
+16
-0
lms/djangoapps/api_manager/tests/test_groups_views.py
+21
-32
No files found.
lms/djangoapps/api_manager/groups_views.py
View file @
3de3238b
""" API implementation for group-oriented interactions. """
""" API implementation for group-oriented interactions. """
import
uuid
import
uuid
import
json
from
django.contrib.auth.models
import
Group
,
User
from
django.contrib.auth.models
import
Group
,
User
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.exceptions
import
ObjectDoesNotExist
...
@@ -10,7 +11,7 @@ from rest_framework.decorators import api_view, permission_classes
...
@@ -10,7 +11,7 @@ from rest_framework.decorators import api_view, permission_classes
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
api_manager.permissions
import
ApiKeyHeaderPermission
from
api_manager.permissions
import
ApiKeyHeaderPermission
from
api_manager.models
import
GroupRelationship
,
CourseGroupRelationship
from
api_manager.models
import
GroupRelationship
,
CourseGroupRelationship
,
GroupProfile
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore
import
Location
,
InvalidLocationError
from
xmodule.modulestore
import
Location
,
InvalidLocationError
...
@@ -43,13 +44,23 @@ def group_list(request):
...
@@ -43,13 +44,23 @@ def group_list(request):
# Group name must be unique, but we need to support dupes
# Group name must be unique, but we need to support dupes
group
=
Group
.
objects
.
create
(
name
=
str
(
uuid
.
uuid4
()))
group
=
Group
.
objects
.
create
(
name
=
str
(
uuid
.
uuid4
()))
original_group_name
=
request
.
DATA
[
'name'
]
original_group_name
=
request
.
DATA
[
'name'
]
group
.
name
=
'{:04d}: {}'
.
format
(
group
.
id
,
original_group_name
)
group
.
name
=
'{:04d}: {}'
.
format
(
group
.
id
,
original_group_name
)
group
.
record_active
=
True
group
.
record_active
=
True
group
.
record_date_created
=
timezone
.
now
()
group
.
record_date_created
=
timezone
.
now
()
group
.
record_date_modified
=
timezone
.
now
()
group
.
record_date_modified
=
timezone
.
now
()
group
.
save
()
group
.
save
()
# Relationship model also allows us to use duplicate names
# Relationship model also allows us to use duplicate names
GroupRelationship
.
objects
.
create
(
name
=
original_group_name
,
group_id
=
group
.
id
,
parent_group
=
None
)
GroupRelationship
.
objects
.
create
(
name
=
original_group_name
,
group_id
=
group
.
id
,
parent_group
=
None
)
# allow for optional meta information about groups, this will end up in the GroupProfile table
group_type
=
request
.
DATA
.
get
(
'group_type'
)
data
=
request
.
DATA
.
get
(
'data'
)
if
group_type
or
data
:
profile
,
_
=
GroupProfile
.
objects
.
get_or_create
(
group_id
=
group
.
id
,
group_type
=
group_type
,
data
=
data
)
response_data
=
{
'id'
:
group
.
id
,
'name'
:
original_group_name
}
response_data
=
{
'id'
:
group
.
id
,
'name'
:
original_group_name
}
base_uri
=
_generate_base_uri
(
request
)
base_uri
=
_generate_base_uri
(
request
)
response_data
[
'uri'
]
=
'{}/{}'
.
format
(
base_uri
,
group
.
id
)
response_data
[
'uri'
]
=
'{}/{}'
.
format
(
base_uri
,
group
.
id
)
...
@@ -80,6 +91,19 @@ def group_detail(request, group_id):
...
@@ -80,6 +91,19 @@ def group_detail(request, group_id):
response_data
[
'resources'
]
.
append
({
'uri'
:
resource_uri
})
response_data
[
'resources'
]
.
append
({
'uri'
:
resource_uri
})
resource_uri
=
'{}/groups'
.
format
(
base_uri
)
resource_uri
=
'{}/groups'
.
format
(
base_uri
)
response_data
[
'resources'
]
.
append
({
'uri'
:
resource_uri
})
response_data
[
'resources'
]
.
append
({
'uri'
:
resource_uri
})
# see if there is an (optional) GroupProfile
try
:
existing_group_profile
=
GroupProfile
.
objects
.
get
(
group_id
=
group_id
)
if
existing_group_profile
.
group_type
:
response_data
[
'group_type'
]
=
existing_group_profile
.
group_type
data
=
existing_group_profile
.
data
if
data
:
print
'******* data = {0}'
.
format
(
data
)
response_data
[
'data'
]
=
json
.
loads
(
data
)
except
ObjectDoesNotExist
:
pass
response_status
=
status
.
HTTP_200_OK
response_status
=
status
.
HTTP_200_OK
else
:
else
:
response_status
=
status
.
HTTP_404_NOT_FOUND
response_status
=
status
.
HTTP_404_NOT_FOUND
...
...
lms/djangoapps/api_manager/models.py
View file @
3de3238b
...
@@ -92,3 +92,19 @@ class CourseGroupRelationship(models.Model):
...
@@ -92,3 +92,19 @@ class CourseGroupRelationship(models.Model):
"""
"""
course_id
=
models
.
CharField
(
max_length
=
255
,
db_index
=
True
)
course_id
=
models
.
CharField
(
max_length
=
255
,
db_index
=
True
)
group
=
models
.
ForeignKey
(
Group
,
db_index
=
True
)
group
=
models
.
ForeignKey
(
Group
,
db_index
=
True
)
class
GroupProfile
(
models
.
Model
):
"""
This table will provide additional tables regarding groups. This has a foreign key to
the auth_groups table
"""
class
Meta
:
db_table
=
"auth_groupprofile"
group
=
models
.
ForeignKey
(
Group
,
db_index
=
True
)
group_type
=
models
.
CharField
(
null
=
True
,
max_length
=
32
,
db_index
=
True
)
data
=
models
.
TextField
(
blank
=
True
)
# JSON dictionary for generic key/value pairs
lms/djangoapps/api_manager/tests/test_groups_views.py
View file @
3de3238b
...
@@ -7,6 +7,7 @@ Run these tests @ Devstack:
...
@@ -7,6 +7,7 @@ Run these tests @ Devstack:
from
random
import
randint
from
random
import
randint
import
unittest
import
unittest
import
uuid
import
uuid
import
json
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.cache
import
cache
from
django.core.cache
import
cache
...
@@ -75,7 +76,6 @@ class GroupsApiTests(TestCase):
...
@@ -75,7 +76,6 @@ class GroupsApiTests(TestCase):
response
=
self
.
client
.
delete
(
uri
,
headers
=
headers
)
response
=
self
.
client
.
delete
(
uri
,
headers
=
headers
)
return
response
return
response
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_list_post
(
self
):
def
test_group_list_post
(
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
)
...
@@ -96,7 +96,6 @@ class GroupsApiTests(TestCase):
...
@@ -96,7 +96,6 @@ class GroupsApiTests(TestCase):
# response = self.do_post(self.base_groups_uri, data)
# response = self.do_post(self.base_groups_uri, data)
# self.assertEqual(response.status_code, 409)
# self.assertEqual(response.status_code, 409)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_detail_get
(
self
):
def
test_group_detail_get
(
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
)
...
@@ -110,13 +109,31 @@ class GroupsApiTests(TestCase):
...
@@ -110,13 +109,31 @@ class GroupsApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'uri'
],
confirm_uri
)
self
.
assertEqual
(
response
.
data
[
'uri'
],
confirm_uri
)
self
.
assertEqual
(
response
.
data
[
'name'
],
self
.
test_group_name
)
self
.
assertEqual
(
response
.
data
[
'name'
],
self
.
test_group_name
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_list_get_with_profile
(
self
):
data
=
{
'name'
:
self
.
test_group_name
,
'group_type'
:
'series'
,
'data'
:
json
.
dumps
({
'display_name'
:
'My first series'
})
}
response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
self
.
assertGreater
(
response
.
data
[
'id'
],
0
)
group_id
=
response
.
data
[
'id'
]
test_uri
=
self
.
base_groups_uri
+
'/'
+
str
(
group_id
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
[
'id'
],
group_id
)
confirm_uri
=
self
.
test_server_prefix
+
test_uri
self
.
assertEqual
(
response
.
data
[
'uri'
],
confirm_uri
)
self
.
assertEqual
(
response
.
data
[
'name'
],
self
.
test_group_name
)
self
.
assertEqual
(
response
.
data
[
'group_type'
],
'series'
)
self
.
assertEqual
(
response
.
data
[
'data'
][
'display_name'
],
'My first series'
)
def
test_group_detail_get_undefined
(
self
):
def
test_group_detail_get_undefined
(
self
):
test_uri
=
self
.
base_groups_uri
+
'/123456789'
test_uri
=
self
.
base_groups_uri
+
'/123456789'
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_users_list_post
(
self
):
def
test_group_users_list_post
(
self
):
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
...
@@ -136,7 +153,6 @@ class GroupsApiTests(TestCase):
...
@@ -136,7 +153,6 @@ class GroupsApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'group_id'
],
str
(
group_id
))
self
.
assertEqual
(
response
.
data
[
'group_id'
],
str
(
group_id
))
self
.
assertEqual
(
response
.
data
[
'user_id'
],
str
(
user_id
))
self
.
assertEqual
(
response
.
data
[
'user_id'
],
str
(
user_id
))
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_users_list_post_duplicate
(
self
):
def
test_group_users_list_post_duplicate
(
self
):
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
...
@@ -153,7 +169,6 @@ class GroupsApiTests(TestCase):
...
@@ -153,7 +169,6 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_post
(
test_uri
,
data
)
response
=
self
.
do_post
(
test_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
409
)
self
.
assertEqual
(
response
.
status_code
,
409
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_users_list_post_invalid_resources
(
self
):
def
test_group_users_list_post_invalid_resources
(
self
):
test_uri
=
self
.
base_groups_uri
+
'/1239878976'
test_uri
=
self
.
base_groups_uri
+
'/1239878976'
test_uri
=
test_uri
+
'/users'
test_uri
=
test_uri
+
'/users'
...
@@ -161,7 +176,6 @@ class GroupsApiTests(TestCase):
...
@@ -161,7 +176,6 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_post
(
test_uri
,
data
)
response
=
self
.
do_post
(
test_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_users_detail_get
(
self
):
def
test_group_users_detail_get
(
self
):
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
...
@@ -184,7 +198,6 @@ class GroupsApiTests(TestCase):
...
@@ -184,7 +198,6 @@ class GroupsApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'group_id'
],
group_id
)
self
.
assertEqual
(
response
.
data
[
'group_id'
],
group_id
)
self
.
assertEqual
(
response
.
data
[
'user_id'
],
user_id
)
self
.
assertEqual
(
response
.
data
[
'user_id'
],
user_id
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_users_detail_delete
(
self
):
def
test_group_users_detail_delete
(
self
):
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
...
@@ -205,13 +218,11 @@ class GroupsApiTests(TestCase):
...
@@ -205,13 +218,11 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_users_detail_delete_invalid_group
(
self
):
def
test_group_users_detail_delete_invalid_group
(
self
):
test_uri
=
self
.
base_groups_uri
+
'/123987102/users/123124'
test_uri
=
self
.
base_groups_uri
+
'/123987102/users/123124'
response
=
self
.
do_delete
(
test_uri
)
response
=
self
.
do_delete
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
204
)
self
.
assertEqual
(
response
.
status_code
,
204
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_users_detail_delete_invalid_user
(
self
):
def
test_group_users_detail_delete_invalid_user
(
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
)
...
@@ -220,7 +231,6 @@ class GroupsApiTests(TestCase):
...
@@ -220,7 +231,6 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_delete
(
test_uri
)
response
=
self
.
do_delete
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
204
)
self
.
assertEqual
(
response
.
status_code
,
204
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_users_detail_get_undefined
(
self
):
def
test_group_users_detail_get_undefined
(
self
):
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
local_username
=
self
.
test_username
+
str
(
randint
(
11
,
99
))
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
data
=
{
'email'
:
self
.
test_email
,
'username'
:
local_username
,
'password'
:
self
.
test_password
}
...
@@ -233,7 +243,6 @@ class GroupsApiTests(TestCase):
...
@@ -233,7 +243,6 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_list_post_hierarchical
(
self
):
def
test_group_groups_list_post_hierarchical
(
self
):
data
=
{
'name'
:
'Alpha Group'
}
data
=
{
'name'
:
'Alpha Group'
}
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
@@ -256,7 +265,6 @@ class GroupsApiTests(TestCase):
...
@@ -256,7 +265,6 @@ class GroupsApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'group_id'
],
str
(
group_id
))
self
.
assertEqual
(
response
.
data
[
'group_id'
],
str
(
group_id
))
self
.
assertEqual
(
response
.
data
[
'relationship_type'
],
relationship_type
)
self
.
assertEqual
(
response
.
data
[
'relationship_type'
],
relationship_type
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_list_post_linked
(
self
):
def
test_group_groups_list_post_linked
(
self
):
data
=
{
'name'
:
'Alpha Group'
}
data
=
{
'name'
:
'Alpha Group'
}
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
@@ -279,7 +287,6 @@ class GroupsApiTests(TestCase):
...
@@ -279,7 +287,6 @@ class GroupsApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'group_id'
],
str
(
group_id
))
self
.
assertEqual
(
response
.
data
[
'group_id'
],
str
(
group_id
))
self
.
assertEqual
(
response
.
data
[
'relationship_type'
],
relationship_type
)
self
.
assertEqual
(
response
.
data
[
'relationship_type'
],
relationship_type
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_list_post_linked_duplicate
(
self
):
def
test_group_groups_list_post_linked_duplicate
(
self
):
data
=
{
'name'
:
'Alpha Group'
}
data
=
{
'name'
:
'Alpha Group'
}
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
@@ -300,7 +307,6 @@ class GroupsApiTests(TestCase):
...
@@ -300,7 +307,6 @@ class GroupsApiTests(TestCase):
# Duplicate responses are idemnotent in this case
# Duplicate responses are idemnotent in this case
self
.
assertEqual
(
response
.
status_code
,
201
)
self
.
assertEqual
(
response
.
status_code
,
201
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_list_post_invalid_group
(
self
):
def
test_group_groups_list_post_invalid_group
(
self
):
test_uri
=
self
.
base_groups_uri
+
'/123098/groups'
test_uri
=
self
.
base_groups_uri
+
'/123098/groups'
relationship_type
=
'g'
# Graph
relationship_type
=
'g'
# Graph
...
@@ -308,7 +314,6 @@ class GroupsApiTests(TestCase):
...
@@ -308,7 +314,6 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_post
(
test_uri
,
data
)
response
=
self
.
do_post
(
test_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_list_post_invalid_relationship_type
(
self
):
def
test_group_groups_list_post_invalid_relationship_type
(
self
):
data
=
{
'name'
:
'Alpha Group'
}
data
=
{
'name'
:
'Alpha Group'
}
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
@@ -326,7 +331,6 @@ class GroupsApiTests(TestCase):
...
@@ -326,7 +331,6 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_post
(
test_uri
,
data
)
response
=
self
.
do_post
(
test_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
406
)
self
.
assertEqual
(
response
.
status_code
,
406
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_list_get
(
self
):
def
test_group_groups_list_get
(
self
):
data
=
{
'name'
:
'Bravo Group'
}
data
=
{
'name'
:
'Bravo Group'
}
bravo_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
bravo_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
@@ -376,13 +380,11 @@ class GroupsApiTests(TestCase):
...
@@ -376,13 +380,11 @@ class GroupsApiTests(TestCase):
self
.
assertGreater
(
len
(
relationship
[
'uri'
]),
0
)
self
.
assertGreater
(
len
(
relationship
[
'uri'
]),
0
)
self
.
assertEqual
(
relationship_count
,
len
(
group_idlist
))
self
.
assertEqual
(
relationship_count
,
len
(
group_idlist
))
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_list_get_notfound
(
self
):
def
test_group_groups_list_get_notfound
(
self
):
test_uri
=
self
.
base_groups_uri
+
'/213213123/groups'
test_uri
=
self
.
base_groups_uri
+
'/213213123/groups'
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_detail_get_hierarchical
(
self
):
def
test_group_groups_detail_get_hierarchical
(
self
):
data
=
{
'name'
:
'Alpha Group'
}
data
=
{
'name'
:
'Alpha Group'
}
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
@@ -410,7 +412,6 @@ class GroupsApiTests(TestCase):
...
@@ -410,7 +412,6 @@ class GroupsApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'to_group_id'
],
str
(
delta_group_id
))
self
.
assertEqual
(
response
.
data
[
'to_group_id'
],
str
(
delta_group_id
))
self
.
assertEqual
(
response
.
data
[
'relationship_type'
],
relationship_type
)
self
.
assertEqual
(
response
.
data
[
'relationship_type'
],
relationship_type
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_detail_get_linked
(
self
):
def
test_group_groups_detail_get_linked
(
self
):
data
=
{
'name'
:
'Alpha Group'
}
data
=
{
'name'
:
'Alpha Group'
}
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
@@ -441,7 +442,6 @@ class GroupsApiTests(TestCase):
...
@@ -441,7 +442,6 @@ class GroupsApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'to_group_id'
],
str
(
delta_group_id
))
self
.
assertEqual
(
response
.
data
[
'to_group_id'
],
str
(
delta_group_id
))
self
.
assertEqual
(
response
.
data
[
'relationship_type'
],
relationship_type
)
self
.
assertEqual
(
response
.
data
[
'relationship_type'
],
relationship_type
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_detail_get_notfound
(
self
):
def
test_group_groups_detail_get_notfound
(
self
):
data
=
{
'name'
:
'Alpha Group'
}
data
=
{
'name'
:
'Alpha Group'
}
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
@@ -450,7 +450,6 @@ class GroupsApiTests(TestCase):
...
@@ -450,7 +450,6 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_detail_delete_hierarchical
(
self
):
def
test_group_groups_detail_delete_hierarchical
(
self
):
data
=
{
'name'
:
'Alpha Group'
}
data
=
{
'name'
:
'Alpha Group'
}
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
@@ -482,7 +481,6 @@ class GroupsApiTests(TestCase):
...
@@ -482,7 +481,6 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_detail_delete_linked
(
self
):
def
test_group_groups_detail_delete_linked
(
self
):
data
=
{
'name'
:
'Alpha Group'
}
data
=
{
'name'
:
'Alpha Group'
}
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
alpha_response
=
self
.
do_post
(
self
.
base_groups_uri
,
data
)
...
@@ -512,13 +510,11 @@ class GroupsApiTests(TestCase):
...
@@ -512,13 +510,11 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_groups_detail_delete_invalid
(
self
):
def
test_group_groups_detail_delete_invalid
(
self
):
test_uri
=
self
.
base_groups_uri
+
'/1231234232/groups/1'
test_uri
=
self
.
base_groups_uri
+
'/1231234232/groups/1'
response
=
self
.
do_delete
(
test_uri
)
response
=
self
.
do_delete
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_courses_list_post
(
self
):
def
test_group_courses_list_post
(
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
)
...
@@ -533,7 +529,6 @@ class GroupsApiTests(TestCase):
...
@@ -533,7 +529,6 @@ class GroupsApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'group_id'
],
str
(
group_id
))
self
.
assertEqual
(
response
.
data
[
'group_id'
],
str
(
group_id
))
self
.
assertEqual
(
response
.
data
[
'course_id'
],
self
.
test_course_id
)
self
.
assertEqual
(
response
.
data
[
'course_id'
],
self
.
test_course_id
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_courses_list_post_duplicate
(
self
):
def
test_group_courses_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
)
...
@@ -546,14 +541,12 @@ class GroupsApiTests(TestCase):
...
@@ -546,14 +541,12 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_post
(
test_uri
,
data
)
response
=
self
.
do_post
(
test_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
409
)
self
.
assertEqual
(
response
.
status_code
,
409
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_courses_list_post_invalid_resources
(
self
):
def
test_group_courses_list_post_invalid_resources
(
self
):
test_uri
=
self
.
base_groups_uri
+
'/1239878976/courses'
test_uri
=
self
.
base_groups_uri
+
'/1239878976/courses'
data
=
{
'course_id'
:
"98723896"
}
data
=
{
'course_id'
:
"98723896"
}
response
=
self
.
do_post
(
test_uri
,
data
)
response
=
self
.
do_post
(
test_uri
,
data
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_courses_detail_get
(
self
):
def
test_group_courses_detail_get
(
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
)
...
@@ -576,7 +569,6 @@ class GroupsApiTests(TestCase):
...
@@ -576,7 +569,6 @@ class GroupsApiTests(TestCase):
self
.
assertEqual
(
response
.
data
[
'group_id'
],
group_id
)
self
.
assertEqual
(
response
.
data
[
'group_id'
],
group_id
)
self
.
assertEqual
(
response
.
data
[
'course_id'
],
self
.
test_course_id
)
self
.
assertEqual
(
response
.
data
[
'course_id'
],
self
.
test_course_id
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_courses_detail_delete
(
self
):
def
test_group_courses_detail_delete
(
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
)
...
@@ -593,13 +585,11 @@ class GroupsApiTests(TestCase):
...
@@ -593,13 +585,11 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_courses_detail_delete_invalid_group
(
self
):
def
test_group_courses_detail_delete_invalid_group
(
self
):
test_uri
=
self
.
base_groups_uri
+
'/123987102/courses/123124'
test_uri
=
self
.
base_groups_uri
+
'/123987102/courses/123124'
response
=
self
.
do_delete
(
test_uri
)
response
=
self
.
do_delete
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
204
)
self
.
assertEqual
(
response
.
status_code
,
204
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_courses_detail_delete_invalid_course
(
self
):
def
test_group_courses_detail_delete_invalid_course
(
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
)
...
@@ -608,7 +598,6 @@ class GroupsApiTests(TestCase):
...
@@ -608,7 +598,6 @@ class GroupsApiTests(TestCase):
response
=
self
.
do_delete
(
test_uri
)
response
=
self
.
do_delete
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
204
)
self
.
assertEqual
(
response
.
status_code
,
204
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
def
test_group_courses_detail_get_undefined
(
self
):
def
test_group_courses_detail_get_undefined
(
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
)
...
...
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