Skip to content

Commit 0861103

Browse files
committed
ci: upgrade typesense version to v30 on ci
1 parent 972b9a1 commit 0861103

25 files changed

+131
-140
lines changed

.github/workflows/test-and-lint.yml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ jobs:
1212
strategy:
1313
matrix:
1414
python-version: ["3.9", "3.10", "3.11", "3.12"]
15-
services:
16-
typesense:
17-
image: typesense/typesense:28.0
18-
ports:
19-
- 8108:8108
20-
volumes:
21-
- /tmp/typesense-data:/data
22-
- /tmp/typesense-analytics:/analytics
23-
env:
24-
TYPESENSE_API_KEY: xyz
25-
TYPESENSE_DATA_DIR: /data
26-
TYPESENSE_ENABLE_CORS: true
27-
TYPESENSE_ANALYTICS_DIR: /analytics
28-
TYPESENSE_ENABLE_SEARCH_ANALYTICS: true
2915

3016
steps:
17+
- name: Start Typesense
18+
run: |
19+
docker run -d \
20+
-p 8108:8108 \
21+
--name typesense \
22+
-v /tmp/typesense-data:/data \
23+
-v /tmp/typesense-analytics-data:/analytics-data \
24+
typesense/typesense:30.0.alpha1 \
25+
--api-key=xyz \
26+
--data-dir=/data \
27+
--enable-search-analytics=true \
28+
--analytics-dir=/analytics-data \
29+
--analytics-flush-interval=60 \
30+
--analytics-minute-rate-limit=50 \
31+
--enable-cors
32+
3133
- name: Wait for Typesense
3234
run: |
3335
timeout 20 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8108/health)" != "200" ]]; do sleep 1; done' || false

tests/analytics_events_test.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
"""Tests for Analytics events endpoints (client.analytics.events)."""
2+
23
from __future__ import annotations
34

45
import pytest
6+
import requests_mock
57

68
from tests.utils.version import is_v30_or_above
79
from typesense.client import Client
8-
import requests_mock
9-
1010
from typesense.types.analytics import AnalyticsEvent
1111

12-
1312
pytestmark = pytest.mark.skipif(
1413
not is_v30_or_above(
15-
Client({
16-
"api_key": "xyz",
17-
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
18-
})
14+
Client(
15+
{
16+
"api_key": "xyz",
17+
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
18+
}
19+
)
1920
),
2021
reason="Run analytics events tests only on v30+",
2122
)
2223

2324

