Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ packages = find:
install_requires =
aiorwlock==1.1.0
async-property==0.2.1
httpx[http2]==0.19.0
httpx[http2]==0.21.3
pydantic[dotenv]==1.8.2
readerwriterlock==1.0.9
sqlparse>=0.4.2
Expand All @@ -47,7 +47,7 @@ dev =
pytest==6.2.5
pytest-asyncio
pytest-cov==3.0.0
pytest-httpx==0.13.0
pytest-httpx==0.18.0
pytest-mock==3.6.1

[options.package_data]
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/async_db/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from httpx import URL, Request, Response, codes
from pytest import fixture
from pytest_httpx import to_response

from firebolt.async_db import ARRAY, Connection, Cursor, connect
from firebolt.async_db.cursor import JSON_OUTPUT_FORMAT, ColType, Column
Expand Down Expand Up @@ -115,7 +114,7 @@ def do_query(request: Request, **kwargs) -> Response:
"scanned_bytes_storage": 0,
},
}
return to_response(status_code=codes.OK, json=query_response)
return Response(status_code=codes.OK, json=query_response)

return do_query

Expand Down Expand Up @@ -147,7 +146,7 @@ def do_query(request: Request, **kwargs) -> Response:
"scanned_bytes_storage": 0,
},
}
return to_response(status_code=codes.OK, json=query_response)
return Response(status_code=codes.OK, json=query_response)

return do_query

Expand All @@ -157,7 +156,7 @@ def insert_query_callback(
query_description: List[Column], query_data: List[List[ColType]]
) -> Callable:
def do_query(request: Request, **kwargs) -> Response:
return to_response(status_code=codes.OK, headers={"content-length": "0"})
return Response(status_code=codes.OK, headers={"content-length": "0"})

return do_query

