Beispiel #1
0
    def test_update_course_exist_requested_preapproved_instid(self):
        user1 = factories.UserFactory(email="", institutional_id="1234")
        factories.ParticipationFactory(course=self.course,
                                       user=user1,
                                       status=participation_status.requested)

        factories.ParticipationPreapprovalFactory(course=self.course,
                                                  institutional_id="4321")

        user2 = factories.UserFactory(email="", institutional_id="2345")
        factories.ParticipationFactory(course=self.course,
                                       user=user2,
                                       status=participation_status.requested)

        factories.ParticipationPreapprovalFactory(course=self.course,
                                                  institutional_id="2345")

        with mock.patch(HANDLE_ENROLLMENT_PATH) as mock_handle_enrollment:
            mock_handle_enrollment.return_value = None

            self.course.listed = not self.course.listed
            self.course.save()
            self.assertEqual(mock_handle_enrollment.call_count, 0)

            self.course.preapproval_require_verified_inst_id = False
            self.course.save()
            self.assertEqual(mock_handle_enrollment.call_count, 1)

            mock_handle_enrollment.reset_mock()

            user1.institutional_id = "4321"
            user1.save()
            self.assertEqual(mock_handle_enrollment.call_count, 1)
Beispiel #2
0
    def setUp(self):
        super(ExamTicketTest, self).setUp()
        self.exam = factories.ExamFactory(course=self.course)

        self.user1 = factories.UserFactory()
        self.participation1 = factories.ParticipationFactory(
            course=self.course, user=self.user1)
        self.user2 = factories.UserFactory()
        self.participation2 = factories.ParticipationFactory(
            course=self.course, user=self.user2)
Beispiel #3
0
    def test_unicode(self):
        course2 = factories.CourseFactory(identifier="another-course")
        user = factories.UserFactory()

        participation1 = factories.ParticipationFactory(course=self.course,
                                                        user=user)
        participation2 = factories.ParticipationFactory(course=course2,
                                                        user=user)

        self.assertNotEqual(str(participation1), str(participation2))
Beispiel #4
0
 def test_post_success(self):
     factories.ParticipationFactory(course=self.course)
     factories.ParticipationFactory(
         course=self.course, status=constants.participation_status.dropped)
     resp = self.post_batch_issue_exam_ticket_view(
         data=self.get_post_data())
     self.assertEqual(resp.status_code, 200)
     self.assertFormErrorLoose(resp, None)
     self.assertEqual(ExamTicket.objects.count(), 4)
     self.assertAddMessageCallCount(1)
     self.assertAddMessageCalledWith("4 tickets issued.")
Beispiel #5
0
    def test_unicode(self):
        participation1 = factories.ParticipationFactory(
            course=self.course, user=factories.UserFactory())

        participation2 = factories.ParticipationFactory(
            course=self.course, user=factories.UserFactory())

        token1 = factories.AuthenticationTokenFactory(
            participation=participation1)

        token2 = factories.AuthenticationTokenFactory(
            participation=participation2)

        self.assertNotEqual(str(token1), str(token2))
Beispiel #6
0
 def setUp(self):
     super(FlowPageVisitGradeTest, self).setUp()
     self.user = factories.UserFactory()
     self.participation = factories.ParticipationFactory(course=self.course,
                                                         user=self.user)
     fs = factories.FlowSessionFactory(participation=self.participation)
     self.fpdata = factories.FlowPageDataFactory(flow_session=fs)
Beispiel #7
0
    def setUpTestData(cls):  # noqa
        super(FlowAnalyticsTest, cls).setUpTestData()
        cls.course.active_git_commit_sha = "my_fake_commit_sha_for_flow_analytics"
        cls.course.save()
        cls.start_flow(cls.flow_id)
        fs = FlowSession.objects.last()
        for page_ordinal in range(fs.page_count):
            cls.submit_page_answer_by_ordinal_and_test(
                page_ordinal=page_ordinal,
                do_grading=False,
                do_human_grade=False)
        cls.end_flow()

        # start another in-progress session with answers
        cls.start_flow(cls.flow_id)
        fs = FlowSession.objects.last()
        for page_ordinal in range(fs.page_count):
            cls.submit_page_answer_by_ordinal_and_test(
                page_ordinal=page_ordinal,
                do_grading=False,
                do_human_grade=False)

        # start another ended session with out answers
        cls.start_flow(cls.flow_id)
        cls.end_flow()

        # create another participation and with a flow session
        another_partcpt = factories.ParticipationFactory(course=cls.course)
        with cls.temporarily_switch_to_user(another_partcpt.user):
            cls.start_flow(cls.flow_id)
            cls.end_flow()