24-
def test_actual_create_event(actual_client: Client, delete_all: None, create_collection: None, delete_all_analytics_rules: None) -> None:
25+
def test_actual_create_event(
26+
actual_client: Client,
27+
delete_all: None,
28+
create_collection: None,
29+
delete_all_analytics_rules: None,
30+
) -> None:
2531
actual_client.analytics.rules.create(
2632
{
2733
"name": "company_analytics_rule",
@@ -61,7 +67,9 @@ def test_status(actual_client: Client, delete_all: None) -> None:
6167
assert isinstance(status, dict)
6268

6369

64-
def test_retrieve_events(actual_client: Client, delete_all: None, delete_all_analytics_rules: None) -> None:
70+
def test_retrieve_events(
71+
actual_client: Client, delete_all: None, delete_all_analytics_rules: None
72+
) -> None:
6573
actual_client.analytics.rules.create(
6674
{
6775
"name": "company_analytics_rule",
@@ -89,19 +97,12 @@ def test_retrieve_events(actual_client: Client, delete_all: None, delete_all_ana
8997
assert "events" in result
9098

9199

92-
93-
def test_retrieve_events(fake_client: Client) -> None:
94-
with requests_mock.Mocker() as mock:
95-
mock.get(
96-
"http://nearest:8108/analytics/events",
97-
json={"events": [{"name": "company_analytics_rule"}]},
98-
)
99-
result = fake_client.analytics.events.retrieve(
100-
user_id="user-1", name="company_analytics_rule", n=10
101-
)
102-
assert "events" in result
103-
104-
def test_acutal_retrieve_events(actual_client: Client, delete_all: None, create_collection: None, delete_all_analytics_rules: None) -> None:
100+
def test_acutal_retrieve_events(
101+
actual_client: Client,
102+
delete_all: None,
103+
create_collection: None,
104+
delete_all_analytics_rules: None,
105+
) -> None:
105106
actual_client.analytics.rules.create(
106107
{
107108
"name": "company_analytics_rule",
@@ -126,6 +127,7 @@ def test_acutal_retrieve_events(actual_client: Client, delete_all: None, create_
126127
)
127128
assert "events" in result
128129

130+
129131
def test_acutal_flush(actual_client: Client, delete_all: None) -> None:
130132
resp = actual_client.analytics.events.flush()
131133
assert resp["ok"] in [True, False]
@@ -136,5 +138,3 @@ def test_flush(fake_client: Client) -> None:
136138
mock.post("http://nearest:8108/analytics/flush", json={"ok": True})
137139
resp = fake_client.analytics.events.flush()
138140
assert resp["ok"] is True
139-
140-

tests/analytics_rule_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Unit tests for per-rule AnalyticsRule operations."""
2+
23
from __future__ import annotations
34

45
import pytest
@@ -12,10 +13,12 @@
1213

1314
pytestmark = pytest.mark.skipif(
1415
not is_v30_or_above(
15-
Client({
16-
"api_key": "xyz",
17-
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
18-
})
16+
Client(
17+
{
18+
"api_key": "xyz",
19+
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
20+
}
21+
)
1922
),
2023
reason="Run analytics tests only on v30+",
2124
)
@@ -63,5 +66,3 @@ def test_actual_rule_delete(
6366
) -> None:
6467
resp = actual_analytics_rules["company_analytics_rule"].delete()
6568
assert resp["name"] == "company_analytics_rule"
66-
67-

tests/analytics_rule_v1_test.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests for the AnalyticsRuleV1 class."""
2+
23
from __future__ import annotations
34

45
import pytest
@@ -14,14 +15,17 @@
1415

1516
pytestmark = pytest.mark.skipif(
1617
is_v30_or_above(
17-
Client({
18-
"api_key": "xyz",
19-
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
20-
})
18+
Client(
19+
{
20+
"api_key": "xyz",
21+
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
22+
}
23+
)
2124
),
22-
reason="Skip AnalyticsV1 tests on v30+"
25+
reason="Skip AnalyticsV1 tests on v30+",
2326
)
2427

28+
2529
def test_init(fake_api_call: ApiCall) -> None:
2630
"""Test that the AnalyticsRuleV1 object is initialized correctly."""
2731
analytics_rule = AnalyticsRuleV1(fake_api_call, "company_analytics_rule")
@@ -42,7 +46,6 @@ def test_init(fake_api_call: ApiCall) -> None:
4246
)
4347

4448

45-
4649
def test_retrieve(fake_analytics_rule: AnalyticsRuleV1) -> None:
4750
"""Test that the AnalyticsRuleV1 object can retrieve an analytics_rule."""
4851
json_response: RuleSchemaForQueries = {
@@ -73,7 +76,6 @@ def test_retrieve(fake_analytics_rule: AnalyticsRuleV1) -> None:
7376
assert response == json_response
7477

7578

76-
7779
def test_delete(fake_analytics_rule: AnalyticsRuleV1) -> None:
7880
"""Test that the AnalyticsRuleV1 object can delete an analytics_rule."""
7981
json_response: RuleDeleteSchema = {
@@ -96,7 +98,6 @@ def test_delete(fake_analytics_rule: AnalyticsRuleV1) -> None:
9698
assert response == json_response
9799

98100

99-
100101
def test_actual_retrieve(
101102
actual_analytics_rules: AnalyticsRulesV1,
102103
delete_all: None,
@@ -119,7 +120,6 @@ def test_actual_retrieve(
119120
assert response == expected
120121

121122

122-
123123
def test_actual_delete(
124124
actual_analytics_rules: AnalyticsRulesV1,
125125
delete_all: None,
@@ -133,5 +133,3 @@ def test_actual_delete(
133133
"name": "company_analytics_rule",
134134
}
135135
assert response == expected
136-
137-

tests/analytics_rules_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests for v30 Analytics Rules endpoints (client.analytics.rules)."""
2+
23
from __future__ import annotations
34

45
import pytest
@@ -13,10 +14,12 @@
1314

1415
pytestmark = pytest.mark.skipif(
1516
not is_v30_or_above(
16-
Client({
17-
"api_key": "xyz",
18-
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
19-
})
17+
Client(
18+
{
19+
"api_key": "xyz",
20+
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
21+
}
22+
)
2023
),
2124
reason="Run v30 analytics tests only on v30+",
2225
)
@@ -130,5 +133,3 @@ def test_actual_retrieve(
130133
rules = actual_analytics_rules.retrieve()
131134
assert isinstance(rules, list)
132135
assert any(r.get("name") == "company_analytics_rule" for r in rules)
133-
134-

tests/analytics_rules_v1_test.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests for the AnalyticsRulesV1 class."""
2+
23
from __future__ import annotations
34

45
import pytest
@@ -17,14 +18,17 @@
1718

1819
pytestmark = pytest.mark.skipif(
1920
is_v30_or_above(
20-
Client({
21-
"api_key": "xyz",
22-
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
23-
})
21+
Client(
22+
{
23+
"api_key": "xyz",
24+
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
25+
}
26+
)
2427
),
25-
reason="Skip AnalyticsV1 tests on v30+"
28+
reason="Skip AnalyticsV1 tests on v30+",
2629
)
2730

31+
2832
def test_init(fake_api_call: ApiCall) -> None:
2933
"""Test that the AnalyticsRulesV1 object is initialized correctly."""
3034
analytics_rules = AnalyticsRulesV1(fake_api_call)
@@ -150,7 +154,6 @@ def test_create(fake_analytics_rules: AnalyticsRulesV1) -> None:
150154
}
151155

152156

153-
154157
def test_actual_create(
155158
actual_analytics_rules: AnalyticsRulesV1,
156159
delete_all: None,
@@ -182,7 +185,6 @@ def test_actual_create(
182185
}
183186

184187

185-
186188
def test_actual_update(
187189
actual_analytics_rules: AnalyticsRulesV1,
188190
delete_all: None,
@@ -213,7 +215,6 @@ def test_actual_update(
213215
}
214216

215217

216-
217218
def test_actual_retrieve(
218219
actual_analytics_rules: AnalyticsRulesV1,
219220
delete_all: None,
@@ -235,5 +236,3 @@ def test_actual_retrieve(
235236
"type": "nohits_queries",
236237
},
237238
)
238-
239-

tests/analytics_test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests for the AnalyticsV1 class."""
2+
23
import pytest
34
from tests.utils.version import is_v30_or_above
45
from typesense.client import Client
@@ -7,7 +8,17 @@
78
from typesense.api_call import ApiCall
89

910

10-
@pytest.mark.skipif(not is_v30_or_above(Client({"api_key": "xyz", "nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}]})), reason="Skip AnalyticsV1 tests on v30+")
11+
@pytest.mark.skipif(
12+
not is_v30_or_above(
13+
Client(
14+
{
15+
"api_key": "xyz",
16+
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
17+
}
18+
)
19+
),
20+
reason="Skip AnalyticsV1 tests on v30+",
21+
)
1122
def test_init(fake_api_call: ApiCall) -> None:
1223
"""Test that the AnalyticsV1 object is initialized correctly."""
1324
analytics = Analytics(fake_api_call)

tests/analytics_v1_test.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests for the AnalyticsV1 class."""
2+
23
import pytest
34
from tests.utils.version import is_v30_or_above
45
from typesense.client import Client
@@ -7,7 +8,17 @@
78
from typesense.api_call import ApiCall
89

910

10-
@pytest.mark.skipif(is_v30_or_above(Client({"api_key": "xyz", "nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}]})), reason="Skip AnalyticsV1 tests on v30+")
11+
@pytest.mark.skipif(
12+
is_v30_or_above(
13+
Client(
14+
{
15+
"api_key": "xyz",
16+
"nodes": [{"host": "localhost", "port": 8108, "protocol": "http"}],
17+
}
18+
)
19+
),
20+
reason="Skip AnalyticsV1 tests on v30+",
21+
)
1122
def test_init(fake_api_call: ApiCall) -> None:
1223
"""Test that the AnalyticsV1 object is initialized correctly."""
1324
analytics = AnalyticsV1(fake_api_call)
@@ -23,5 +34,3 @@ def test_init(fake_api_call: ApiCall) -> None:
2334
)
2435

2536
assert not analytics.rules.rules
26-
27-

0 commit comments

Comments
 (0)