Expand All @@ -174,7 +173,7 @@ def set_params() -> Dict:
@fixture
def query_url(settings: Settings, db_name: str) -> str:
return URL(
f"https://{settings.server}?database={db_name}"
f"https://{settings.server}/?database={db_name}"
f"&output_format={JSON_OUTPUT_FORMAT}"
)

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/async_db/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async def test_cursor_execute_error(
httpx_mock.add_callback(auth_callback, url=auth_url)

# Internal httpx error
def http_error(**kwargs):
def http_error(*args, **kwargs):
raise StreamError("httpx error")

httpx_mock.add_callback(http_error, url=query_url)
Expand All @@ -217,7 +217,7 @@ def http_error(**kwargs):
# Database query error
httpx_mock.add_response(
status_code=codes.INTERNAL_SERVER_ERROR,
data="Query error message",
content="Query error message",
url=query_url,
)
with raises(OperationalError) as excinfo:
Expand All @@ -230,7 +230,7 @@ def http_error(**kwargs):
# Database does not exist error
httpx_mock.add_response(
status_code=codes.FORBIDDEN,
data="Query error message",
content="Query error message",
url=query_url,
)
httpx_mock.add_response(
Expand All @@ -243,7 +243,7 @@ def http_error(**kwargs):
# Engine is not running error
httpx_mock.add_response(
status_code=codes.SERVICE_UNAVAILABLE,
data="Query error message",
content="Query error message",
url=query_url,
)
httpx_mock.add_response(
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/client/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

import httpx
import pytest
from pytest_httpx import to_response
from pytest_httpx._httpx_internals import Response
from httpx import Response


@pytest.fixture
Expand Down Expand Up @@ -42,7 +41,7 @@ def check_credentials(
assert "password" in body, "Missing password"
assert body["password"] == test_password, "Invalid password"

return to_response(
return Response(
status_code=httpx.codes.OK,
json={"expires_in": 2 ** 32, "access_token": test_token},
)
Expand All @@ -61,6 +60,6 @@ def check_token(request: httpx.Request = None, **kwargs) -> Response:
token = auth[len(prefix) :]
assert token == test_token, "invalid authorization token"

return to_response(status_code=httpx.codes.OK)
return Response(status_code=httpx.codes.OK)

return check_token
2 changes: 1 addition & 1 deletion tests/unit/client/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_auth_error_handling(httpx_mock: HTTPXMock):
auth = Auth("user", "password", api_endpoint=api_endpoint)

# Internal httpx error
def http_error(**kwargs):
def http_error(*args, **kwargs):
raise StreamError("httpx")

httpx_mock.add_callback(http_error)
Expand Down
13 changes: 6 additions & 7 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import httpx
import pytest
from httpx import Response
from pydantic import SecretStr
from pytest_httpx import to_response
from pytest_httpx._httpx_internals import Response

from firebolt.common.exception import (
DatabaseError,
Expand Down Expand Up @@ -106,7 +105,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == auth_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json={"access_token": "", "expires_in": 2 ** 32},
)
Expand Down Expand Up @@ -150,11 +149,11 @@ def do_mock(
) -> Response:
assert request.url == account_id_url
if account_id_url.endswith(ACCOUNT_URL): # account_name shouldn't be specified.
return to_response(
return Response(
status_code=httpx.codes.OK, json={"account": {"id": account_id}}
)
# In this case, an account_name *should* be specified.
return to_response(status_code=httpx.codes.OK, json={"account_id": account_id})
return Response(status_code=httpx.codes.OK, json={"account_id": account_id})

return do_mock

Expand All @@ -180,7 +179,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == get_engine_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json={
"engine": {
Expand Down Expand Up @@ -216,7 +215,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == get_providers_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json=list_to_paginated_response([provider]),
)
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/db/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from httpx import URL, Request, Response, codes
from pytest import fixture
from pytest_httpx import to_response

from firebolt.async_db.cursor import JSON_OUTPUT_FORMAT, ColType, Column
from firebolt.common.settings import Settings
Expand Down Expand Up @@ -115,7 +114,7 @@ def do_query(request: Request, **kwargs) -> Response:
"scanned_bytes_storage": 0,
},
}
return to_response(status_code=codes.OK, json=query_response)
return Response(status_code=codes.OK, json=query_response)

return do_query

Expand Down Expand Up @@ -147,7 +146,7 @@ def do_query(request: Request, **kwargs) -> Response:
"scanned_bytes_storage": 0,
},
}
return to_response(status_code=codes.OK, json=query_response)
return Response(status_code=codes.OK, json=query_response)

return do_query

Expand All @@ -157,7 +156,7 @@ def insert_query_callback(
query_description: List[Column], query_data: List[List[ColType]]
) -> Callable:
def do_query(request: Request, **kwargs) -> Response:
return to_response(status_code=codes.OK, headers={"content-length": "0"})
return Response(status_code=codes.OK, headers={"content-length": "0"})

return do_query

Expand All @@ -174,7 +173,7 @@ def set_params() -> Dict:
@fixture
def query_url(settings: Settings, db_name: str) -> str:
return URL(
f"https://{settings.server}?database={db_name}"
f"https://{settings.server}/?database={db_name}"
f"&output_format={JSON_OUTPUT_FORMAT}"
)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/db/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_cursor_execute_error(
httpx_mock.add_callback(auth_callback, url=auth_url)

# Internal httpx error
def http_error(**kwargs):
def http_error(*args, **kwargs):
raise StreamError("httpx error")

httpx_mock.add_callback(http_error, url=query_url)
Expand All @@ -199,7 +199,7 @@ def http_error(**kwargs):
# Database query error
httpx_mock.add_response(
status_code=codes.INTERNAL_SERVER_ERROR,
data="Query error message",
content="Query error message",
url=query_url,
)
with raises(OperationalError) as excinfo:
Expand Down
31 changes: 15 additions & 16 deletions tests/unit/service/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

import httpx
import pytest
from pytest_httpx import to_response
from pytest_httpx._httpx_internals import Response
from httpx import Response

from firebolt.common.settings import Settings
from firebolt.common.urls import (
Expand Down Expand Up @@ -83,7 +82,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == provider_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json=list_to_paginated_response(mock_providers),
)
Expand All @@ -103,7 +102,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == region_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json=list_to_paginated_response(mock_regions),
)
Expand All @@ -123,7 +122,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == instance_type_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json=list_to_paginated_response(mock_instance_types),
)
Expand All @@ -143,7 +142,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == engine_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json={"engine": mock_engine.dict()},
)
Expand All @@ -165,7 +164,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == account_engine_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json={"engine": mock_engine.dict()},
)
Expand Down Expand Up @@ -205,7 +204,7 @@ def do_mock(
mock_database.description = database_properties["description"]

assert request.url == databases_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json={"database": mock_database.dict()},
)
Expand All @@ -218,7 +217,7 @@ def databases_get_callback(databases_url: str, mock_database) -> Callable:
def get_databases_callback_inner(
request: httpx.Request = None, **kwargs
) -> Response:
return to_response(
return Response(
status_code=httpx.codes.OK, json={"edges": [{"node": mock_database.dict()}]}
)

Expand All @@ -239,7 +238,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == database_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json={"database": mock_database.dict()},
)
Expand All @@ -254,7 +253,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == database_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json={},
)
Expand All @@ -276,7 +275,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == database_get_by_name_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json={"database_id": {"database_id": mock_database.database_id}},
)
Expand All @@ -300,7 +299,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == database_get_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json={"database": mock_database.dict()},
)
Expand Down Expand Up @@ -335,7 +334,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == bindings_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json=list_to_paginated_response([binding]),
)
Expand All @@ -350,7 +349,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == bindings_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json=list_to_paginated_response([]),
)
Expand All @@ -374,7 +373,7 @@ def do_mock(
**kwargs,
) -> Response:
assert request.url == create_binding_url
return to_response(
return Response(
status_code=httpx.codes.OK,
json={"binding": binding.dict()},
)
Expand Down