Skip to content

Commit

Permalink
Add in a functional test for the http server as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jwills committed May 16, 2023
1 parent beeb083 commit d7b83e7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 0 additions & 1 deletion buenavista/examples/duckdb_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class DuckDBHTTPRewriter(rewrite.Rewriter):
def rewrite(self, sql: str) -> str:
sql = super().rewrite(sql)
sql = ESCAPE_PATTERN.sub(_escape_replace, sql)
print("Rewritten to %s" % sql)
return sql


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
long_description = f.read()

package_name = "buenavista"
package_version = "0.2.3"
package_version = "0.3.0"

description = """Programmable Presto and Postgres Proxies"""

Expand Down
35 changes: 35 additions & 0 deletions tests/functional/duckdb/test_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest

import duckdb
from fastapi import FastAPI
from fastapi.testclient import TestClient

from buenavista.backends.duckdb import DuckDBConnection
from buenavista.examples.duckdb_http import rewriter
from buenavista.http import main


@pytest.fixture(scope="session")
def db():
return duckdb.connect()


@pytest.fixture(scope="session")
def client(db):
app = FastAPI()
main.quacko(app, DuckDBConnection(db), rewriter)
return TestClient(app)


def test_info(client):
response = client.get("/v1/info")
assert response.status_code == 200


def test_select(client):
response = client.post(
"/v1/statement",
json="SELECT 1",
headers={"Content-Type": "application/json", "x-trino-user": "test"},
)
assert response.status_code == 200
2 changes: 2 additions & 0 deletions tests/functional/duckdb/test_postgres.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import threading
import time

import pytest

Expand All @@ -25,6 +26,7 @@ def duckdb_postgres_server(db, user_password):
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = True
server_thread.start()
time.sleep(1) # wait for server to start
yield server
finally:
db.close()
Expand Down

0 comments on commit d7b83e7

Please sign in to comment.