Skip to content

Commit 577c753

Browse files
Merge pull request #46 from JuliaSprenger/fix/cli
Fix missing cli default value and add tests
2 parents 1eaf701 + 682d6e0 commit 577c753

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

redcap_bridge/cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def main(command_line=None):
3535
if args.debug:
3636
print("debug: " + str(args))
3737
if args.command == 'download':
38+
if not args.format:
39+
args.format = ['csv']
40+
3841
download_records(args.destination[0], args.config_json[0], format=args.format[0],
3942
compressed=bool(args.compressed))
4043

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)