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)
def test_clean_roles_course_matched(self): course1_role = factories.ParticipationRoleFactory(course=self.course1) data = { "user": self.test_user.pk, "course": self.course1.pk, "status": constants.participation_status.active, "enroll_time": now(), "time_factor": 1, "roles": [course1_role] } form = admin.ParticipationForm(data=data) self.assertTrue(form.is_valid())
def test_clean_roles_course_not_match(self): course1_role = factories.ParticipationRoleFactory(course=self.course1) data = { "user": self.test_user.pk, "course": self.course2.pk, "status": constants.participation_status.active, "enroll_time": now(), "time_factor": 1, "roles": [course1_role] } form = admin.ParticipationForm(data=data) self.assertFalse(form.is_valid()) expected_error_msg = "Role must belong to same course as participation." self.assertIn(expected_error_msg, str(form.errors))
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())
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"))
def test_unicode(self): tag1 = factories.ParticipationRoleFactory(course=self.course, identifier="ta") tag2 = factories.ParticipationRoleFactory(course=self.course, identifier="stu") self.assertNotEqual(str(tag1), str(tag2))