Skip to content

Commit 6802a53

Browse files
committed
Testing without explicitly setting duckdb
1 parent f5cdcdf commit 6802a53

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

tests/conftest.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import os
22
import pytest
3-
import duckdb
43
import boto3
54
from testcontainers.localstack import LocalStackContainer
65
from botocore.exceptions import ClientError
76

8-
97
os.environ["AWS_ACCESS_KEY_ID"] = "test"
108
os.environ["AWS_SECRET_ACCESS_KEY"] = "test"
119
os.environ["AWS_DEFAULT_REGION"] = "eu-west-2"
@@ -14,13 +12,17 @@
1412
os.environ["PERFORMANCE_BASE_PATH"] = "test/path_perf"
1513
os.environ["SPECIFICATION_BASE_PATH"] = "test/path_spec"
1614
os.environ["USE_AWS_CREDENTIAL_CHAIN"] = "false"
15+
os.environ["DUCKDB_S3_USE_SSL"] = "false"
1716

1817

1918
@pytest.fixture(scope="module")
2019
def localstack_container():
2120
# Start LocalStack container
2221
with LocalStackContainer() as localstack:
2322
# Wait for the service to be ready
23+
os.environ[
24+
"DUCKDB_S3_ENDPOINT"
25+
] = f"s3.localhost.localstack.cloud:{localstack.get_exposed_port(4566)}" # noqa
2426
yield localstack
2527

2628

@@ -37,19 +39,6 @@ def s3_client(localstack_container):
3739
return s3
3840

3941

40-
@pytest.fixture
41-
def duckdb_connection(localstack_container):
42-
# Set up a DuckDB in-memory database
43-
conn = duckdb.connect()
44-
# Configure DuckDB to connect to S3 via LocalStack
45-
conn.execute(
46-
f"SET s3_endpoint = '{localstack_container.get_url().lstrip('http://')}';" # noqa
47-
)
48-
conn.execute("SET s3_url_style = 'path';")
49-
yield conn
50-
conn.close()
51-
52-
5342
@pytest.fixture(scope="module")
5443
def test_dir(request):
5544
return os.path.dirname(request.module.__file__)

tests/integration/test_main.py

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from fastapi.testclient import TestClient
2-
from unittest.mock import patch
32
from main import app
43
import json
54

@@ -8,7 +7,7 @@
87
client = TestClient(app)
98

109

11-
def test_search_issues(s3_bucket, duckdb_connection):
10+
def test_search_issues(s3_bucket):
1211
# Prepare test params
1312
params = {
1413
"dataset": "conservation-area",
@@ -17,8 +16,7 @@ def test_search_issues(s3_bucket, duckdb_connection):
1716
}
1817

1918
# Test the function that interacts with DuckDB and S3 via LocalStack
20-
with patch("db.duckdb.connect", return_value=duckdb_connection):
21-
response = client.get("/log/issue", params=params)
19+
response = client.get("/log/issue", params=params)
2220

2321
# Validate the results from the search
2422
assert response.status_code == 200
@@ -35,13 +33,12 @@ def test_search_issues(s3_bucket, duckdb_connection):
3533
)
3634

3735

38-
def test_search_issues_no_parameters(duckdb_connection):
36+
def test_search_issues_no_parameters():
3937
# Prepare test params
4038
params = {}
4139

4240
# Test the function that interacts with DuckDB and S3 via LocalStack
43-
with patch("db.duckdb.connect", return_value=duckdb_connection):
44-
response = client.get("/log/issue", params=params)
41+
response = client.get("/log/issue", params=params)
4542

4643
response_json = json.loads(response.content.decode("utf-8"))
4744
details = response_json.get("detail", [])
@@ -52,17 +49,15 @@ def test_search_issues_no_parameters(duckdb_connection):
5249
)
5350

5451

55-
def test_provision_summary(s3_bucket, duckdb_connection):
52+
def test_provision_summary(s3_bucket):
5653
# Prepare test params
5754
params = {
5855
"organisation": "local-authority:BDG",
5956
"offset": 0,
6057
"limit": 8,
6158
}
6259

63-
with patch("db.duckdb.connect", return_value=duckdb_connection):
64-
# Test the function that interacts with DuckDB and S3 via LocalStack
65-
response = client.get("/performance/provision_summary", params=params)
60+
response = client.get("/performance/provision_summary", params=params)
6661

6762
# Validate the results from the search
6863
assert response.status_code == 200
@@ -75,16 +70,14 @@ def test_provision_summary(s3_bucket, duckdb_connection):
7570
assert len(response_data) > 0
7671

7772

78-
def test_specification(s3_bucket, duckdb_connection):
73+
def test_specification(s3_bucket):
7974
# Prepare test params
8075
params = {
8176
"offset": 0,
8277
"limit": 8,
8378
}
8479

85-
with patch("db.duckdb.connect", return_value=duckdb_connection):
86-
# Test the function that interacts with DuckDB and S3 via LocalStack
87-
response = client.get("/specification/specification", params=params)
80+
response = client.get("/specification/specification", params=params)
8881

8982
# Validate the results from the search
9083
assert response.status_code == 200

0 commit comments

Comments
 (0)