Skip to content

Commit

Permalink
Merge pull request #93 from amosproj/#84-Fix-broken-API-test
Browse files Browse the repository at this point in the history
#84: Fix API bug
  • Loading branch information
mollle authored Dec 4, 2024
2 parents cf040b0 + 36f377c commit f1e99ac
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def filter(self) -> DataFrame:
tolerance_in_ms = None
if self.tolerance is not None:
tolerance_in_ms = self.get_time_delta(self.tolerance).total_seconds() * 1000
print(tolerance_in_ms)

time_delta_in_ms = self.get_time_delta(self.interval).total_seconds() * 1000

Expand Down
18 changes: 9 additions & 9 deletions tests/api/v1/test_api_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
RawResponse,
)
from pandas.io.json import build_table_schema
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport, ASGITransport
from src.api.v1 import app
from src.api.v1.common import json_response_batch
from src.sdk.python.rtdip_sdk.queries.time_series import batch
Expand Down Expand Up @@ -87,7 +87,7 @@ async def test_api_batch_single_get_success(mocker: MockerFixture):
mock_lookup = "src.api.v1.batch.lookup_before_get"
mocked_lookup_before_get = mocker.patch(mock_lookup, return_value=None)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -175,7 +175,7 @@ async def test_api_batch_single_get_success_with_lookup(mocker: MockerFixture):
mock_lookup = "src.api.v1.batch.lookup_before_get"
mocked_lookup_before_get = mocker.patch(mock_lookup, return_value=test_data)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -255,7 +255,7 @@ async def test_api_batch_single_post_success(mocker: MockerFixture):
# Make a surveillance batch method reference to check if called and what args with
surveillance_batch = mocker.patch(mock_method, return_value=mock_method_return_data)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -300,7 +300,7 @@ async def test_api_batch_single_get_unsupported_route_error(mocker: MockerFixtur
os.environ, {"DATABRICKS_SERVING_ENDPOINT": MOCK_MAPPING_ENDPOINT_URL}
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -343,7 +343,7 @@ async def test_api_batch_single_post_missing_body_error(mocker: MockerFixture):
os.environ, {"DATABRICKS_SERVING_ENDPOINT": MOCK_MAPPING_ENDPOINT_URL}
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -406,7 +406,7 @@ async def test_api_batch_multiple_success(mocker: MockerFixture):
# Make a surveillance batch method reference to check if called and what args with
surveillance_batch = mocker.patch(mock_method, side_effect=mock_patch_side_effect)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -464,7 +464,7 @@ async def test_api_batch_one_success_one_fail(mocker: MockerFixture):
os.environ, {"DATABRICKS_SERVING_ENDPOINT": MOCK_MAPPING_ENDPOINT_URL}
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -515,7 +515,7 @@ async def test_api_batch_one_success_one_fail(mocker: MockerFixture):
os.environ, {"DATABRICKS_SERVING_ENDPOINT": MOCK_MAPPING_ENDPOINT_URL}
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down
21 changes: 11 additions & 10 deletions tests/api/v1/test_api_circular_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import os
import pytest
from fastapi import FastAPI
from pytest_mock import MockerFixture
import pandas as pd
from datetime import datetime, timezone
Expand All @@ -30,7 +31,7 @@
MOCK_TAG_MAPPING_EMPTY,
MOCK_MAPPING_ENDPOINT_URL,
)
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport, ASGITransport
from src.api.v1 import app

