Exemplo n.º 1
0
def run():
    """
    Executed during django startup
    """
    django_utils_translation.patch()

    autostartup()

    add_mimetypes()

    if settings.FEATURES.get('USE_CUSTOM_THEME', False):
        enable_stanford_theme()

    if settings.FEATURES.get('USE_MICROSITES', False):
        enable_microsites()

    if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False):
        enable_third_party_auth()

    # Initialize Segment.io analytics module. Flushes first time a message is received and
    # every 50 messages thereafter, or if 10 seconds have passed since last flush
    if settings.FEATURES.get('SEGMENT_IO_LMS') and hasattr(settings, 'SEGMENT_IO_LMS_KEY'):
        analytics.init(settings.SEGMENT_IO_LMS_KEY, flush_at=50)

    # register any dependency injections that we need to support in edx_proctoring
    # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit
    # as well as the instructor dashboard (for deleting student attempts)
    if settings.FEATURES.get('ENABLE_PROCTORED_EXAMS'):
        # Import these here to avoid circular dependencies of the form:
        # edx-platform app --> DRF --> django translation --> edx-platform app
        from edx_proctoring.runtime import set_runtime_service
        from instructor.services import InstructorService
        from openedx.core.djangoapps.credit.services import CreditService
        set_runtime_service('credit', CreditService())
        set_runtime_service('instructor', InstructorService())
Exemplo n.º 2
0
    def test_send_email_unicode(self):
        """
        Assert that email can be sent with a unicode course name.
        """

        course_name = u'अआईउऊऋऌ अआईउऊऋऌ'
        set_runtime_service('credit', MockCreditService(course_name=course_name))

        exam_attempt = self._create_started_exam_attempt()
        credit_state = get_runtime_service('credit').get_credit_state(self.user_id, self.course_id)
        update_attempt_status(
            exam_attempt.proctored_exam_id,
            self.user.id,
            ProctoredExamStudentAttemptStatus.submitted
        )
        self.assertEqual(len(mail.outbox), 1)

        # Verify the subject
        actual_subject = self._normalize_whitespace(mail.outbox[0].subject)
        self.assertIn('Proctoring Review In Progress', actual_subject)
        self.assertIn(course_name, actual_subject)

        # Verify the body
        actual_body = self._normalize_whitespace(mail.outbox[0].body)
        self.assertIn('was submitted successfully', actual_body)
        self.assertIn(credit_state['course_name'], actual_body)
Exemplo n.º 3
0
    def test_is_user_course_or_global_staff(self):
        """
        Test that is_user_course_or_global_staff function correctly returns whether
        a user is either global staff or course staff.
        """
        user = User.objects.create(
            email='*****@*****.**',
            username='******'
        )
        course_id = self.attempt['proctored_exam']['course_id']

        # course_staff = true, is_staff = false
        # by default, user.is_staff is false and instructor_service.is_course_staff returns true
        self.assertTrue(is_user_course_or_global_staff(user, course_id))

        # course_staff = true, is_staff = true
        user.is_staff = True
        self.assertTrue(is_user_course_or_global_staff(user, course_id))

        # mock instructor service must be configured to treat users as not course staff.
        set_runtime_service('instructor', MockInstructorService(is_user_course_staff=False))

        # course_staff = false, is_staff = true
        self.assertTrue(is_user_course_or_global_staff(user, course_id))

        # course_staff = false, is_staff = false
        user.is_staff = False
        self.assertFalse(is_user_course_or_global_staff(user, course_id))
Exemplo n.º 4
0
 def ready(self):
     """
     Connect handlers to fetch enrollments.
     """
     if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
         from .services import EnrollmentsService
         set_runtime_service('enrollments', EnrollmentsService())
Exemplo n.º 5
0
def run():
    """
    Executed during django startup
    """
    django_utils_translation.patch()

    autostartup()

    add_mimetypes()

    if settings.FEATURES.get('USE_CUSTOM_THEME', False):
        enable_stanford_theme()

    if settings.FEATURES.get('USE_MICROSITES', False):
        enable_microsites()

    if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False):
        enable_third_party_auth()

    # Initialize Segment analytics module by setting the write_key.
    if settings.LMS_SEGMENT_KEY:
        analytics.write_key = settings.LMS_SEGMENT_KEY

    # register any dependency injections that we need to support in edx_proctoring
    # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit
    # as well as the instructor dashboard (for deleting student attempts)
    if settings.FEATURES.get('ENABLE_PROCTORED_EXAMS'):
        # Import these here to avoid circular dependencies of the form:
        # edx-platform app --> DRF --> django translation --> edx-platform app
        from edx_proctoring.runtime import set_runtime_service
        from instructor.services import InstructorService
        from openedx.core.djangoapps.credit.services import CreditService
        set_runtime_service('credit', CreditService())
        set_runtime_service('instructor', InstructorService())
Exemplo n.º 6
0
 def ready(self):
     """
     Connect services.
     """
     if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
         from edx_name_affirmation.services import NameAffirmationService
         set_runtime_service('name_affirmation', NameAffirmationService())