Beispiel #8
0
    def setUp(self):
        super(FlowRuleExceptionTest, self).setUp()
        user = factories.UserFactory()
        self.participation = factories.ParticipationFactory(course=self.course,
                                                            user=user)
        fake_get_course_repo = mock.patch("course.content.get_course_repo")
        self.mock_get_course_repo = fake_get_course_repo.start()
        self.mock_get_course_repo.return_value = mock.MagicMock()
        self.addCleanup(fake_get_course_repo.stop)

        fake_get_flow_desc = mock.patch("course.content.get_flow_desc")
        self.mock_get_flow_desc = fake_get_flow_desc.start()
        self.addCleanup(fake_get_flow_desc.stop)

        fake_validate_session_start_rule = mock.patch(
            "course.validation.validate_session_start_rule")
        self.mock_validate_session_start_rule = (
            fake_validate_session_start_rule.start())
        self.addCleanup(fake_validate_session_start_rule.stop)

        fake_validate_session_access_rule = mock.patch(
            "course.validation.validate_session_access_rule")
        self.mock_validate_session_access_rule = (
            fake_validate_session_access_rule.start())
        self.addCleanup(fake_validate_session_access_rule.stop)

        fake_validate_session_grading_rule = mock.patch(
            "course.validation.validate_session_grading_rule")
        self.mock_validate_session_grading_rule = (
            fake_validate_session_grading_rule.start())
        self.addCleanup(fake_validate_session_grading_rule.stop)
Beispiel #9
0
    def test_deny_enrollment(self):
        active = factories.ParticipationFactory(
            course=self.course1, status=constants.participation_status.active)
        (requested1, requested2) = factories.ParticipationFactory.create_batch(
            size=2,
            course=self.course1,
            status=constants.participation_status.requested)

        from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
        action_data = {
            ACTION_CHECKBOX_NAME: [active.pk, requested1.pk, requested2.pk],
            'action': "deny_enrollment",
            'index': 0,
        }
        with self.temporarily_switch_to_user(self.instructor1):
            resp = self.c.post(
                self.get_admin_course_change_list_view_url(
                    models.Participation.__name__), action_data)
            self.assertEqual(resp.status_code, 302)

        active.refresh_from_db()
        self.assertEqual(active.status, constants.participation_status.active)
        requested1.refresh_from_db()
        self.assertEqual(requested1.status,
                         constants.participation_status.denied)
        requested2.refresh_from_db()
        self.assertEqual(requested2.status,
                         constants.participation_status.denied)
Beispiel #10
0
    def test_not_found_across_course(self):
        # This ensure course is filtered
        another_participation = factories.ParticipationFactory(
            course=factories.CourseFactory(identifier="another-course"))

        with self.assertRaises(grades.ParticipantNotFound):
            grades.find_participant_from_id(self.course,
                                            another_participation.user.email)
Beispiel #11
0
    def setUp(self):
        super(RunCourseUpdateCommandTest, self).setUp()
        self.course = factories.CourseFactory(
            active_git_commit_sha=self.default_old_sha)
        user = factories.UserFactory()
        instructor_role = factories.ParticipationRoleFactory(
            course=self.course,
            identifier="instructor"
        )

        self.participation = factories.ParticipationFactory(
            course=self.course,
            preview_git_commit_sha=None,
            user=user)
        self.participation.roles.set([instructor_role])

        self.request = mock.MagicMock()
        self.request.user = user

        self.pctx = mock.MagicMock()
        self.pctx.course = self.course
        self.pctx.participation = self.participation

        self.repo = mock.MagicMock()
        self.content_repo = self.repo

        fake_get_dulwich_client_and_remote_path_from_course = mock.patch(
            "course.versioning.get_dulwich_client_and_remote_path_from_course")
        self.mock_get_dulwich_client_and_remote_path_from_course = (
            fake_get_dulwich_client_and_remote_path_from_course.start()
        )

        self.mock_client = mock.MagicMock()
        remote_path = "/remote/path"
        self.mock_get_dulwich_client_and_remote_path_from_course.return_value = (
            self.mock_client, remote_path
        )
        self.mock_client.fetch.return_value = {
            b"HEAD": self.default_switch_to_sha.encode()}

        self.addCleanup(fake_get_dulwich_client_and_remote_path_from_course.stop)

        fake_transfer_remote_refs = mock.patch(
            "course.versioning.transfer_remote_refs")
        self.mock_transfer_remote_refs = fake_transfer_remote_refs.start()
        self.addCleanup(fake_transfer_remote_refs.stop)

        fake_is_parent_commit = mock.patch("course.versioning.is_parent_commit")
        self.mock_is_parent_commit = fake_is_parent_commit.start()
        self.mock_is_parent_commit.return_value = False
        self.addCleanup(fake_is_parent_commit.stop)

        fake_validate_course_content = mock.patch(
            "course.validation.validate_course_content")
        self.mock_validate_course_content = fake_validate_course_content.start()
        self.mock_validate_course_content.return_value = []
        self.addCleanup(fake_validate_course_content.stop)
