/
test_shed_upload.py
261 lines (233 loc) · 10.4 KB
/
test_shed_upload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
""" Integration tests for shed_upload, shed_download, and shed_create
commands.
"""
from os.path import exists, join
import os
import tarfile
import shutil
from .test_utils import CliShedTestCase
class ShedUploadTestCase(CliShedTestCase):
def test_tar_single(self):
with self._isolate_repo("single_tool") as f:
upload_command = ["shed_upload", "--tar_only"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
assert_exists(join(f, "shed_upload.tar.gz"))
def test_upload_not_exists(self):
with self._isolate_repo("single_tool"):
upload_command = ["shed_upload"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command, exit_code=-1)
def test_upload_with_force_create(self):
with self._isolate_repo("single_tool") as f:
upload_command = ["shed_upload", "--force_repository_creation"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
self._verify_single_uploaded(f)
def test_create_and_upload(self):
with self._isolate_repo("single_tool") as f:
create_command = ["shed_create"]
create_command.extend(self._shed_args())
self._check_exit_code(create_command)
upload_command = ["shed_upload"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
self._verify_single_uploaded(f)
def test_cannont_recreate(self):
with self._isolate_repo("single_tool"):
create_command = ["shed_create"]
create_command.extend(self._shed_args())
self._check_exit_code(create_command)
self._check_exit_code(create_command, exit_code=-1)
def test_upload_recusrive(self):
with self._isolate_repo("multi_repos_nested") as f:
upload_command = [
"shed_upload", "-r", "--force_repository_creation"
]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
self._verify_upload(f, ["cat1.xml", "macros.xml"], ["cat1"])
self._verify_upload(f, ["cat2.xml", "macros.xml"], ["cat2"])
def test_upload_filters_invalid_suite(self):
with self._isolate_repo("suite_1") as f:
# No .shed.yml, make sure to test it can infer type
# from passed in --name.
upload_command = ["shed_upload", "--tar_only",
"--name", "suite_1"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
target = self._untar(f, "shed_upload.tar.gz")
# Only one file was in archive
assert_exists(join(target, "repository_dependencies.xml"))
# this got filtered
assert not exists(join(target, "README.rst"))
def test_upload_suite_auto(self):
with self._isolate_repo("suite_auto") as f:
upload_command = ["shed_upload", "--tar_only"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
target = self._untar(f, "shed_upload.tar.gz")
# Only one file was in archive
assert_exists(join(target, "repository_dependencies.xml"))
def test_upload_filters_ignore(self):
with self._isolate_repo("single_tool_exclude") as f:
upload_command = ["shed_upload", "--force_repository_creation"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
target = self._verify_upload(f)
assert not exists(join(target, "related_file"))
def test_tar_with_symlinks(self):
with self._isolate_repo("multi_repos_nested") as f:
upload_command = ["shed_upload", "--force_repository_creation"]
upload_command.append("cat2")
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
target = self._verify_upload(f, ["macros.xml"], ["cat2"])
with open(join(target, "macros.xml"), "r") as macro_f:
macro_contents = macro_f.read()
assert macro_contents.startswith("<macros>")
def test_upload_filters_git(self):
with self._isolate_repo("single_tool") as f:
mock_git_dir = join(f, ".git")
os.makedirs(mock_git_dir)
index_path = join(mock_git_dir, "index_file")
with open(index_path, "w") as index_f:
index_f.write("test")
upload_command = ["shed_upload", "--force_repository_creation"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
target = self._verify_upload(f)
assert not exists(join(target, ".git"))
def test_upload_filters_invalid_package(self):
with self._isolate_repo("package_1") as f:
upload_command = ["shed_upload", "--tar_only"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
target = self._untar(f, "shed_upload.tar.gz")
# Only one file was in archive
assert_exists(join(target, "tool_dependencies.xml"))
# this got filtered
assert not exists(join(target, "README.rst"))
# .shed.yml always gets filtered
assert not exists(join(target, ".shed.yml"))
def test_upload_not_filters_unrestricted(self):
with self._isolate_repo("workflow_1") as f:
upload_command = ["shed_upload", "--tar_only"]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
target = self._untar(f, "shed_upload.tar.gz")
# Only one file was in archive
assert_exists(join(target, "repository_dependencies.xml"))
assert_exists(join(target, "README.rst"))
def test_upload_expansion_configured(self):
with self._isolate_repo("multi_repos_flat_configured") as f:
self._verify_expansion(f)
def test_upload_expansion_flagged(self):
with self._isolate_repo("multi_repos_flat_flag") as f:
self._verify_expansion(f)
def test_upload_expansion_configured_extras(self):
with self._isolate() as f:
repo = join(f, "repo")
self._copy_repo("multi_repos_flat_configured_complex", repo)
self._copy_repo("shared_files", join(f, "shared_files"))
self._verify_expansion(f, "repo")
for tool_id in ["cat1", "cat2"]:
self._check_tar(
f, "shed_upload_cs_%s.tar.gz" % tool_id,
contains=[
"CITATION.txt",
"test-data/extra_test_file.txt",
],
)
def test_upload_expansion_suite(self):
with self._isolate_repo("multi_repos_flat_flag_suite") as f:
self._verify_expansion(f)
target = self._check_tar(
f, "shed_upload_suite_cat.tar.gz",
contains=[
"repository_dependencies.xml",
],
not_contains=["macros.xml"]
)
with open(join(target, "repository_dependencies.xml")) as f:
repo_xml = f.read()
assert 'owner="devteam" name="cat_legacy"' in repo_xml
assert 'owner="iuc" name="cs-cat2"' in repo_xml
def _verify_expansion(self, f, name=None):
upload_command = ["shed_upload", "--tar_only"]
upload_command.extend(self._shed_args())
if name is not None:
upload_command.append(join(f, name))
self._check_exit_code(upload_command)
self._check_tar(
f, "shed_upload_cs_cat1.tar.gz",
contains=[
"cat1.xml",
"macros.xml",
"test-data/1.bed"
],
not_contains=["cat2.xml"]
)
self._check_tar(
f, "shed_upload_cs_cat2.tar.gz",
contains=[
"cat2.xml",
"macros.xml",
"test-data/1.bed"
],
not_contains=["cat1.xml"]
)
def _verify_single_uploaded(self, f):
self._verify_upload(f, ["cat.xml", "related_file", "test-data/1.bed"])
def _verify_upload(self, f, download_files=[], download_args=[]):
target = self._download_repo(f, download_args)
for download_file in download_files:
assert_exists(join(target, download_file))
return target
def _check_tar(self, f, tar_path, contains=[], not_contains=[]):
tar_path = join(f, tar_path)
assert_exists(tar_path)
target = self._untar(f, tar_path)
for path in contains:
assert_exists(join(target, path))
for path in not_contains:
assert not exists(join(target, path))
return target
def _download_repo(self, f, download_args=[]):
download_command = ["shed_download"]
download_command.extend(download_args)
download_command.extend(self._shed_args(read_only=True))
self._check_exit_code(download_command)
download = join(f, "shed_download.tar.gz")
assert_exists(download)
return self._untar(f, "shed_download.tar.gz", tarbomb=False)
def _untar(self, f, path, tarbomb=True):
target = join(f, "download")
if exists(target):
shutil.rmtree(target)
os.makedirs(target)
tar = tarfile.open(path, "r:gz")
tar.extractall(path=target)
tar.close()
tar = tarfile.open(path, "r:gz")
for tar_info in tar.getmembers():
# These entries cause problems with TS.
assert tar_info.name != "."
assert tar_info.name != ""
tar.close()
if not tarbomb:
return os.path.join(target, os.listdir(target)[0])
else:
return target
def assert_exists(path):
dir_path = os.path.dirname(path)
msg = None
if not exists(dir_path):
template = "Expected path [%s] to exist, but parent absent."
msg = template % path
if not exists(path):
contents = os.listdir(dir_path)
template = "Expected path [%s] to exist. Directory contents %s."
msg = template % (path, contents)
if msg is not None:
raise AssertionError(msg)