Newer
Older
versioning._get_commit_message_as_html(repo, commit_sha_2),
expected_msg)
expected_msg = "abc\\uDC80"
self.assertEqual(
versioning._get_commit_message_as_html(repo, commit_sha_3),
expected_msg)
class UpdateCourseTest(SingleCourseTestMixin, MockAddMessageMixing, TestCase):
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
def test_no_permission(self):
with self.temporarily_switch_to_user(self.student_participation.user):
resp = self.c.get(self.get_update_course_url())
self.assertEqual(resp.status_code, 403)
for command in versioning.ALLOWED_COURSE_REVISIOIN_COMMANDS:
resp = self.post_update_course_content(
"some_commit_sha", command=command,
force_login_instructor=False)
self.assertEqual(resp.status_code, 403)
def test_participation_with_preview_permission(self):
# Just to make sure it won't fail, Todo: assersion on form kwargs
from course.models import ParticipationPermission
pp = ParticipationPermission(
participation=self.student_participation,
permission=pperm.preview_content)
pp.save()
self.student_participation.individual_permissions.set([pp])
with self.temporarily_switch_to_user(self.student_participation.user):
for command in versioning.ALLOWED_COURSE_REVISIOIN_COMMANDS:
resp = self.post_update_course_content(
"some_commit_sha", command=command,
force_login_instructor=False)
self.assertEqual(resp.status_code, 200, command)
def test_participation_with_update_permission(self):
# Just to make sure it won't fail, Todo: assersion on form kwargs
from course.models import ParticipationPermission
pp = ParticipationPermission(
participation=self.student_participation,
permission=pperm.update_content)
pp.save()
self.student_participation.individual_permissions.set([pp])
with self.temporarily_switch_to_user(self.student_participation.user):
for command in versioning.ALLOWED_COURSE_REVISIOIN_COMMANDS:
resp = self.post_update_course_content(
"some_commit_sha", command=command,
force_login_instructor=False)
self.assertEqual(resp.status_code, 200, command)
def test_get(self):
with self.temporarily_switch_to_user(self.instructor_participation.user):
resp = self.c.get(self.get_update_course_url())
self.assertEqual(resp.status_code, 200)
def test_unknown_command(self):
resp = self.post_update_course_content(
"some_commit_sha", command="unknown")
self.assertEqual(resp.status_code, 400)
@suppress_stdout_decorator(suppress_stderr=True)
def test_run_course_update_command_failure(self):
with mock.patch(
"course.versioning.run_course_update_command"
) as mock_run_update:
error_msg = "my runtime error"
mock_run_update.side_effect = RuntimeError(error_msg)
resp = self.post_update_course_content(
self.course.active_git_commit_sha, command="update")
self.assertEqual(resp.status_code, 200)
expected_error_msg = "Error: RuntimeError %s" % error_msg
self.assertAddMessageCalledWith(expected_error_msg)
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
def test_form_not_valid(self):
with mock.patch(
"course.versioning.GitUpdateForm.is_valid"
) as mock_form_valid, mock.patch(
"course.versioning.run_course_update_command"
) as mock_run_update:
mock_form_valid.return_value = False
resp = self.post_update_course_content(
"some_commit_sha", command="update")
self.assertEqual(resp.status_code, 200)
self.assertEqual(mock_run_update.call_count, 0)
def test_repo_is_in_subdir(self):
self.course.course_root_path = "/subdir"
self.course.save()
from course.content import get_course_repo, SubdirRepoWrapper
self.assertIsInstance(get_course_repo(self.course), SubdirRepoWrapper)
with mock.patch(
"course.versioning.run_course_update_command"
) as mock_run_update:
self.post_update_course_content(
self.course.active_git_commit_sha, command="update")
self.assertEqual(mock_run_update.call_count, 1)
from course.content import SubdirRepoWrapper
from dulwich.repo import Repo
self.assertIsInstance(mock_run_update.call_args[0][1], Repo)