Beispiel #12
0
    def test_get_role_desc(self):
        course2 = factories.CourseFactory(identifier="another-course")
        user = factories.UserFactory()

        participation1 = factories.ParticipationFactory(course=self.course,
                                                        user=user)
        participation2 = factories.ParticipationFactory(course=course2,
                                                        user=user)

        self.assertIsInstance(participation1.get_role_desc(), six.text_type)
        self.assertEqual(participation1.get_role_desc(),
                         participation2.get_role_desc())

        instructor_role = factories.ParticipationRoleFactory(
            course=self.course, identifier="instructor")
        participation2.roles.set([instructor_role])
        self.assertNotEqual(participation1.get_role_desc(),
                            participation2.get_role_desc())
Beispiel #13
0
    def test_unicode(self):
        user = factories.UserFactory()
        participation = factories.ParticipationFactory(course=self.course,
                                                       user=user)
        im1 = factories.InstantMessageFactory(participation=participation,
                                              text="my message")
        im2 = factories.InstantMessageFactory(participation=participation,
                                              text="my message2")

        self.assertNotEqual(str(im1), str(im2))
Beispiel #14
0
    def test_skip_not_active(self):
        dropped_participation = factories.ParticipationFactory(
            course=self.course, status=constants.participation_status.dropped)

        with self.assertRaises(grades.ParticipantNotFound) as cm:
            grades.find_participant_from_id(self.course,
                                            dropped_participation.user.email)
        expected_error_msg = ("no participant found for '%s'" %
                              dropped_participation.user.email)
        self.assertIn(expected_error_msg, str(cm.exception))
Beispiel #15
0
 def setUp(self):
     super(GradingChangeTest, self).setUp()
     self.user = factories.UserFactory()
     self.participation = factories.ParticipationFactory(course=self.course,
                                                         user=self.user)
     self.flow_session = factories.FlowSessionFactory(
         participation=self.participation)
     self.opportunity1 = factories.GradingOpportunityFactory(
         course=self.course, identifier="gopp1")
     self.opportunity2 = factories.GradingOpportunityFactory(
         course=self.course, identifier="gopp2")
Beispiel #16
0
    def test_has_permission(self):
        user = factories.UserFactory()
        participation = factories.ParticipationFactory(course=self.course,
                                                       user=user)

        self.assertTrue(
            participation.has_permission(pperm.access_files_for, "unenrolled"))
        self.assertFalse(participation.has_permission(pperm.view_gradebook))

        instructor = factories.UserFactory()
        instructor_role = factories.ParticipationRoleFactory(
            course=self.course, identifier="instructor")
        instructor_participation = factories.ParticipationFactory(
            course=self.course, user=instructor)
        instructor_participation.roles.set([instructor_role])

        self.assertTrue(
            participation.has_permission(pperm.access_files_for, "unenrolled"))
        self.assertTrue(
            participation.has_permission(pperm.access_files_for, "student"))
Beispiel #17
0
    def test_update_course_exist_requested_not_preapprove(self):
        user = factories.UserFactory()
        factories.ParticipationFactory(course=self.course,
                                       user=user,
                                       status=participation_status.requested)

        with mock.patch(HANDLE_ENROLLMENT_PATH) as mock_handle_enrollment:
            mock_handle_enrollment.return_value = None

            self.course.listed = not self.course.listed
            self.course.save()
            self.assertEqual(mock_handle_enrollment.call_count, 0)
Beispiel #18
0
    def test_not_found_across_course(self):
        # This ensure course is filtered
        another_participation = factories.ParticipationFactory(
            course=factories.CourseFactory(identifier="another-course"))

        with self.assertRaises(grades.ParticipantNotFound) as cm:
            grades.find_participant_from_user_attr(
                self.course, "username", another_participation.user.username)

            expected_error_msg = ("no participant found with username '%s'" %
                                  another_participation.user.username)
            self.assertIn(expected_error_msg, str(cm.exception))