Exemplo n.º 7
0
    def test_is_user_course_or_global_staff(self):
        """
        Test that is_user_course_or_global_staff function correctly returns whether
        a user is either global staff or course staff.
        """
        user = User.objects.create(
            email='*****@*****.**',
            username='******'
        )
        course_id = self.attempt['proctored_exam']['course_id']

        # course_staff = true, is_staff = false
        # by default, user.is_staff is false and instructor_service.is_course_staff returns true
        self.assertTrue(is_user_course_or_global_staff(user, course_id))

        # course_staff = true, is_staff = true
        user.is_staff = True
        self.assertTrue(is_user_course_or_global_staff(user, course_id))

        # mock instructor service must be configured to treat users as not course staff.
        set_runtime_service('instructor', MockInstructorService(is_user_course_staff=False))

        # course_staff = false, is_staff = true
        self.assertTrue(is_user_course_or_global_staff(user, course_id))

        # course_staff = false, is_staff = false
        user.is_staff = False
        self.assertFalse(is_user_course_or_global_staff(user, course_id))
Exemplo n.º 8
0
def run():
    """
    Executed during django startup
    """
    django_utils_translation.patch()

    autostartup()

    add_mimetypes()

    if settings.FEATURES.get('USE_CUSTOM_THEME', False):
        enable_stanford_theme()

    if settings.FEATURES.get('USE_MICROSITES', False):
        enable_microsites()

    if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False):
        enable_third_party_auth()

    # Initialize Segment analytics module by setting the write_key.
    if settings.LMS_SEGMENT_KEY:
        analytics.write_key = settings.LMS_SEGMENT_KEY

    # register any dependency injections that we need to support in edx_proctoring
    # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit
    # as well as the instructor dashboard (for deleting student attempts)
    if settings.FEATURES.get('ENABLE_PROCTORED_EXAMS'):
        # Import these here to avoid circular dependencies of the form:
        # edx-platform app --> DRF --> django translation --> edx-platform app
        from edx_proctoring.runtime import set_runtime_service
        from instructor.services import InstructorService
        from openedx.core.djangoapps.credit.services import CreditService
        set_runtime_service('credit', CreditService())
        set_runtime_service('instructor', InstructorService())
Exemplo n.º 9
0
    def test_send_email_unicode(self):
        """
        Assert that email can be sent with a unicode course name.
        """

        course_name = u'अआईउऊऋऌ अआईउऊऋऌ'
        set_runtime_service('credit',
                            MockCreditService(course_name=course_name))

        exam_attempt = self._create_started_exam_attempt()
        credit_state = get_runtime_service('credit').get_credit_state(
            self.user_id, self.course_id)
        update_attempt_status(exam_attempt.proctored_exam_id, self.user.id,
                              ProctoredExamStudentAttemptStatus.submitted)
        self.assertEqual(len(mail.outbox), 1)

        # Verify the subject
        actual_subject = self._normalize_whitespace(mail.outbox[0].subject)
        self.assertIn('Proctoring Review In Progress', actual_subject)
        self.assertIn(course_name, actual_subject)

        # Verify the body
        actual_body = self._normalize_whitespace(mail.outbox[0].body)
        self.assertIn('was submitted successfully', actual_body)
        self.assertIn(credit_state['course_name'], actual_body)
Exemplo n.º 10
0
    def test_unicode_attempt(self):
        """
        Tests to make sure we can handle an attempt when a user's fullname has unicode characters in it
        """

        set_runtime_service('credit', MockCreditService(profile_fullname=u'अआईउऊऋऌ अआईउऊऋऌ'))

        exam_id = create_exam(
            course_id='foo/bar/baz',
            content_id='content',
            exam_name='Sample Exam',
            time_limit_mins=10,
            is_proctored=True,
            backend='software_secure',
        )

        with HTTMock(mock_response_content):
            attempt_id = create_exam_attempt(exam_id, self.user.id, taking_as_proctored=True)
            self.assertIsNotNone(attempt_id)

        # try unicode exam name, also
        exam_id = create_exam(
            course_id='foo/bar/baz',
            content_id='content_unicode_name',
            exam_name=u'अआईउऊऋऌ अआईउऊऋऌ',
            time_limit_mins=10,
            is_proctored=True,
            backend='software_secure',
        )

        with HTTMock(mock_response_content):
            attempt_id = create_exam_attempt(exam_id, self.user.id, taking_as_proctored=True)
            self.assertIsNotNone(attempt_id)
Exemplo n.º 11
0
 def tearDown(self):
     """
     When tests are done
     """
     super(ProctoredExamEmailTests, self).tearDown()
     set_runtime_service('grades', None)
     set_runtime_service('certificates', None)