MOCK_METHOD = "src.sdk.python.rtdip_sdk.queries.time_series.circular_average.get"
Expand All @@ -42,7 +43,7 @@
async def test_api_circular_average_get_success(mocker: MockerFixture, api_test_data):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -59,7 +60,7 @@ async def test_api_circular_average_get_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -82,7 +83,7 @@ async def test_api_circular_average_get_error(mocker: MockerFixture, api_test_da
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -97,7 +98,7 @@ async def test_api_circular_average_get_error(mocker: MockerFixture, api_test_da
async def test_api_circular_average_post_success(mocker: MockerFixture, api_test_data):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -115,7 +116,7 @@ async def test_api_circular_average_post_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -139,7 +140,7 @@ async def test_api_circular_average_post_error(mocker: MockerFixture, api_test_d
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -182,7 +183,7 @@ async def test_api_circular_average_get_lookup_success(mocker: MockerFixture):
modified_param_dict = CIRCULAR_AVERAGE_MOCKED_PARAMETER_DICT.copy()
del modified_param_dict["business_unit"]

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.get(
MOCK_API_NAME, headers=TEST_HEADERS, params=modified_param_dict
)
Expand Down Expand Up @@ -228,7 +229,7 @@ async def test_api_circular_average_post_lookup_success(mocker: MockerFixture):
modified_param_dict = CIRCULAR_AVERAGE_MOCKED_PARAMETER_DICT.copy()
del modified_param_dict["business_unit"]

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -278,7 +279,7 @@ async def test_api_circular_average_get_lookup_no_tag_map_error(mocker: MockerFi
modified_param_dict["tagname"] = ["NonExistentTag"]
del modified_param_dict["business_unit"]

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
actual = await ac.get(
MOCK_API_NAME, headers=TEST_HEADERS, params=modified_param_dict
)
Expand Down
14 changes: 7 additions & 7 deletions tests/api/v1/test_api_circular_standard_deviation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
TEST_HEADERS,
BASE_URL,
)
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport
from src.api.v1 import app

MOCK_METHOD = (
Expand All @@ -41,7 +41,7 @@ async def test_api_circular_standard_deviation_get_success(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -58,7 +58,7 @@ async def test_api_circular_standard_deviation_get_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -83,7 +83,7 @@ async def test_api_circular_standard_deviation_get_error(
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -100,7 +100,7 @@ async def test_api_circular_standard_deviation_post_success(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -118,7 +118,7 @@ async def test_api_circular_standard_deviation_post_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -144,7 +144,7 @@ async def test_api_circular_standard_deviation_post_error(
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down
14 changes: 7 additions & 7 deletions tests/api/v1/test_api_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
TEST_HEADERS,
BASE_URL,
)
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport, ASGITransport
from src.api.v1 import app

MOCK_METHOD = "src.sdk.python.rtdip_sdk.queries.time_series.interpolate.get"
Expand All @@ -37,7 +37,7 @@
async def test_api_interpolate_get_success(mocker: MockerFixture, api_test_data):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -54,7 +54,7 @@ async def test_api_interpolate_get_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -77,7 +77,7 @@ async def test_api_interpolate_get_error(mocker: MockerFixture, api_test_data):
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -92,7 +92,7 @@ async def test_api_interpolate_get_error(mocker: MockerFixture, api_test_data):
async def test_api_interpolate_post_success(mocker: MockerFixture, api_test_data):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -110,7 +110,7 @@ async def test_api_interpolate_post_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -134,7 +134,7 @@ async def test_api_interpolate_post_error(mocker: MockerFixture, api_test_data):
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down
14 changes: 7 additions & 7 deletions tests/api/v1/test_api_interpolation_at_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
TEST_HEADERS,
BASE_URL,
)
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport
from src.api.v1 import app

MOCK_METHOD = "src.sdk.python.rtdip_sdk.queries.time_series.interpolation_at_time.get"
Expand All @@ -38,7 +38,7 @@ async def test_api_interpolation_at_time_get_success(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -57,7 +57,7 @@ async def test_api_interpolation_at_time_get_success(
# )
# mocker = mocker_setup(mocker, MOCK_METHOD, test_data)

# async with AsyncClient(app=app, base_url=BASE_URL) as ac:
# async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
# response = await ac.get(
# MOCK_API_NAME,
# headers=TEST_HEADERS,
Expand All @@ -82,7 +82,7 @@ async def test_api_interpolation_at_time_get_error(
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -99,7 +99,7 @@ async def test_api_interpolation_at_time_post_success(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -119,7 +119,7 @@ async def test_api_interpolation_at_time_post_success(
# )
# mocker = mocker_setup(mocker, MOCK_METHOD, test_data)

# async with AsyncClient(app=app, base_url=BASE_URL) as ac:
# async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
# response = await ac.post(
# MOCK_API_NAME,
# headers=TEST_HEADERS,
Expand All @@ -145,7 +145,7 @@ async def test_api_interpolation_at_time_post_error(
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down
Loading

0 comments on commit f1e99ac

Please sign in to comment.