from course_groups.models import CourseUserGroup from course_groups.cohorts import (get_cohort, get_course_cohorts, is_commentable_cohorted, get_cohort_by_name) from xmodule.modulestore.django import modulestore, clear_existing_modulestores from xmodule.modulestore.tests.django_utils import mixed_store_config # NOTE: running this with the lms.envs.test config works without # manually overriding the modulestore. However, running with # cms.envs.test doesn't. TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT TEST_MAPPING = {'edX/toy/2012_Fall': 'xml'} TEST_DATA_MIXED_MODULESTORE = mixed_store_config(TEST_DATA_DIR, TEST_MAPPING) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) class TestCohorts(django.test.TestCase): @staticmethod def topic_name_to_id(course, name): """ Given a discussion topic name, return an id for that name (includes course and url_name). """ return "{course}_{run}_{name}".format(course=course.location.course, run=course.url_name, name=name)
from django.test.utils import override_settings from django.core.urlresolvers import reverse from rest_framework.test import APITestCase from rest_framework import status from django.conf import settings from xmodule.modulestore.tests.django_utils import (ModuleStoreTestCase, mixed_store_config) from xmodule.modulestore.tests.factories import CourseFactory from enrollment import api from enrollment.errors import CourseEnrollmentError from student.tests.factories import UserFactory, CourseModeFactory from student.models import CourseEnrollment # Since we don't need any XML course fixtures, use a modulestore configuration # that disables the XML modulestore. MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) @ddt.ddt @override_settings(MODULESTORE=MODULESTORE_CONFIG) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') class EnrollmentTest(ModuleStoreTestCase, APITestCase): """ Test user enrollment, especially with different course modes. """ USERNAME = "******" EMAIL = "*****@*****.**" PASSWORD = "******" def setUp(self):
from xmodule.modulestore.tests.django_utils import ( TEST_DATA_MONGO_MODULESTORE, TEST_DATA_SPLIT_MODULESTORE ) from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.xml_importer import import_course_from_xml DATA_DIR = settings.COMMON_TEST_DATA_ROOT XML_COURSE_DIRS = ['toy', 'simple', 'open_ended'] MAPPINGS = { 'edX/toy/2012_Fall': 'xml', 'edX/simple/2012_Fall': 'xml', 'edX/open_ended/2012_Fall': 'xml', } TEST_DATA_MIXED_XML_MODULESTORE = mixed_store_config( DATA_DIR, MAPPINGS, include_xml=True, xml_source_dirs=XML_COURSE_DIRS, ) @attr('shard_1') class CommandsTestBase(ModuleStoreTestCase): """ Base class for testing different django commands. Must be subclassed using override_settings set to the modulestore to be tested. """ __test__ = False url_name = '2012_Fall'
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config from xmodule.modulestore.tests.django_utils import ( TEST_DATA_MONGO_MODULESTORE, TEST_DATA_SPLIT_MODULESTORE) from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.xml_importer import import_course_from_xml DATA_DIR = settings.COMMON_TEST_DATA_ROOT XML_COURSE_DIRS = ['toy', 'simple'] MAPPINGS = { 'edX/toy/2012_Fall': 'xml', 'edX/simple/2012_Fall': 'xml', } TEST_DATA_MIXED_XML_MODULESTORE = mixed_store_config( DATA_DIR, MAPPINGS, include_xml=True, xml_source_dirs=XML_COURSE_DIRS, ) @attr('shard_1') class CommandsTestBase(ModuleStoreTestCase): """ Base class for testing different django commands. Must be subclassed using override_settings set to the modulestore to be tested. """ __test__ = False url_name = '2012_Fall'
from lxml.html import soupparser from django.test.utils import override_settings from django.core.urlresolvers import reverse from django.conf import settings from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config from student.tests.factories import UserFactory from student.models import CourseEnrollment from course_modes.tests.factories import CourseModeFactory from verify_student.models import SoftwareSecurePhotoVerification # Since we don't need any XML course fixtures, use a modulestore configuration # that disables the XML modulestore. MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False) @override_settings(MODULESTORE=MODULESTORE_CONFIG) class TestProfEdVerification(ModuleStoreTestCase): """ Integration test for professional ed verification, including course mode selection. """ # Choose an uncommon number for the price so we can search for it on the page MIN_PRICE = 1438 def setUp(self): self.user = UserFactory.create(username="******", password="******") self.client.login(username="******", password="******") course = CourseFactory.create(org='Robot', number='999', display_name='Test Course')
from social.apps.django_app.default.models import UserSocialAuth from student.tests.factories import UserFactory, RegistrationFactory, UserProfileFactory from student.views import ( _parse_course_id_from_string, _get_course_enrollment_domain, login_oauth_token, ) from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config from xmodule.modulestore.django import modulestore from external_auth.models import ExternalAuthMap from opaque_keys.edx.locations import SlashSeparatedCourseKey TEST_DATA_MIXED_MODULESTORE = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}) class LoginTest(TestCase): ''' Test student.views.login_user() view ''' def setUp(self): # Create one user and save it to the database self.user = UserFactory.build(username='******', email='*****@*****.**') self.user.set_password('test_password') self.user.save() # Create a registration for the user RegistrationFactory(user=self.user)
import uuid from django.conf import settings from django.contrib.auth.models import Group, User from django.test.utils import override_settings from courseware.management.commands import delete_course_references from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from edx_solutions_api_integration.models import ( GroupProfile, CourseGroupRelationship, CourseContentGroupRelationship) from edx_solutions_projects import models as project_models from gradebook import models as gradebook_models from progress import models as progress_models MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}) @override_settings(MODULESTORE=MODULESTORE_CONFIG) class DeleteCourseReferencesTests(ModuleStoreTestCase): """ Test suite for course reference deletion script """ def setUp(self): super(DeleteCourseReferencesTests, self).setUp() # Create a course to work with self.course = CourseFactory.create(start=datetime(2014, 6, 16, 14, 30), end=datetime(2020, 1, 16)) test_data = '<html>{}</html>'.format(str(uuid.uuid4())) self.chapter = ItemFactory.create(category="chapter",
from student.models import CourseEnrollment from student.tests.factories import UserFactory from xmodule.modulestore.django import modulestore, clear_existing_modulestores from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_TOY_MODULESTORE, mixed_store_config from ..models import CourseUserGroup, CourseUserGroupPartitionGroup from .. import cohorts from ..tests.helpers import topic_name_to_id, config_course_cohorts, CohortFactory # NOTE: running this with the lms.envs.test config works without # manually overriding the modulestore. However, running with # cms.envs.test doesn't. TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT TEST_MAPPING = {'edX/toy/2012_Fall': 'xml'} TEST_DATA_MIXED_MODULESTORE = mixed_store_config(TEST_DATA_DIR, TEST_MAPPING) @patch("openedx.core.djangoapps.course_groups.cohorts.tracker") class TestCohortSignals(TestCase): def setUp(self): self.course_key = SlashSeparatedCourseKey("dummy", "dummy", "dummy") def test_cohort_added(self, mock_tracker): # Add cohort cohort = CourseUserGroup.objects.create( name="TestCohort", course_id=self.course_key, group_type=CourseUserGroup.COHORT ) mock_tracker.emit.assert_called_with(
from django.contrib.auth.models import Group, User from django.test.utils import override_settings from courseware.management.commands import delete_course_references from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from edx_solutions_api_integration.models import ( GroupProfile, CourseGroupRelationship, CourseContentGroupRelationship ) from edx_solutions_projects import models as project_models from gradebook import models as gradebook_models from progress import models as progress_models MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}) @override_settings(MODULESTORE=MODULESTORE_CONFIG) class DeleteCourseReferencesTests(ModuleStoreTestCase): """ Test suite for course reference deletion script """ def setUp(self): super(DeleteCourseReferencesTests, self).setUp() # Create a course to work with self.course = CourseFactory.create( start=datetime(2014, 6, 16, 14, 30), end=datetime(2020, 1, 16) )
Define test configuration for modulestores. """ from xmodule.modulestore.tests.django_utils import xml_store_config, \ mixed_store_config from django.conf import settings TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR) # Map all XML course fixtures so they are accessible through # the MixedModuleStore MAPPINGS = { 'edX/simple/2012_Fall': 'xml', 'edX/toy/2012_Fall': 'xml', 'edX/toy/TT_2012_Fall': 'xml', 'edX/test_end/2012_Fall': 'xml', 'edX/test_about_blob_end_date/2012_Fall': 'xml', 'edX/graded/2012_Fall': 'xml', 'edX/open_ended/2012_Fall': 'xml', 'edX/due_date/2013_fall': 'xml', 'edX/open_ended_nopath/2012_Fall': 'xml', 'edX/detached_pages/2014': 'xml', } TEST_DATA_MIXED_MODULESTORE = mixed_store_config(TEST_DATA_DIR, MAPPINGS) # All store requests now go through mixed # Some tests require that no XML courses exist. So provide the following constant with no course Mappings. TEST_DATA_MONGO_MODULESTORE = mixed_store_config(TEST_DATA_DIR, {})
CohortedTopicGroupIdTestMixin, NonCohortedTopicGroupIdTestMixin ) from django_comment_client.tests.unicode import UnicodeTestMixin from django_comment_client.tests.utils import CohortedContentTestCase from django_comment_client.forum import views from django_comment_client.utils import strip_none from courseware.tests.modulestore_config import TEST_DATA_DIR from courseware.courses import UserNotEnrolled from nose.tools import assert_true # pylint: disable=no-name-in-module from mock import patch, Mock, ANY, call from course_groups.models import CourseUserGroup TEST_DATA_MONGO_MODULESTORE = mixed_store_config(TEST_DATA_DIR, {}, include_xml=False) log = logging.getLogger(__name__) # pylint: disable=missing-docstring @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) class ViewsExceptionTestCase(UrlResetMixin, ModuleStoreTestCase): @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): # Patching the ENABLE_DISCUSSION_SERVICE value affects the contents of urls.py, # so we need to call super.setUp() which reloads urls.py (because # of the UrlResetMixin)
from xmodule.partitions.partitions import Group, UserPartition, UserPartitionError from xmodule.modulestore.django import modulestore, clear_existing_modulestores from xmodule.modulestore.tests.django_utils import mixed_store_config from opaque_keys.edx.locations import SlashSeparatedCourseKey from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme from ..partition_scheme import CohortPartitionScheme, get_cohorted_user_partition from ..models import CourseUserGroupPartitionGroup from ..views import link_cohort_to_partition_group, unlink_cohort_partition_group from ..cohorts import add_user_to_cohort, get_course_cohorts from .helpers import CohortFactory, config_course_cohorts TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT TEST_MAPPING = {'edX/toy/2012_Fall': 'xml'} TEST_DATA_MIXED_MODULESTORE = mixed_store_config(TEST_DATA_DIR, TEST_MAPPING, include_xml=True) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) class TestCohortPartitionScheme(django.test.TestCase): """ Test the logic for linking a user to a partition group based on their cohort. """ def setUp(self): """ Regenerate a course with cohort configuration, partition and groups, and a student for each test. """ self.course_key = SlashSeparatedCourseKey("edX", "toy", "2012_Fall") self.course = modulestore().get_course(self.course_key)
CohortedTopicGroupIdTestMixin, NonCohortedTopicGroupIdTestMixin ) from django_comment_client.tests.unicode import UnicodeTestMixin from django_comment_client.tests.utils import CohortedContentTestCase from django_comment_client.forum import views from django_comment_client.utils import strip_none from courseware.tests.modulestore_config import TEST_DATA_DIR from courseware.courses import UserNotEnrolled from nose.tools import assert_true # pylint: disable=E0611 from mock import patch, Mock, ANY, call from course_groups.models import CourseUserGroup TEST_DATA_MONGO_MODULESTORE = mixed_store_config(TEST_DATA_DIR, {}, include_xml=False) log = logging.getLogger(__name__) # pylint: disable=C0111 @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) class ViewsExceptionTestCase(UrlResetMixin, ModuleStoreTestCase): @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): # Patching the ENABLE_DISCUSSION_SERVICE value affects the contents of urls.py, # so we need to call super.setUp() which reloads urls.py (because # of the UrlResetMixin)