Exemplo n.º 12
0
def run():
    """
    Executed during django startup
    """
    django_utils_translation.patch()

    autostartup()

    add_mimetypes()

    if settings.FEATURES.get('USE_CUSTOM_THEME', False):
        enable_theme()

    if settings.FEATURES.get('USE_MICROSITES', False):
        enable_microsites()

    if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False):
        enable_third_party_auth()

    # Initialize Segment.io analytics module. Flushes first time a message is received and
    # every 50 messages thereafter, or if 10 seconds have passed since last flush
    if settings.FEATURES.get('SEGMENT_IO_LMS') and hasattr(
            settings, 'SEGMENT_IO_LMS_KEY'):
        analytics.init(settings.SEGMENT_IO_LMS_KEY, flush_at=50)

    # register any dependency injections that we need to support in edx_proctoring
    # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit
    # as well as the instructor dashboard (for deleting student attempts)
    if settings.FEATURES.get('ENABLE_PROCTORED_EXAMS'):
        set_runtime_service('credit', CreditService())
        set_runtime_service('instructor', InstructorService())
    def test_unicode_attempt(self):
        """
        Tests to make sure we can handle an attempt when a user's fullname has unicode characters in it
        """

        set_runtime_service("credit", MockCreditService(profile_fullname=u"अआईउऊऋऌ अआईउऊऋऌ"))

        exam_id = create_exam(
            course_id="foo/bar/baz",
            content_id="content",
            exam_name="Sample Exam",
            time_limit_mins=10,
            is_proctored=True,
        )

        with HTTMock(mock_response_content):
            attempt_id = create_exam_attempt(exam_id, self.user.id, taking_as_proctored=True)
            self.assertIsNotNone(attempt_id)

        # try unicode exam name, also
        exam_id = create_exam(
            course_id="foo/bar/baz",
            content_id="content_unicode_name",
            exam_name=u"अआईउऊऋऌ अआईउऊऋऌ",
            time_limit_mins=10,
            is_proctored=True,
        )

        with HTTMock(mock_response_content):
            attempt_id = create_exam_attempt(exam_id, self.user.id, taking_as_proctored=True)
            self.assertIsNotNone(attempt_id)
Exemplo n.º 14
0
 def tearDown(self):
     """
     When tests are done
     """
     super(ProctoredExamEmailTests, self).tearDown()
     set_runtime_service('grades', None)
     set_runtime_service('certificates', None)
Exemplo n.º 15
0
 def tearDown(self):
     """
     When tests are done
     """
     super(SoftwareSecureTests, self).tearDown()
     set_runtime_service('credit', None)
     set_runtime_service('grades', None)
Exemplo n.º 16
0
    def test_unicode_attempt(self):
        """
        Tests to make sure we can handle an attempt when a user's fullname has unicode characters in it
        """

        set_runtime_service('credit', MockCreditService(profile_fullname=u'अआईउऊऋऌ अआईउऊऋऌ'))

        exam_id = create_exam(
            course_id='foo/bar/baz',
            content_id='content',
            exam_name='Sample Exam',
            time_limit_mins=10,
            is_proctored=True,
            backend='software_secure',
        )

        with HTTMock(mock_response_content):
            attempt_id = create_exam_attempt(exam_id, self.user.id, taking_as_proctored=True)
            self.assertIsNotNone(attempt_id)

        # try unicode exam name, also
        exam_id = create_exam(
            course_id='foo/bar/baz',
            content_id='content_unicode_name',
            exam_name=u'अआईउऊऋऌ अआईउऊऋऌ',
            time_limit_mins=10,
            is_proctored=True,
            backend='software_secure',
        )

        with HTTMock(mock_response_content):
            attempt_id = create_exam_attempt(exam_id, self.user.id, taking_as_proctored=True)
            self.assertIsNotNone(attempt_id)
Exemplo n.º 17
0
def run():
    """
    Executed during django startup
    """
    django_db_models_options.patch()

    # To override the settings before executing the autostartup() for python-social-auth
    if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False):
        enable_third_party_auth()

    # Comprehensive theming needs to be set up before django startup,
    # because modifying django template paths after startup has no effect.
    if is_comprehensive_theming_enabled():
        enable_theming()

    # We currently use 2 template rendering engines, mako and django_templates,
    # and one of them (django templates), requires the directories be added
    # before the django.setup().
    microsite.enable_microsites_pre_startup(log)

    django.setup()

    autostartup()

    add_mimetypes()

    # Mako requires the directories to be added after the django setup.
    microsite.enable_microsites(log)

    # Initialize Segment analytics module by setting the write_key.
    if settings.LMS_SEGMENT_KEY:
        analytics.write_key = settings.LMS_SEGMENT_KEY

    # register any dependency injections that we need to support in edx_proctoring
    # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit
    if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
        # Import these here to avoid circular dependencies of the form:
        # edx-platform app --> DRF --> django translation --> edx-platform app
        from edx_proctoring.runtime import set_runtime_service
        from lms.djangoapps.instructor.services import InstructorService
        from openedx.core.djangoapps.credit.services import CreditService
        set_runtime_service('credit', CreditService())

        # register InstructorService (for deleting student attempts and user staff access roles)
        set_runtime_service('instructor', InstructorService())

    # In order to allow modules to use a handler url, we need to
    # monkey-patch the x_module library.
    # TODO: Remove this code when Runtimes are no longer created by modulestores
    # https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes
    xmodule.x_module.descriptor_global_handler_url = lms_xblock.runtime.handler_url
    xmodule.x_module.descriptor_global_local_resource_url = lms_xblock.runtime.local_resource_url

    # Set the version of docs that help-tokens will go to.
    settings.HELP_TOKENS_LANGUAGE_CODE = settings.LANGUAGE_CODE
    settings.HELP_TOKENS_VERSION = doc_version()

    # validate configurations on startup
    validate_lms_config(settings)
