Commit 74dd216a authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

TEST: more integration tests

parent 1b88590d
Pipeline #5698 passed with stage
in 35 seconds
......@@ -2,7 +2,9 @@
import os
import os.path as op
import time
import json
import shutil
from unittest import mock
import pytest
......@@ -533,3 +535,135 @@ def test_main_plugins_and_manifest():
'i/j', 'k/l', 'm/n', 'o/p'])
def test_main_skip_already_downloaded():
with tempdir() as cwd, server() as srv:
make_archive('abc.zip', 'a/b', 'c/d')
make_archive('abc_bad.zip', 'e/f', 'g/h')
url = {
'abc' : f'http://localhost:{srv.port}/abc.zip',
'abc_bad' : f'http://localhost:{srv.port}/abc_bad.zip',
}
manifest = [
{'name' : 'abc',
'url' : url['abc'],
'checksum' : routines.calcChecksum('abc.zip')
},
{'name' : 'abc_bad',
'url' : url['abc_bad'],
'checksum' : routines.calcChecksum('abc_bad.zip')
},
]
with open('manifest.json', 'wt') as f:
f.write(json.dumps(manifest))
archiveDir = op.join(cwd, 'archives')
destDir = op.join(cwd, 'dest')
archivePath = {
'abc' : op.join(archiveDir, 'abc.zip'),
'abc_bad' : op.join(archiveDir, 'abc_bad.zip')
}
os.mkdir(destDir)
os.mkdir(archiveDir)
# We test via modification time, so sleep
# a bit to make sure they're different
# (note incorrect file for abc_bad, which
# should cause checksum to fail and file
# to be re-downloaded)
shutil.copy('abc.zip', archivePath['abc'])
shutil.copy('abc.zip', archivePath['abc_bad'])
mtime = {
'abc' : os.stat(archivePath['abc']) .st_mtime_ns,
'abc_bad' : os.stat(archivePath['abc_bad']).st_mtime_ns,
}
time.sleep(1.5)
# direct download - if file exists, it is
# assumed to be ok, and not re-downloaded.
with mock.patch('fsl.scripts.fsl_add_module.MANIFEST_URL', None):
fam.main(f'{url["abc"]} -a {archiveDir} -d {destDir} -f'.split())
assert os.stat(archivePath['abc']).st_mtime_ns == mtime['abc']
check_dir(destDir, ['a/b', 'c/d'])
# download via manifest - if file exists, and
# checksums match, it is not re-downloaded
shutil.rmtree(destDir)
os.mkdir(destDir)
fam.main(f'abc -a {archiveDir} -d {destDir} '
'-m manifest.json -f'.split())
assert os.stat(archivePath['abc']).st_mtime_ns == mtime['abc']
check_dir(destDir, ['a/b', 'c/d'])
# if file exists, but checksums do not
# match, file should be re-downloaded
shutil.rmtree(destDir)
os.mkdir(destDir)
fam.main(f'abc_bad -a {archiveDir} -d {destDir} '
'-m manifest.json -f'.split())
assert os.stat(archivePath['abc_bad']).st_mtime_ns != mtime['abc_bad']
check_dir(destDir, ['e/f', 'g/h'])
def test_main_customise_plugin_dir():
with tempdir() as cwd:
make_archive('abc.zip', 'a/b', 'c/d')
make_archive('def.zip', 'e/f', 'g/h')
make_archive('ghi.zip', 'i/j', 'k/l')
abcdest = 'dest1'
defdest = 'dest2'
ghidest = 'dest3'
os.mkdir(abcdest)
os.mkdir(defdest)
os.mkdir(ghidest)
with mock.patch('fsl.scripts.fsl_add_module.MANIFEST_URL', None), \
mock_input('c', abcdest, defdest, ghidest):
fam.main(f'abc.zip def.zip ghi.zip'.split())
check_dir(abcdest, ['a/b', 'c/d'])
check_dir(defdest, ['e/f', 'g/h'])
check_dir(ghidest, ['i/j', 'k/l'])
def test_main_default_destinations():
with tempdir() as cwd, server() as srv:
manifest = [
{'name' : 'abc',
'url' : f'http://localhost:{srv.port}/abc.zip'},
{'name' : 'def',
'url' : f'http://localhost:{srv.port}/def.zip',
'destination' : f'{cwd}/defdest/'},
]
with open('manifest.json', 'wt') as f:
f.write(json.dumps(manifest))
make_archive('abc.zip', 'a/b', 'c/d')
make_archive('def.zip', 'e/f', 'g/h')
# default == FSLDIR if it is set
os.mkdir('defdest')
os.mkdir('fsl')
with mock.patch.dict(os.environ, {'FSLDIR' : f'{cwd}/fsl'}):
fam.main('abc def -m manifest.json -f'.split())
check_dir('fsl', ['a/b', 'c/d'])
check_dir('defdest', ['e/f', 'g/h'])
# default == cwd if FSLDIR is not set
shutil.rmtree('defdest')
shutil.rmtree('fsl')
os.mkdir('defdest')
with mock.patch.dict(os.environ, clear=True):
fam.main('abc def -m manifest.json -f'.split())
check_dir('.', ['a/b', 'c/d'])
check_dir('defdest', ['e/f', 'g/h'])
shutil.rmtree('defdest')
shutil.rmtree('a')
shutil.rmtree('c')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment