BLD-1110: Create, edit, delete groups.
This commit is contained in:
@@ -5,6 +5,7 @@ import json
|
||||
from unittest import skipUnless
|
||||
from django.conf import settings
|
||||
from contentstore.utils import reverse_course_url
|
||||
from contentstore.views.component import SPLIT_TEST_COMPONENT_TYPE
|
||||
from contentstore.tests.utils import CourseTestCase
|
||||
from xmodule.partitions.partitions import Group, UserPartition
|
||||
|
||||
@@ -12,6 +13,10 @@ from xmodule.partitions.partitions import Group, UserPartition
|
||||
GROUP_CONFIGURATION_JSON = {
|
||||
u'name': u'Test name',
|
||||
u'description': u'Test description',
|
||||
u'groups': [
|
||||
{u'name': u'Group A'},
|
||||
{u'name': u'Group B'},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +101,6 @@ class GroupConfigurationsListHandlerTestCase(CourseTestCase, GroupConfigurations
|
||||
"""
|
||||
Test cases for group_configurations_list_handler.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Set up GroupConfigurationsListHandlerTestCase.
|
||||
@@ -109,13 +113,35 @@ class GroupConfigurationsListHandlerTestCase(CourseTestCase, GroupConfigurations
|
||||
"""
|
||||
return reverse_course_url('group_configurations_list_handler', self.course.id)
|
||||
|
||||
def test_can_retrieve_html(self):
|
||||
def test_view_index_ok(self):
|
||||
"""
|
||||
Check that the group configuration index page responds correctly.
|
||||
Basic check that the groups configuration page responds correctly.
|
||||
"""
|
||||
|
||||
self.course.user_partitions = [
|
||||
UserPartition(0, 'First name', 'First description', [Group(0, 'Group A'), Group(1, 'Group B'), Group(2, 'Group C')]),
|
||||
]
|
||||
self.save_course()
|
||||
|
||||
if SPLIT_TEST_COMPONENT_TYPE not in self.course.advanced_modules:
|
||||
self.course.advanced_modules.append(SPLIT_TEST_COMPONENT_TYPE)
|
||||
self.store.update_item(self.course, self.user.id)
|
||||
|
||||
response = self.client.get(self._url())
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn('New Group Configuration', response.content)
|
||||
self.assertContains(response, 'First name')
|
||||
self.assertContains(response, 'Group C')
|
||||
|
||||
def test_view_index_disabled(self):
|
||||
"""
|
||||
Check that group configuration page is not displayed when turned off.
|
||||
"""
|
||||
if SPLIT_TEST_COMPONENT_TYPE in self.course.advanced_modules:
|
||||
self.course.advanced_modules.remove(SPLIT_TEST_COMPONENT_TYPE)
|
||||
self.store.update_item(self.course, self.user.id)
|
||||
|
||||
resp = self.client.get(self._url())
|
||||
self.assertContains(resp, "module is disabled")
|
||||
|
||||
def test_unsupported_http_accept_header(self):
|
||||
"""
|
||||
@@ -157,8 +183,12 @@ class GroupConfigurationsListHandlerTestCase(CourseTestCase, GroupConfigurations
|
||||
self.assertEqual(len(group_ids), 2)
|
||||
self.reload_course()
|
||||
# Verify that user_partitions in the course contains the new group configuration.
|
||||
self.assertEqual(len(self.course.user_partitions), 1)
|
||||
self.assertEqual(self.course.user_partitions[0].name, u'Test name')
|
||||
user_partititons = self.course.user_partitions
|
||||
self.assertEqual(len(user_partititons), 1)
|
||||
self.assertEqual(user_partititons[0].name, u'Test name')
|
||||
self.assertEqual(len(user_partititons[0].groups), 2)
|
||||
self.assertEqual(user_partititons[0].groups[0].name, u'Group A')
|
||||
self.assertEqual(user_partititons[0].groups[1].name, u'Group B')
|
||||
|
||||
|
||||
# pylint: disable=no-member
|
||||
@@ -204,7 +234,7 @@ class GroupConfigurationsDetailHandlerTestCase(CourseTestCase, GroupConfiguratio
|
||||
|
||||
response = self.client.put(
|
||||
self._url(cid=999),
|
||||
data=json.dumps(GROUP_CONFIGURATION_JSON),
|
||||
data=json.dumps(expected),
|
||||
content_type="application/json",
|
||||
HTTP_ACCEPT="application/json",
|
||||
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
|
||||
@@ -213,8 +243,12 @@ class GroupConfigurationsDetailHandlerTestCase(CourseTestCase, GroupConfiguratio
|
||||
self.assertEqual(content, expected)
|
||||
self.reload_course()
|
||||
# Verify that user_partitions in the course contains the new group configuration.
|
||||
self.assertEqual(len(self.course.user_partitions), 1)
|
||||
self.assertEqual(self.course.user_partitions[0].name, u'Test name')
|
||||
user_partititons = self.course.user_partitions
|
||||
self.assertEqual(len(user_partititons), 1)
|
||||
self.assertEqual(user_partititons[0].name, u'Test name')
|
||||
self.assertEqual(len(user_partititons[0].groups), 2)
|
||||
self.assertEqual(user_partititons[0].groups[0].name, u'Group A')
|
||||
self.assertEqual(user_partititons[0].groups[1].name, u'Group B')
|
||||
|
||||
def test_can_edit_group_configuration(self):
|
||||
"""
|
||||
@@ -231,8 +265,8 @@ class GroupConfigurationsDetailHandlerTestCase(CourseTestCase, GroupConfiguratio
|
||||
u'description': u'New Test description',
|
||||
u'version': 1,
|
||||
u'groups': [
|
||||
{u'id': 0, u'name': u'Group A', u'version': 1},
|
||||
{u'id': 1, u'name': u'Group B', u'version': 1},
|
||||
{u'id': 0, u'name': u'New Group Name', u'version': 1},
|
||||
{u'id': 2, u'name': u'Group C', u'version': 1},
|
||||
],
|
||||
}
|
||||
response = self.client.put(
|
||||
@@ -246,5 +280,9 @@ class GroupConfigurationsDetailHandlerTestCase(CourseTestCase, GroupConfiguratio
|
||||
self.assertEqual(content, expected)
|
||||
self.reload_course()
|
||||
# Verify that user_partitions is properly updated in the course.
|
||||
self.assertEqual(len(self.course.user_partitions), 1)
|
||||
self.assertEqual(self.course.user_partitions[0].name, u'New Test name')
|
||||
user_partititons = self.course.user_partitions
|
||||
self.assertEqual(len(user_partititons), 1)
|
||||
self.assertEqual(user_partititons[0].name, u'New Test name')
|
||||
self.assertEqual(len(user_partititons[0].groups), 2)
|
||||
self.assertEqual(user_partititons[0].groups[0].name, u'New Group Name')
|
||||
self.assertEqual(user_partititons[0].groups[1].name, u'Group C')
|
||||
|
||||
@@ -6,19 +6,17 @@ import ddt
|
||||
|
||||
from mock import patch
|
||||
from pytz import UTC
|
||||
from unittest import skipUnless
|
||||
from webob import Response
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import Http404
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
from django.core.urlresolvers import reverse
|
||||
from contentstore.utils import reverse_usage_url, reverse_course_url
|
||||
from contentstore.utils import reverse_usage_url
|
||||
from contentstore.views.preview import StudioUserService
|
||||
|
||||
from contentstore.views.component import (
|
||||
component_handler, get_component_templates,
|
||||
SPLIT_TEST_COMPONENT_TYPE
|
||||
component_handler, get_component_templates
|
||||
)
|
||||
|
||||
from contentstore.tests.utils import CourseTestCase
|
||||
@@ -776,7 +774,6 @@ class TestEditItem(ItemTest):
|
||||
self.verify_publish_state(html_usage_key, PublishState.draft)
|
||||
|
||||
|
||||
@skipUnless(settings.FEATURES.get('ENABLE_GROUP_CONFIGURATIONS'), 'Tests Group Configurations feature')
|
||||
class TestEditSplitModule(ItemTest):
|
||||
"""
|
||||
Tests around editing instances of the split_test module.
|
||||
@@ -977,6 +974,12 @@ class TestEditSplitModule(ItemTest):
|
||||
group_id_to_child = split_test.group_id_to_child
|
||||
self.assertEqual(2, len(group_id_to_child))
|
||||
|
||||
# Test environment and Studio use different module systems
|
||||
# (CachingDescriptorSystem is used in tests, PreviewModuleSystem in Studio).
|
||||
# CachingDescriptorSystem doesn't have user service, that's needed for
|
||||
# SplitTestModule. So, in this line of code we add this service manually.
|
||||
split_test.runtime._services['user'] = StudioUserService(self.request) # pylint: disable=protected-access
|
||||
|
||||
# Call add_missing_groups method to add the missing group.
|
||||
split_test.add_missing_groups(self.request)
|
||||
split_test = self._assert_children(3)
|
||||
@@ -989,34 +992,6 @@ class TestEditSplitModule(ItemTest):
|
||||
split_test = self._assert_children(3)
|
||||
self.assertEqual(group_id_to_child, split_test.group_id_to_child)
|
||||
|
||||
def test_view_index_ok(self):
|
||||
"""
|
||||
Basic check that the groups configuration page responds correctly.
|
||||
"""
|
||||
if SPLIT_TEST_COMPONENT_TYPE not in self.course.advanced_modules:
|
||||
self.course.advanced_modules.append(SPLIT_TEST_COMPONENT_TYPE)
|
||||
self.store.update_item(self.course, self.user.id)
|
||||
|
||||
url = reverse_course_url('group_configurations_list_handler', self.course.id)
|
||||
resp = self.client.get(url)
|
||||
self.assertContains(resp, self.course.display_name)
|
||||
self.assertContains(resp, 'First Partition')
|
||||
self.assertContains(resp, 'alpha')
|
||||
self.assertContains(resp, 'Second Partition')
|
||||
self.assertContains(resp, 'Group 1')
|
||||
|
||||
def test_view_index_disabled(self):
|
||||
"""
|
||||
Check that group configuration page is not displayed when turned off.
|
||||
"""
|
||||
if SPLIT_TEST_COMPONENT_TYPE in self.course.advanced_modules:
|
||||
self.course.advanced_modules.remove(SPLIT_TEST_COMPONENT_TYPE)
|
||||
self.store.update_item(self.course, self.user.id)
|
||||
|
||||
url = reverse_course_url('group_configurations_list_handler', self.course.id)
|
||||
resp = self.client.get(url)
|
||||
self.assertContains(resp, "module is disabled")
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestComponentHandler(TestCase):
|
||||
|
||||
Reference in New Issue
Block a user