Exemplo n.º 18
0
    def setUp(self):
        """
        Initialize
        """
        super(ProctoredExamEmailTests, self).setUp()

        set_runtime_service('grades', MockGradesService())
        set_runtime_service('certificates', MockCertificateService())
Exemplo n.º 19
0
    def ready(self):
        # Register celery workers
        # from .tasks import ls_listen_for_course_publish  # pylint: disable=unused-variable

        if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
            from .services import LearningSequencesRuntimeService
            set_runtime_service('learning_sequences',
                                LearningSequencesRuntimeService())
Exemplo n.º 20
0
    def setUp(self):
        """
        Initialize
        """
        super(ProctoredExamEmailTests, self).setUp()

        set_runtime_service('grades', MockGradesService())
        set_runtime_service('certificates', MockCertificateService())
Exemplo n.º 21
0
 def ready(self):
     """
     Connect services.
     """
     if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
         name_affirmation_service = get_name_affirmation_service()
         if name_affirmation_service:
             set_runtime_service('name_affirmation', name_affirmation_service)
Exemplo n.º 22
0
    def setUp(self):
        """
        Initialize
        """
        super(SoftwareSecureTests, self).setUp()
        self.user = User(username='******', email='*****@*****.**')
        self.user.save()

        set_runtime_service('credit', MockCreditService())
Exemplo n.º 23
0
    def setUp(self):
        """
        Initialize
        """
        super(SoftwareSecureTests, self).setUp()
        self.user = User(username="******", email="*****@*****.**")
        self.user.save()

        set_runtime_service("credit", MockCreditService())
Exemplo n.º 24
0
def run():
    """
    Executed during django startup
    """
    third_party_auth.patch()
    django_db_models_options.patch()

    # To override the settings before executing the autostartup() for python-social-auth
    if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False):
        enable_third_party_auth()

    # Comprehensive theming needs to be set up before django startup,
    # because modifying django template paths after startup has no effect.
    if is_comprehensive_theming_enabled():
        enable_theming()

    # We currently use 2 template rendering engines, mako and django_templates,
    # and one of them (django templates), requires the directories be added
    # before the django.setup().
    microsite.enable_microsites_pre_startup(log)

    django.setup()

    autostartup()

    add_mimetypes()

    # Mako requires the directories to be added after the django setup.
    microsite.enable_microsites(log)

    # Initialize Segment analytics module by setting the write_key.
    if settings.LMS_SEGMENT_KEY:
        analytics.write_key = settings.LMS_SEGMENT_KEY

    # register any dependency injections that we need to support in edx_proctoring
    # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit
    if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
        # Import these here to avoid circular dependencies of the form:
        # edx-platform app --> DRF --> django translation --> edx-platform app
        from edx_proctoring.runtime import set_runtime_service
        from instructor.services import InstructorService
        from openedx.core.djangoapps.credit.services import CreditService
        set_runtime_service('credit', CreditService())

        # register InstructorService (for deleting student attempts and user staff access roles)
        set_runtime_service('instructor', InstructorService())

    # In order to allow modules to use a handler url, we need to
    # monkey-patch the x_module library.
    # TODO: Remove this code when Runtimes are no longer created by modulestores
    # https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes
    xmodule.x_module.descriptor_global_handler_url = lms_xblock.runtime.handler_url
    xmodule.x_module.descriptor_global_local_resource_url = lms_xblock.runtime.local_resource_url

    # validate configurations on startup
    validate_lms_config(settings)
Exemplo n.º 25
0
 def ready(self):
     """
     Connect handlers to signals.
     """
     # Can't import models at module level in AppConfigs, and models get
     # included from the signal handlers
     from . import signals  # pylint: disable=unused-variable
     if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
         from .services import CertificateService
         set_runtime_service('certificates', CertificateService())
Exemplo n.º 26
0
 def ready(self):
     """
     Connect handlers to recalculate grades.
     """
     # Can't import models at module level in AppConfigs, and models get
     # included from the signal handlers
     from .signals import handlers  # pylint: disable=unused-variable
     if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
         from .services import GradesService
         set_runtime_service('grades', GradesService())
Exemplo n.º 27
0
 def ready(self):
     """
     Connect handlers to recalculate grades.
     """
     # Can't import models at module level in AppConfigs, and models get
     # included from the signal handlers
     from .signals import handlers  # pylint: disable=unused-variable
     if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
         from .services import GradesService
         set_runtime_service('grades', GradesService())
