Skip to content

Commit 682d6e0

Browse files
author
sprenger
committed
add first cli tests
1 parent af61b0c commit 682d6e0

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import subprocess
2+
import pathlib
3+
4+
from redcap_bridge.server_interface import upload_datadict, upload_records
5+
from redcap_bridge.test_redcap.test_utils import (test_directory, initialize_test_dir)
6+
from redcap_bridge.test_redcap.test_server_interface import SERVER_CONFIG_YAML
7+
8+
project_dir = test_directory / 'testfiles' / 'TestProject'
9+
10+
11+
def test_installed(initialize_test_dir):
12+
"""
13+
Check that RedCapBridge was installed successfully
14+
"""
15+
result = subprocess.run(['RedCapBridge', '--help'], stdout=subprocess.PIPE)
16+
assert 'usage:' in str(result.stdout)
17+
18+
19+
def test_download(initialize_test_dir):
20+
"""
21+
Check that download option works for Test Project
22+
"""
23+
24+
# Set up project on server
25+
metadata_csv = test_directory / 'testfiles' / 'metadata.csv'
26+
upload_datadict(metadata_csv, SERVER_CONFIG_YAML)
27+
records_csv = test_directory / 'testfiles' / 'record.csv'
28+
upload_records(records_csv, SERVER_CONFIG_YAML)
29+
30+
output_file = test_directory / 'cli_download_test.csv'
31+
32+
# download with default arguments
33+
result = subprocess.run(['RedCapBridge', 'download', output_file, SERVER_CONFIG_YAML],
34+
stdout=subprocess.PIPE)
35+
assert 'error' not in str(result.stdout)
36+
assert output_file.exists()
37+
output_file.unlink()
38+
39+
# download in compressed mode
40+
result = subprocess.run(['RedCapBridge', 'download', '--compressed', output_file,
41+
SERVER_CONFIG_YAML],
42+
stdout=subprocess.PIPE)
43+
assert 'error' not in str(result.stdout)
44+
assert pathlib.Path(output_file).exists()
45+
output_file.unlink()
46+
47+
# download with format argument
48+
result = subprocess.run(['RedCapBridge', 'download', '--format', 'csv', output_file,
49+
SERVER_CONFIG_YAML],
50+
stdout=subprocess.PIPE)
51+
assert 'error' not in str(result.stdout)
52+
assert pathlib.Path(output_file).exists()

0 commit comments

Comments
 (0)