Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test tests #5607

Merged
merged 2 commits into from
Oct 25, 2023
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
18 changes: 18 additions & 0 deletions openbb_platform/extensions/ta/integration/test_ta_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,24 @@ def test_ta_adx(params, data_type, obb):
assert len(result.results) > 0


@pytest.mark.parametrize(
"params, data_type",
[
({"data": "", "index": "", "offset": ""}, "stocks"),
({"data": "", "index": "date", "offset": "5"}, "crypto"),
],
)
@pytest.mark.integration
def test_ta_ad(params, data_type, obb):
params = {p: v for p, v in params.items() if v}
params["data"] = get_data(data_type)

result = obb.ta.ad(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@pytest.mark.parametrize(
"params, data_type",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from extensions.tests.utils.integration_tests_testers import (
check_missing_integration_test_params,
check_missing_integration_test_providers,
check_missing_integration_tests,
check_wrong_integration_test_params,
get_integration_tests,
get_module_functions,
Expand Down Expand Up @@ -51,3 +52,9 @@ def test_charting_extension_function_coverage() -> None:
]

assert missing_items == [], "\n".join(missing_items)


def test_missing_api_integration_tests() -> None:
"""Check if there are missing tests."""
missing = check_missing_integration_tests(test_type="api")
assert not missing, "\n".join(missing)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from extensions.tests.utils.integration_tests_testers import (
check_missing_integration_test_params,
check_missing_integration_test_providers,
check_missing_integration_tests,
check_wrong_integration_test_params,
get_integration_tests,
get_module_functions,
Expand Down Expand Up @@ -51,3 +52,9 @@ def test_charting_extension_function_coverage() -> None:
]

assert missing_items == [], "\n".join(missing_items)


def test_missing_api_integration_tests() -> None:
"""Check if there are missing tests."""
missing = check_missing_integration_tests(test_type="python")
assert not missing, "\n".join(missing)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Generate API integration tests."""
import argparse
import os
from typing import Dict, List, Literal, Type, get_type_hints
Expand Down Expand Up @@ -25,7 +26,6 @@ def get_post_flat_params(hints: Dict[str, Type]):

def write_init_test_template(http_method: str, path: str):
"""Write some common initialization for the tests with the defined template."""

http_template_imports = {"get": "", "post": "import json"}
template = http_template_imports[http_method]
template += """
Expand Down Expand Up @@ -57,7 +57,6 @@ def write_test_w_template(
chart: bool = False,
):
"""Write the test with the defined template."""

params_str = ",\n".join([f"({params})" for params in params_list])

http_template_request = {
Expand Down Expand Up @@ -103,6 +102,7 @@ def test_exists(route: str, path: str):
return route.replace("/", "_")[1:] in f.read()


# pylint: disable=W0621
def write_commands_integration_tests(
command_map: CommandMap,
provider_interface: ProviderInterface,
Expand All @@ -111,11 +111,11 @@ def write_commands_integration_tests(
"""Write the commands integration tests."""
commands_not_found = []

commandmap_map = command_map.map
commandmap_models = command_map.commands_model
cm_map = command_map.map
cm_models = command_map.commands_model
provider_interface_map = provider_interface.map

for route in commandmap_map:
for route in cm_map:
http_method = get_http_method(api_paths, f"/api/v1{route}")

menu = route.split("/")[1]
Expand All @@ -128,15 +128,15 @@ def write_commands_integration_tests(
if not http_method:
commands_not_found.append(route)
else:
hints = get_type_hints(commandmap_map[route])
hints = get_type_hints(cm_map[route])
hints.pop("cc", None)
hints.pop("return", None)

params_list = (
[{k: "" for k in get_post_flat_params(hints)}]
if http_method == "post"
else get_test_params(
model_name=commandmap_models[route],
model_name=cm_models[route],
provider_interface_map=provider_interface_map,
)
)
Expand All @@ -154,7 +154,6 @@ def write_commands_integration_tests(

def write_charting_extension_integration_tests():
"""Write the charting extension integration tests."""

functions = ChartingService.get_implemented_charting_functions()

# we assume test file exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,36 @@ def check_integration_tests(
return all_missing_items


def check_missing_integration_tests(test_type: Literal["api", "python"]) -> List[str]:
"""Check if all endpoints have integration tests."""
cm = CommandMap(coverage_sep=".")
routes = [route[1:].replace("/", "_") for route in cm.map]
missing_integration_tests: List[str] = []

if test_type == "api":
functions = get_module_functions(get_integration_tests(test_type="api"))
else:
functions = get_module_functions(get_integration_tests(test_type="python"))

tested_functions = [
function.replace("test_", "")
for function in functions
if function.startswith("test_")
]

for route in routes:
if route not in tested_functions:
# TODO: See how to handle edge cases that are excluded from the schema
# on purpose. This is currently on the econometrics router.
if test_type == "api" and "econometrics" in route:
continue
missing_integration_tests.append(
f"Missing {test_type} integration test for route {route}"
)

return missing_integration_tests


def check_missing_integration_test_providers(functions: Dict[str, Any]) -> List[str]:
"""Check if there are any missing providers for integration tests."""
return check_integration_tests(functions, check_missing_providers)
Expand Down
Loading