Exemplo n.º 28
0
    def test_escalation_email_not_included(self, status):
        """
        Test that verified and rejected emails link to support if an escalation email is
        not given.
        """
        set_runtime_service('instructor', None)

        exam_attempt = self._create_started_exam_attempt()
        update_attempt_status(exam_attempt.id, status)

        actual_body = self._normalize_whitespace(mail.outbox[0].body)
        self.assertIn('support/contact_us', actual_body)
Exemplo n.º 29
0
    def setUp(self):
        super(ReviewTests, self).setUp()
        self.dummy_request = RequestFactory().get('/')
        self.exam_creation_params = {
            'course_id': 'foo/bar/baz',
            'content_id': 'content',
            'exam_name': 'Sample Exam',
            'time_limit_mins': 10,
            'is_proctored': True,
            'backend': 'test'
        }
        self.exam_id = create_exam(**self.exam_creation_params)

        self.attempt_id = create_exam_attempt(
            self.exam_id,
            self.user.id,
            taking_as_proctored=True
        )

        self.attempt = get_exam_attempt_by_id(self.attempt_id)
        set_runtime_service('credit', MockCreditService())
        set_runtime_service('instructor', MockInstructorService())
        set_runtime_service('grades', MockGradesService())
        set_runtime_service('certificates', MockCertificateService())
        set_current_request(self.dummy_request)
Exemplo n.º 30
0
    def setUp(self):
        super(ReviewTests, self).setUp()
        self.dummy_request = RequestFactory().get('/')
        self.exam_creation_params = {
            'course_id': 'foo/bar/baz',
            'content_id': 'content',
            'exam_name': 'Sample Exam',
            'time_limit_mins': 10,
            'is_proctored': True,
            'backend': 'test'
        }
        self.exam_id = create_exam(**self.exam_creation_params)

        self.attempt_id = create_exam_attempt(
            self.exam_id,
            self.user.id,
            taking_as_proctored=True
        )

        self.attempt = get_exam_attempt_by_id(self.attempt_id)
        set_runtime_service('credit', MockCreditService())
        set_runtime_service('instructor', MockInstructorService())
        set_runtime_service('grades', MockGradesService())
        set_runtime_service('certificates', MockCertificateService())
        set_current_request(self.dummy_request)
Exemplo n.º 31
0
def run():
    """
    Executed during django startup
    """
    third_party_auth.patch()

    # To override the settings before executing the autostartup() for python-social-auth
    if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False):
        enable_third_party_auth()

    if settings.FEATURES.get('USE_MICROSITES', False):
        enable_microsites_pre_startup()

    django.setup()

    autostartup()

    add_mimetypes()

    if settings.FEATURES.get('USE_CUSTOM_THEME', False):
        enable_stanford_theme()

    if settings.FEATURES.get('USE_MICROSITES', False):
        enable_microsites()

    # Initialize Segment analytics module by setting the write_key.
    if settings.LMS_SEGMENT_KEY:
        analytics.write_key = settings.LMS_SEGMENT_KEY

    # register any dependency injections that we need to support in edx_proctoring
    # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit
    if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
        # Import these here to avoid circular dependencies of the form:
        # edx-platform app --> DRF --> django translation --> edx-platform app
        from edx_proctoring.runtime import set_runtime_service
        from instructor.services import InstructorService
        from openedx.core.djangoapps.credit.services import CreditService
        set_runtime_service('credit', CreditService())

        # register InstructorService (for deleting student attempts and user staff access roles)
        set_runtime_service('instructor', InstructorService())

    # In order to allow modules to use a handler url, we need to
    # monkey-patch the x_module library.
    # TODO: Remove this code when Runtimes are no longer created by modulestores
    # https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes
    xmodule.x_module.descriptor_global_handler_url = lms_xblock.runtime.handler_url
    xmodule.x_module.descriptor_global_local_resource_url = lms_xblock.runtime.local_resource_url
Exemplo n.º 32
0
def run():
    """
    Executed during django startup
    """
    third_party_auth.patch()

    # To override the settings before executing the autostartup() for python-social-auth
    if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False):
        enable_third_party_auth()

    if settings.FEATURES.get('USE_MICROSITES', False):
        enable_microsites_pre_startup()

    django.setup()

    autostartup()

    add_mimetypes()

    if settings.FEATURES.get('USE_CUSTOM_THEME', False):
        enable_stanford_theme()

    if settings.FEATURES.get('USE_MICROSITES', False):
        enable_microsites()

    # Initialize Segment analytics module by setting the write_key.
    if settings.LMS_SEGMENT_KEY:
        analytics.write_key = settings.LMS_SEGMENT_KEY

    # register any dependency injections that we need to support in edx_proctoring
    # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit
    if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
        # Import these here to avoid circular dependencies of the form:
        # edx-platform app --> DRF --> django translation --> edx-platform app
        from edx_proctoring.runtime import set_runtime_service
        from instructor.services import InstructorService
        from openedx.core.djangoapps.credit.services import CreditService
        set_runtime_service('credit', CreditService())

        # register InstructorService (for deleting student attempts and user staff access roles)
        set_runtime_service('instructor', InstructorService())

    # In order to allow modules to use a handler url, we need to
    # monkey-patch the x_module library.
    # TODO: Remove this code when Runtimes are no longer created by modulestores
    # https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes
    xmodule.x_module.descriptor_global_handler_url = lms_xblock.runtime.handler_url
    xmodule.x_module.descriptor_global_local_resource_url = lms_xblock.runtime.local_resource_url
Exemplo n.º 33
0
 def test_student_response_without_credit_state(self):
     """
     Test that response is not None for users who are not enrolled.
     """
     set_runtime_service('credit', MockCreditServiceNone())
     rendered_response = get_student_view(user_id=self.user_id,
                                          course_id=self.course_id,
                                          content_id=self.content_id,
                                          context={
                                              'is_proctored': True,
                                              'display_name':
                                              self.exam_name,
                                              'default_time_limit_mins': 90
                                          },
                                          user_role='student')
     self.assertIsNotNone(rendered_response)
Exemplo n.º 34
0
 def test_student_response_without_credit_state(self):
     """
     Test that response is not None for users who are not enrolled.
     """
     set_runtime_service('credit', MockCreditServiceNone())
     rendered_response = get_student_view(
         user_id=self.user_id,
         course_id=self.course_id,
         content_id=self.content_id,
         context={
             'is_proctored': True,
             'display_name': self.exam_name,
             'default_time_limit_mins': 90
         },
         user_role='student'
     )
     self.assertIsNotNone(rendered_response)
Exemplo n.º 35
0
    def test_single_name_attempt(self):
        """
        Tests to make sure we can parse a fullname which does not have any spaces in it
        """

        set_runtime_service('credit', MockCreditService())

        exam_id = create_exam(course_id='foo/bar/baz',
                              content_id='content',
                              exam_name='Sample Exam',
                              time_limit_mins=10,
                              is_proctored=True)

        with HTTMock(mock_response_content):
            attempt_id = create_exam_attempt(exam_id,
                                             self.user.id,
                                             taking_as_proctored=True)
            self.assertIsNotNone(attempt_id)
    def setUp(self):
        """
        Build up test data
        """
        super(SetAttemptStatusTests, self).setUp()
        set_runtime_service("credit", MockCreditService())
        self.exam_id = create_exam(course_id="foo", content_id="bar", exam_name="Test Exam", time_limit_mins=90)

        ProctoredExamStudentAttempt.objects.create(
            proctored_exam_id=self.exam_id,
            user_id=self.user.id,
            external_id="foo",
            started_at=datetime.now(pytz.UTC),
            status=ProctoredExamStudentAttemptStatus.started,
            allowed_time_limit_mins=10,
            taking_as_proctored=True,
            is_sample_attempt=False,
        )
    def setup_proctored_exam(self, block, attempt_status, user_id):
        """
        Test helper to configure the given block as a proctored exam.
        """
        exam_id = create_exam(
            course_id=unicode(block.location.course_key),
            content_id=unicode(block.location),
            exam_name='foo',
            time_limit_mins=10,
            is_proctored=True,
            is_practice_exam=block.is_practice_exam,
        )

        set_runtime_service('credit',
                            MockCreditService(enrollment_mode='verified'))

        create_exam_attempt(exam_id, user_id, taking_as_proctored=True)
        update_attempt_status(exam_id, user_id, attempt_status)
    def test_single_name_attempt(self):
        """
        Tests to make sure we can parse a fullname which does not have any spaces in it
        """

        set_runtime_service("credit", MockCreditService())

        exam_id = create_exam(
            course_id="foo/bar/baz",
            content_id="content",
            exam_name="Sample Exam",
            time_limit_mins=10,
            is_proctored=True,
        )

        with HTTMock(mock_response_content):
            attempt_id = create_exam_attempt(exam_id, self.user.id, taking_as_proctored=True)
            self.assertIsNotNone(attempt_id)
Exemplo n.º 39
0
    def setUp(self):
        """
        Initialize
        """
        super(SoftwareSecureTests, self).setUp()
        self.user = User(username='******', email='*****@*****.**')
        self.user.save()

        set_runtime_service('credit', MockCreditService())
        set_runtime_service('instructor', MockInstructorService())
        set_runtime_service('grades', MockGradesService())
        set_runtime_service('certificates', MockCertificateService())
Exemplo n.º 40
0
    def setUp(self):
        """
        Initialize
        """
        super().setUp()
        self.user = User(username='******', email='*****@*****.**')
        self.user.save()

        set_runtime_service('credit', MockCreditService())
        set_runtime_service('instructor', MockInstructorService())
        set_runtime_service('grades', MockGradesService())
        set_runtime_service('certificates', MockCertificateService())
    def setup_proctored_exam(self, block, attempt_status, user_id):
        """
        Test helper to configure the given block as a proctored exam.
        """
        exam_id = create_exam(
            course_id=unicode(block.location.course_key),
            content_id=unicode(block.location),
            exam_name='foo',
            time_limit_mins=10,
            is_proctored=True,
            is_practice_exam=block.is_practice_exam,
        )

        set_runtime_service(
            'credit',
            MockCreditService(enrollment_mode='verified')
        )

        create_exam_attempt(exam_id, user_id, taking_as_proctored=True)
        update_attempt_status(exam_id, user_id, attempt_status)