Beispiel #19
0
    def test_fail_course_not_matched(self):
        another_course = factories.CourseFactory(identifier="another-course")
        another_course_fs = factories.FlowSessionFactory(
            participation=factories.ParticipationFactory(
                course=another_course))

        token = self.create_token()

        resp = self.c.get(self.get_get_flow_session_content_url(
            flow_session_id=another_course_fs.id),
                          HTTP_AUTHORIZATION="Token %i_%s" %
                          (token.id, self.default_token_hash_str))
        self.assertEqual(resp.status_code, 403)
Beispiel #20
0
    def test_clean_failure(self):
        course2 = factories.CourseFactory(identifier="another-course")
        participation3 = factories.ParticipationFactory(course=course2,
                                                        user=self.user2)

        et2 = models.ExamTicket(exam=self.exam,
                                participation=participation3,
                                code="cdef")

        with self.assertRaises(ValidationError) as cm:
            et2.clean()

        expected_error_msg = ("Participation and exam must live "
                              "in the same course")
        self.assertIn(expected_error_msg, str(cm.exception))
Beispiel #21
0
    def test_multiple_found(self):
        exist_inst_id = self.student_participation.user.institutional_id
        another_student_participation = factories.ParticipationFactory(
            course=self.course,
            user=factories.UserFactory(institutional_id=exist_inst_id.upper()))

        with self.assertRaises(grades.ParticipantNotFound) as cm:
            grades.find_participant_from_user_attr(
                self.course, "institutional_id",
                another_student_participation.user.institutional_id)

        expected_error_msg = (
            "more than one participant found with Institutional ID '%s'" %
            another_student_participation.user.institutional_id)
        self.assertIn(expected_error_msg, str(cm.exception))
Beispiel #22
0
 def test_update_course_user_not_active(self):
     user = factories.UserFactory(is_active=False)
     factories.ParticipationFactory(course=self.course,
                                    user=user,
                                    status=participation_status.requested)
     factories.ParticipationPreapprovalFactory(course=self.course,
                                               email=user.email)
     with mock.patch(
             "course.models.ParticipationPreapproval.objects.get")\
             as mock_pprvl_get,\
             mock.patch(HANDLE_ENROLLMENT_PATH) as mock_handle_enrollment:
         self.course.listed = not self.course.listed
         self.course.save()
         self.assertEqual(mock_pprvl_get.call_count, 0)
         self.assertEqual(mock_handle_enrollment.call_count, 0)
Beispiel #23
0
    def test_found_multiple(self):
        email = self.student_participation.user.email
        at_index = email.index("@")
        uid = email[:at_index]

        # create another participation with the same uid
        factories.ParticipationFactory(
            course=self.course,
            user=factories.UserFactory(email="*****@*****.**" % uid.upper()))

        with self.assertRaises(grades.ParticipantNotFound) as cm:
            grades.find_participant_from_id(self.course, uid)

        expected_error_msg = "more than one participant found for '%s'" % uid
        self.assertIn(expected_error_msg, str(cm.exception))
Beispiel #24
0
    def test_permission_cached(self):
        user = factories.UserFactory()
        participation = factories.ParticipationFactory(course=self.course,
                                                       user=user)

        self.assertTrue(
            participation.has_permission(pperm.access_files_for, "unenrolled"))

        with mock.patch(
                "course.models.ParticipationRolePermission.objects.filter"
        ) as mock_filter:
            self.assertFalse(participation.has_permission(
                pperm.view_gradebook))

            self.assertEqual(
                mock_filter.call_count, 0,
                "participation permissions is expected to be cached.")
Beispiel #25
0
    def test_flow_session_course_not_matching(self):
        another_course = factories.CourseFactory(identifier="another-course")
        some_user = factories.UserFactory()
        his_participation = factories.ParticipationFactory(
            course=another_course, user=some_user)
        his_flow_session = factories.FlowSessionFactory(
            course=another_course, participation=his_participation)

        url = self.get_page_grading_url_by_ordinal(
            page_ordinal=1,
            course_identifier=self.course.identifier,
            flow_session_id=his_flow_session.pk)

        with self.temporarily_switch_to_user(
                self.instructor_participation.user):
            resp = self.c.get(url)
            self.assertEqual(resp.status_code, 400)
Beispiel #26
0
    def test_no_perm_to_post_grade(self):
        some_user = factories.UserFactory()
        his_participation = factories.ParticipationFactory(user=some_user,
                                                           course=self.course)
        from course.models import ParticipationPermission
        pp = ParticipationPermission(participation=his_participation,
                                     permission=pperm.view_gradebook)
        pp.save()
        his_participation.individual_permissions.set([pp])
        with self.temporarily_switch_to_user(some_user):
            resp = self.c.get(
                self.get_page_grading_url_by_page_id(self.page_id))
            self.assertEqual(resp.status_code, 200)

            grade_data = {"grade_points": "4", "released": "on"}
            resp = self.post_grade_by_page_id(self.page_id,
                                              grade_data,
                                              force_login_instructor=False)
            self.assertEqual(resp.status_code, 403)
