-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic.py
More file actions
143 lines (109 loc) · 3.76 KB
/
Copy pathtest_basic.py
File metadata and controls
143 lines (109 loc) · 3.76 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
"""
Basic tests for Crunch.
"""
import pytest
def test_import():
"""Test that the package can be imported."""
import crunch
assert crunch.__version__ == "1.0.1"
def test_settings_import():
"""Test that settings can be imported."""
from crunch.config.settings import Settings, get_settings
settings = Settings()
assert settings.app.title == "NiceMeta" # legacy display name in settings
assert settings.app.port == 8080
def test_query_builder():
"""Test the visual query builder."""
from crunch.query.builder import (
Column,
Filter,
FilterOperator,
QueryBuilder,
VisualQuery,
)
builder = QueryBuilder()
query = VisualQuery(
table="users",
columns=[
Column(name="id"),
Column(name="email"),
],
filters=[
Filter(column="active", operator=FilterOperator.EQUALS, value=True),
],
limit=100,
)
sql = builder.build(query)
assert "SELECT" in sql
assert '"users"' in sql
assert '"id"' in sql
assert '"email"' in sql
assert "LIMIT 100" in sql
def test_query_validator():
"""Test SQL query validation."""
from crunch.query.validator import QueryValidator, QueryType
validator = QueryValidator()
# Test SELECT detection
result = validator.validate("SELECT * FROM users")
assert result.is_valid
assert result.query_type == QueryType.SELECT
assert result.is_read_only
# Test INSERT detection
result = validator.validate("INSERT INTO users VALUES (1)")
assert not result.is_valid # Writes not allowed by default
assert result.query_type == QueryType.INSERT
# Test with writes allowed
validator_with_writes = QueryValidator(allow_writes=True)
result = validator_with_writes.validate("INSERT INTO users VALUES (1)")
assert result.is_valid
def test_chart_types():
"""Test chart type definitions."""
from crunch.visualization.chart_types import (
CHART_TYPES,
ChartCategory,
get_chart_type,
get_chart_types_by_category,
)
# Test getting chart type
line_chart = get_chart_type("line")
assert line_chart is not None
assert line_chart.name == "Line Chart"
assert "plotly" in line_chart.supported_renderers
# Test category filtering
basic_charts = get_chart_types_by_category(ChartCategory.BASIC)
assert len(basic_charts) > 0
assert all(ct.category == ChartCategory.BASIC for ct in basic_charts)
def test_chart_factory():
"""Test chart factory."""
from crunch.visualization.factory import ChartFactory
# Test renderer listing
renderers = ChartFactory.get_available_renderers()
assert "plotly" in renderers
assert "matplotlib" in renderers
assert "seaborn" in renderers
# Test getting renderer
plotly = ChartFactory.get_renderer("plotly")
assert plotly.name == "plotly"
# Test chart types listing
chart_types = ChartFactory.get_chart_types()
assert len(chart_types) > 0
assert any(ct["id"] == "line" for ct in chart_types)
@pytest.mark.asyncio
async def test_connection_manager():
"""Test connection manager."""
from crunch.connections.manager import ConnectionManager
from crunch.config.connections import ConnectionConfig
manager = ConnectionManager()
# Test supported types
types = manager.get_supported_types()
assert "postgresql" in types
assert "mysql" in types
assert "sqlite" in types
# Test creating SQLite adapter
config = ConnectionConfig(
name="Test SQLite",
type="sqlite",
database=":memory:",
)
adapter = manager.create_adapter(config)
assert adapter.db_type == "sqlite"