Exemplo n.º 42
0
    def setUp(self):
        """
        Build up test data
        """
        super(SetAttemptStatusTests, self).setUp()
        set_runtime_service('credit', MockCreditService())
        self.exam_id = create_exam(course_id='foo',
                                   content_id='bar',
                                   exam_name='Test Exam',
                                   time_limit_mins=90)

        ProctoredExamStudentAttempt.objects.create(
            proctored_exam_id=self.exam_id,
            user_id=self.user.id,
            external_id='foo',
            started_at=datetime.now(pytz.UTC),
            status=ProctoredExamStudentAttemptStatus.started,
            allowed_time_limit_mins=10,
            taking_as_proctored=True,
            is_sample_attempt=False)
Exemplo n.º 43
0
    def test_full_name_without_credit_service(self):
        """
        Tests to make sure split doesn't raises AttributeError if credit service is down.
        """

        set_runtime_service('credit', MockCreditServiceNone())

        exam_id = create_exam(
            course_id='foo/bar/baz',
            content_id='content',
            exam_name='Sample Exam',
            time_limit_mins=10,
            is_proctored=True,
            backend='software_secure',
        )

        with HTTMock(mock_response_content):
            attempt_id = create_exam_attempt(exam_id,
                                             self.user.id,
                                             taking_as_proctored=True)
            self.assertIsNotNone(attempt_id)
Exemplo n.º 44
0
    def test_practice_exam_passed_end_date(self):
        """
        Verify that we get a None back on a practice exam
        if the course end date is passed
        """

        set_runtime_service('credit', MockCreditServiceWithCourseEndDate())

        rendered_response = get_student_view(user_id=self.user_id,
                                             course_id='foo',
                                             content_id='bar',
                                             context={
                                                 'is_proctored': True,
                                                 'is_practice_exam': True,
                                                 'display_name':
                                                 self.exam_name,
                                                 'default_time_limit_mins': 90,
                                                 'due_date': None,
                                                 'hide_after_due': False,
                                             },
                                             user_role='student')
        self.assertIsNone(rendered_response)
Exemplo n.º 45
0
 def tearDown(self):
     """
     When tests are done
     """
     super().tearDown()
     set_runtime_service('credit', None)
     set_runtime_service('grades', None)
     set_runtime_service('certificates', None)
Exemplo n.º 46
0
 def tearDown(self):
     """
     When tests are done
     """
     super(SoftwareSecureTests, self).tearDown()
     set_runtime_service('credit', None)
     set_runtime_service('grades', None)
     set_runtime_service('certificates', None)
Exemplo n.º 47
0
    def test_send_email_unicode(self):
        """
        Assert that email can be sent with a unicode course name.
        """

        course_name = u'अआईउऊऋऌ अआईउऊऋऌ'
        set_runtime_service('credit',
                            MockCreditService(course_name=course_name))

        exam_attempt = self._create_started_exam_attempt()
        credit_state = get_runtime_service('credit').get_credit_state(
            self.user_id, self.course_id)
        update_attempt_status(exam_attempt.proctored_exam_id, self.user.id,
                              ProctoredExamStudentAttemptStatus.submitted)
        self.assertEquals(len(mail.outbox), 1)
        self.assertIn(self.proctored_exam_email_subject,
                      mail.outbox[0].subject)
        self.assertIn(course_name, mail.outbox[0].subject)
        self.assertIn(self.proctored_exam_email_body, mail.outbox[0].body)
        self.assertIn(
            ProctoredExamStudentAttemptStatus.get_status_alias(
                ProctoredExamStudentAttemptStatus.submitted),
            mail.outbox[0].body)
        self.assertIn(credit_state['course_name'], mail.outbox[0].body)
Exemplo n.º 48
0
 def setUp(self):
     """
     Initialize
     """
     super().setUp()
     self.proctored_exam_id = self._create_proctored_exam()
     self.timed_exam_id = self._create_timed_exam()
     set_runtime_service('grades', MockGradesService())
     set_runtime_service('certificates', MockCertificateService())
     set_runtime_service('instructor', MockInstructorService())