Beispiel #27
0
    def test_result(self):
        flow_ids = ["c", "b", "a"]

        for flow_id in flow_ids:
            factories.FlowSessionFactory.create_batch(
                size=2,
                participation=self.student_participation,
                flow_id=flow_id)

        another_course = factories.CourseFactory(identifier="another-course")
        another_participation = factories.ParticipationFactory(
            course=another_course)

        # This make sure other courses' flow_id won't be included
        factories.FlowSessionFactory(participation=another_participation,
                                     flow_id="d")

        resp = self.get_flow_list_view()
        self.assertEqual(resp.status_code, 200)

        self.assertResponseContextEqual(resp, "flow_ids", sorted(flow_ids))
Beispiel #28
0
 def setUp(self):
     super(FlowPageDataTest, self).setUp()
     self.user = factories.UserFactory()
     self.participation = factories.ParticipationFactory(course=self.course,
                                                         user=self.user)
Beispiel #29
0
    def test_course_not_none_check_attributes_yml(self):
        # This test check_attributes_yml args access_type
        # is generated with course-specific pperm.access_files_for

        user = factories.UserFactory()

        # {{{ create another course with different set of participation role
        # permission and participation permission

        another_course = factories.CourseFactory(identifier="another-course")
        another_course_prole = ParticipationRole(
            course=another_course,
            identifier="another_course_role",
            name="another_course_role")
        another_course_prole.save()

        another_course_participation = factories.ParticipationFactory(
            course=another_course, user=user)
        another_course_participation.roles.set([another_course_prole])

        another_course_ppm_access_files_for_roles = "another_role"
        ParticipationPermission(
            participation=another_course_participation,
            permission=pperm.access_files_for,
            argument=another_course_ppm_access_files_for_roles).save()

        another_course_rpm_access_files_for_roles = "another_course_everyone"
        ParticipationRolePermission(
            role=another_course_prole,
            permission=pperm.access_files_for,
            argument=another_course_rpm_access_files_for_roles).save()

        self.assertTrue(
            another_course_participation.has_permission(
                pperm.access_files_for,
                argument=another_course_ppm_access_files_for_roles))

        self.assertTrue(
            another_course_participation.has_permission(
                pperm.access_files_for,
                argument=another_course_rpm_access_files_for_roles))
        # }}}

        # {{{ create for default test course extra participation role
        # permission and participation permission

        this_course_prole = ParticipationRole(course=self.course,
                                              identifier="another_course_role",
                                              name="another_course_role")
        this_course_prole.save()

        this_course_participation = factories.ParticipationFactory(
            course=self.course, user=user)
        this_course_participation.roles.set([this_course_prole])

        this_course_ppm_access_files_for_roles = "this_course_some_role"
        ParticipationPermission(
            participation=this_course_participation,
            permission=pperm.access_files_for,
            argument=this_course_ppm_access_files_for_roles).save()

        this_course_rpm_access_files_for_roles = "this_course_everyone"
        ParticipationRolePermission(
            role=this_course_prole,
            permission=pperm.access_files_for,
            argument=this_course_rpm_access_files_for_roles).save()

        self.assertTrue(
            this_course_participation.has_permission(
                pperm.access_files_for,
                argument=this_course_ppm_access_files_for_roles))

        self.assertTrue(
            this_course_participation.has_permission(
                pperm.access_files_for,
                argument=this_course_rpm_access_files_for_roles))
        # }}}

        validation.validate_course_content(self.repo,
                                           course_file,
                                           events_file,
                                           validate_sha,
                                           course=self.course)
        self.assertEqual(self.mock_vctx_add_warning.call_count, 0)

        # check_attributes_yml is called
        self.assertEqual(self.mock_check_attributes_yml.call_count, 1)

        access_kinds = list(self.mock_check_attributes_yml.call_args[0][-1])

        self.assertIn(this_course_ppm_access_files_for_roles, access_kinds)
        self.assertIn(this_course_rpm_access_files_for_roles, access_kinds)

        self.assertNotIn(another_course_ppm_access_files_for_roles,
                         access_kinds)
        self.assertNotIn(another_course_rpm_access_files_for_roles,
                         access_kinds)
Beispiel #30
0
 def setUpTestData(cls):  # noqa
     super(FindParticipantFromUserAttrTest, cls).setUpTestData()
     cls.course = factories.CourseFactory()
     cls.student_participation = factories.ParticipationFactory(
         course=cls.course)