-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_cli.py
More file actions
49 lines (40 loc) · 1.7 KB
/
test_cli.py
File metadata and controls
49 lines (40 loc) · 1.7 KB
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
import json
import os
from unittest.mock import mock_open, patch
from click.testing import CliRunner
from datacustomcode.cli import init
class TestInit:
@patch("datacustomcode.template.copy_template")
@patch("datacustomcode.scan.dc_config_json_from_file")
@patch("builtins.open", new_callable=mock_open)
def test_init_command(self, mock_file, mock_scan, mock_copy):
"""Test init command."""
mock_scan.return_value = {
"sdkVersion": "1.0.0",
"entryPoint": "entrypoint.py",
"dataspace": "default",
"permissions": {
"read": {"dlo": ["input_dlo"]},
"write": {"dlo": ["output_dlo"]},
},
}
runner = CliRunner()
with runner.isolated_filesystem():
# Create test directory structure
os.makedirs(os.path.join("test_dir", "payload"), exist_ok=True)
result = runner.invoke(init, ["test_dir"])
assert result.exit_code == 0
mock_copy.assert_called_once_with("test_dir")
mock_scan.assert_called_once_with(
os.path.join("test_dir", "payload", "entrypoint.py")
)
# Verify the config.json was written with the correct content
mock_file.assert_any_call(
os.path.join("test_dir", "payload", "config.json"), "w"
)
# Get all write calls and join them to get the complete written content
written_content = "".join(
call.args[0] for call in mock_file().write.call_args_list
)
expected_content = json.dumps(mock_scan.return_value, indent=2)
assert written_content == expected_content