Exemplo n.º 49
0
def run():
    """
    Executed during django startup

    NOTE: DO **NOT** add additional code to this method or this file! The Platform Team
          is moving all startup code to more standard locations using Django best practices.
    """
    django_db_models_options.patch()

    # We currently use 2 template rendering engines, mako and django_templates,
    # and one of them (django templates), requires the directories be added
    # before the django.setup().
    microsite.enable_microsites_pre_startup(log)

    django.setup()

    autostartup()

    add_mimetypes()

    # Mako requires the directories to be added after the django setup.
    microsite.enable_microsites(log)

    # register any dependency injections that we need to support in edx_proctoring
    # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit and
    # lms.djangoapps.grades
    if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
        # Import these here to avoid circular dependencies of the form:
        # edx-platform app --> DRF --> django translation --> edx-platform app
        from edx_proctoring.runtime import set_runtime_service
        from lms.djangoapps.instructor.services import InstructorService
        from openedx.core.djangoapps.credit.services import CreditService
        from lms.djangoapps.grades.services import GradesService
        set_runtime_service('credit', CreditService())

        # register InstructorService (for deleting student attempts and user staff access roles)
        set_runtime_service('instructor', InstructorService())

        set_runtime_service('grades', GradesService())

    # In order to allow modules to use a handler url, we need to
    # monkey-patch the x_module library.
    # TODO: Remove this code when Runtimes are no longer created by modulestores
    # https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes
    xmodule.x_module.descriptor_global_handler_url = lms_xblock.runtime.handler_url
    xmodule.x_module.descriptor_global_local_resource_url = lms_xblock.runtime.local_resource_url

    # Set the version of docs that help-tokens will go to.
    settings.HELP_TOKENS_LANGUAGE_CODE = settings.LANGUAGE_CODE
    settings.HELP_TOKENS_VERSION = doc_version()

    # validate configurations on startup
    validate_lms_config(settings)
Exemplo n.º 50
0
    def setUp(self):
        """
        Build up test data
        """
        super(SetAttemptStatusTests, self).setUp()
        set_runtime_service('credit', MockCreditService())
        set_runtime_service('grades', MockGradesService())
        set_runtime_service('certificates', MockCertificateService())
        self.exam_id = create_exam(
            course_id='foo',
            content_id='bar',
            exam_name='Test Exam',
            time_limit_mins=90)

        ProctoredExamStudentAttempt.objects.create(
            proctored_exam_id=self.exam_id,
            user_id=self.user.id,
            external_id='foo',
            started_at=datetime.now(pytz.UTC),
            status=ProctoredExamStudentAttemptStatus.started,
            allowed_time_limit_mins=10,
            taking_as_proctored=True,
            is_sample_attempt=False)
Exemplo n.º 51
0
 def ready(self):
     if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
         from .services import InstructorService
         set_runtime_service('instructor', InstructorService())
Exemplo n.º 52
0
    def setUp(self):
        """
        Build out test harnessing
        """
        super(ProctoredExamTestCase, self).setUp()
        self.default_time_limit = 21
        self.course_id = 'a/b/c'
        self.content_id_for_exam_with_due_date = 'test_content_due_date_id'
        self.content_id = 'test_content_id'
        self.content_id_timed = 'test_content_id_timed'
        self.content_id_practice = 'test_content_id_practice'
        self.content_id_onboarding = 'test_content_id_onboarding'
        self.disabled_content_id = 'test_disabled_content_id'
        self.exam_name = 'Test Exam'
        self.user_id = self.user.id
        self.key = 'additional_time_granted'
        self.value = '10'
        self.external_id = 'test_external_id'
        self.proctored_exam_id = self._create_proctored_exam()
        self.timed_exam_id = self._create_timed_exam()
        self.practice_exam_id = self._create_practice_exam()
        self.onboarding_exam_id = self._create_onboarding_exam()
        self.disabled_exam_id = self._create_disabled_exam()

        set_runtime_service('credit', MockCreditService())
        set_runtime_service('instructor', MockInstructorService(is_user_course_staff=True))

        tracker.register_tracker(MockTracker())

        self.prerequisites = [
            {
                'namespace': 'proctoring',
                'name': 'proc1',
                'order': 2,
                'status': 'satisfied',
            },
            {
                'namespace': 'reverification',
                'name': 'rever1',
                'order': 1,
                'status': 'satisfied',
            },
            {
                'namespace': 'grade',
                'name': 'grade1',
                'order': 0,
                'status': 'pending',
            },
            {
                'namespace': 'reverification',
                'name': 'rever2',
                'order': 3,
                'status': 'failed',
            },
            {
                'namespace': 'proctoring',
                'name': 'proc2',
                'order': 4,
                'status': 'pending',
            },
        ]

        self.declined_prerequisites = [
            {
                'namespace': 'proctoring',
                'name': 'proc1',
                'order': 2,
                'status': 'satisfied',
            },
            {
                'namespace': 'reverification',
                'name': 'rever1',
                'order': 1,
                'status': 'satisfied',
            },
            {
                'namespace': 'grade',
                'name': 'grade1',
                'order': 0,
                'status': 'pending',
            },
            {
                'namespace': 'reverification',
                'name': 'rever2',
                'order': 3,
                'status': 'declined',
            },
            {
                'namespace': 'proctoring',
                'name': 'proc2',
                'order': 4,
                'status': 'pending',
            },
        ]
Exemplo n.º 53
0
 def tearDown(self):
     super(ReviewTests, self).tearDown()
     set_runtime_service('credit', None)
     set_runtime_service('grades', None)
     set_runtime_service('certificates', None)
Exemplo n.º 54
0
 def ready(self):
     from . import signals
     if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
         from .services import CreditService
         set_runtime_service('credit', CreditService())
 def tearDown(self):
     """
     When tests are done
     """
     set_runtime_service("credit", None)