Newer
Older
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
tree = Tree()
tree.add(b"a_dir", stat.S_IFDIR,
hashlib.sha224(b"a dir").hexdigest().encode())
validation.check_attributes_yml(
vctx, repo, path, tree, default_access_kinds)
self.assertEqual(vctx.add_warning.call_count, 0)
# make sure check_attributes_yml is called recursively
self.assertEqual(
self.mock_get_true_repo_and_path.call_count, 2,
"check_attributes_yml is expected to be called recursively")
self.assertEqual(
self.mock_get_true_repo_and_path.call_args[0][1], "a_dir",
"check_attributes_yml is expected call with subfolder'a_dir'"
)
def test_success_with_attributes_yml(self):
path = ""
repo = vctx.repo
tree = Tree()
tree.add(ATTRIBUTES_FILENAME.encode(), stat.S_IFREG,
b".attributes.yml_content")
fake_repo = FakeRepo()
fake_repo[b".attributes.yml_content"] = FakeBlob(VALID_ATTRIBUTES_YML)
self.mock_get_true_repo_and_path.return_value = (fake_repo, "")
validation.check_attributes_yml(
vctx, repo, path, tree, default_access_kinds)
def test_attributes_yml_public_deprecated(self):
path = ""
repo = vctx.repo
tree = Tree()
tree.add(ATTRIBUTES_FILENAME.encode(), stat.S_IFREG,
b".attributes.yml_content")
fake_repo = FakeRepo()
fake_repo[b".attributes.yml_content"] = FakeBlob(
VALID_ATTRIBUTES_WITH_PUBLIC_YML)
self.mock_get_true_repo_and_path.return_value = (fake_repo, "")
validation.check_attributes_yml(
vctx, repo, path, tree, default_access_kinds)
self.assertEqual(vctx.add_warning.call_count, 1)
expected_warn_msg = ("Access class 'public' is deprecated. "
"Use 'unenrolled' instead.")
self.assertIn(expected_warn_msg, vctx.add_warning.call_args[0])
def test_failure_with_invalid_attributes_yml(self):
path = ""
repo = vctx.repo
tree = Tree()
tree.add(ATTRIBUTES_FILENAME.encode(), stat.S_IFREG,
b".attributes.yml_content")
fake_repo = FakeRepo()
fake_repo[b".attributes.yml_content"] = FakeBlob(INVALID_ATTRIBUTES_YML)
self.mock_get_true_repo_and_path.return_value = (fake_repo, "")
with self.assertRaises(ValidationError) as cm:
validation.check_attributes_yml(
vctx, repo, path, tree, default_access_kinds)
expected_error_msg = "entry 2 in 'student' is not a string"
self.assertIn(expected_error_msg, str(cm.exception))
def test_attributes_yml_failed_with_public_and_unenrolled(self):
path = ""
repo = vctx.repo
tree = Tree()
tree.add(ATTRIBUTES_FILENAME.encode(), stat.S_IFREG,
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
b".attributes.yml_content")
fake_repo = FakeRepo()
fake_repo[b".attributes.yml_content"] = (
FakeBlob(INVALID_ATTRIBUTES_WITH_PUBLIC_AND_UNENROLLED_YML))
self.mock_get_true_repo_and_path.return_value = (fake_repo, "")
with self.assertRaises(ValidationError) as cm:
validation.check_attributes_yml(
vctx, repo, path, tree, default_access_kinds)
expected_error_msg = ("access classes 'public' and 'unenrolled' may not "
"exist simultaneously.")
self.assertIn(expected_error_msg, str(cm.exception))
def test_attributes_yml_gitignore_subfolder(self):
path = ""
repo = vctx.repo
tree = Tree()
tree.add(b".gitignore", stat.S_IFREG, b".gitignore_content")
tree.add(b"a_dir", stat.S_IFDIR, b"a_dir_content")
fake_repo = FakeRepo()
fake_repo[b".gitignore_content"] = (
FakeBlob(GITIGNORE))
fake_repo[b"a_dir_content"] = Tree()
self.mock_get_true_repo_and_path.return_value = (fake_repo, "")
validation.check_attributes_yml(
vctx, repo, path, tree, default_access_kinds)
self.assertEqual(vctx.add_warning.call_count, 0)
# make sure check_attributes_yml is not called recursively
self.assertEqual(
self.mock_get_true_repo_and_path.call_count, 1,
"check_attributes_yml is expected to be called only once")
def test_attributes_yml_gitignore_subfolder_commented(self):
path = ""
repo = vctx.repo
tree = Tree()
tree.add(b".gitignore", stat.S_IFREG, b".gitignore_content")
tree.add(b"a_dir", stat.S_IFDIR, b"a_dir_content")
fake_repo = FakeRepo()
fake_repo[b".gitignore_content"] = (
FakeBlob(GITIGNORE_COMMENTED))
fake_repo[b"a_dir_content"] = Tree()
self.mock_get_true_repo_and_path.return_value = (fake_repo, "")
validation.check_attributes_yml(
vctx, repo, path, tree, default_access_kinds)
self.assertEqual(vctx.add_warning.call_count, 0)
# make sure check_attributes_yml is called recursively
self.assertEqual(
self.mock_get_true_repo_and_path.call_count, 2,
"check_attributes_yml is expected to be called twice")
def test_attributes_yml_failed_with_public_and_unenrolled_in_subfolder(self):
path = ""
repo = vctx.repo
tree = Tree()
tree.add(b"a_dir", stat.S_IFDIR, b"a_dir_content")
fake_repo = FakeRepo()
fake_sub_repo = FakeRepo()
sub_tree = Tree()
sub_tree.add(b"some_file", stat.S_IFREG, b"some_content")
sub_tree.add(ATTRIBUTES_FILENAME.encode(), stat.S_IFREG,
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
b".attributes.yml_content")
fake_sub_repo[b".attributes.yml_content"] = FakeBlob(
INVALID_ATTRIBUTES_WITH_PUBLIC_AND_UNENROLLED_YML)
fake_repo[b"a_dir_content"] = sub_tree
self.mock_get_true_repo_and_path.side_effect = [
(fake_repo, ""), (fake_sub_repo, "a_dir")]
with self.assertRaises(ValidationError) as cm:
validation.check_attributes_yml(
vctx, repo, path, tree, default_access_kinds)
expected_error_msg = ("access classes 'public' and 'unenrolled' may not "
"exist simultaneously.")
self.assertIn(expected_error_msg, str(cm.exception))
# make sure check_attributes_yml is called recursively
self.assertEqual(
self.mock_get_true_repo_and_path.call_count, 2,
"check_attributes_yml is expected to be called twice")