-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_integration.py
More file actions
144 lines (108 loc) · 4.56 KB
/
test_integration.py
File metadata and controls
144 lines (108 loc) · 4.56 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
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
"""Integration tests for Phase 1 commands."""
import pytest
from click.testing import CliRunner
from pathlib import Path
import tempfile
import shutil
from dremio_cli.cli import cli
from dremio_cli.config import ProfileManager
@pytest.fixture
def temp_config_dir():
"""Create temporary config directory."""
temp_dir = Path(tempfile.mkdtemp())
yield temp_dir
shutil.rmtree(temp_dir)
@pytest.fixture
def runner():
"""Create CLI test runner."""
return CliRunner()
@pytest.fixture
def mock_profile(temp_config_dir, monkeypatch):
"""Create a mock profile for testing."""
# Set up environment variables for testing
monkeypatch.setenv("DREMIO_MOCKTEST_TYPE", "software")
monkeypatch.setenv("DREMIO_MOCKTEST_BASE_URL", "http://localhost:9047/api/v3")
monkeypatch.setenv("DREMIO_MOCKTEST_TOKEN", "test_token_123")
# Create profile manager with temp directory
manager = ProfileManager(config_dir=temp_config_dir)
# Create a test profile with unique name
manager.create_profile(
name="mocktest",
profile_type="software",
base_url="http://localhost:9047/api/v3",
auth_type="pat",
token="test_token_123",
)
return "mocktest"
class TestProfileCommands:
"""Test profile management commands."""
def test_profile_list(self, runner, mock_profile):
"""Test profile list command."""
result = runner.invoke(cli, ["profile", "list"])
assert result.exit_code == 0
assert "test" in result.output or "Profiles" in result.output
def test_profile_current(self, runner, mock_profile):
"""Test profile current command."""
result = runner.invoke(cli, ["profile", "current"])
assert result.exit_code == 0
class TestCatalogCommands:
"""Test catalog commands."""
def test_catalog_list_help(self, runner):
"""Test catalog list help."""
result = runner.invoke(cli, ["catalog", "list", "--help"])
assert result.exit_code == 0
assert "List catalog contents" in result.output
def test_catalog_get_help(self, runner):
"""Test catalog get help."""
result = runner.invoke(cli, ["catalog", "get", "--help"])
assert result.exit_code == 0
assert "Get catalog item by ID" in result.output
class TestSQLCommands:
"""Test SQL commands."""
def test_sql_execute_help(self, runner):
"""Test SQL execute help."""
result = runner.invoke(cli, ["sql", "execute", "--help"])
assert result.exit_code == 0
assert "Execute SQL query" in result.output
def test_sql_execute_no_query(self, runner, mock_profile):
"""Test SQL execute without query."""
result = runner.invoke(cli, ["--profile", "mocktest", "sql", "execute"])
assert result.exit_code != 0
class TestSourceCommands:
"""Test source commands."""
def test_source_list_help(self, runner):
"""Test source list help."""
result = runner.invoke(cli, ["source", "list", "--help"])
assert result.exit_code == 0
assert "List all sources" in result.output
def test_source_get_help(self, runner):
"""Test source get help."""
result = runner.invoke(cli, ["source", "get", "--help"])
assert result.exit_code == 0
assert "Get source by ID" in result.output
class TestTableCommands:
"""Test table commands."""
def test_table_get_help(self, runner):
"""Test table get help."""
result = runner.invoke(cli, ["table", "get", "--help"])
assert result.exit_code == 0
assert "Get table by ID" in result.output
def test_table_get_by_path_help(self, runner):
"""Test table get-by-path help."""
result = runner.invoke(cli, ["table", "get-by-path", "--help"])
assert result.exit_code == 0
assert "Get table by path" in result.output
class TestOutputFormats:
"""Test output format options."""
def test_json_output_format(self, runner):
"""Test JSON output format option."""
result = runner.invoke(cli, ["--output", "json", "profile", "list"])
assert result.exit_code == 0
def test_yaml_output_format(self, runner):
"""Test YAML output format option."""
result = runner.invoke(cli, ["--output", "yaml", "profile", "list"])
assert result.exit_code == 0
def test_table_output_format(self, runner):
"""Test table output format option."""
result = runner.invoke(cli, ["--output", "table", "profile", "list"])
assert result.exit_code == 0