-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from database_client.database_client import DatabaseClient | ||
Check warning on line 1 in middleware/primary_resource_logic/metrics_logic.py GitHub Actions / flake8[flake8] middleware/primary_resource_logic/metrics_logic.py#L1 <100>
Raw output
|
||
|
||
|
||
def get_metrics(db_client: DatabaseClient): | ||
Check warning on line 4 in middleware/primary_resource_logic/metrics_logic.py GitHub Actions / flake8[flake8] middleware/primary_resource_logic/metrics_logic.py#L4 <103>
Raw output
|
||
return db_client.get_metrics() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from marshmallow import Schema, fields | ||
Check warning on line 1 in middleware/schema_and_dto_logic/primary_resource_schemas/metrics_schemas.py GitHub Actions / flake8[flake8] middleware/schema_and_dto_logic/primary_resource_schemas/metrics_schemas.py#L1 <100>
Raw output
|
||
|
||
from middleware.schema_and_dto_logic.util import get_json_metadata | ||
|
||
|
||
class MetricsGetResponseSchema(Schema): | ||
Check warning on line 6 in middleware/schema_and_dto_logic/primary_resource_schemas/metrics_schemas.py GitHub Actions / flake8[flake8] middleware/schema_and_dto_logic/primary_resource_schemas/metrics_schemas.py#L6 <101>
Raw output
|
||
source_count = fields.Int(metadata=get_json_metadata("The number of data sources")) | ||
agency_count = fields.Int(metadata=get_json_metadata("The number of agencies")) | ||
county_count = fields.Int(metadata=get_json_metadata("The number of counties")) | ||
state_count = fields.Int(metadata=get_json_metadata("The number of states")) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from flask import Response | ||
|
||
from middleware.access_logic import AccessInfoPrimary, GET_AUTH_INFO | ||
from middleware.decorators import endpoint_info | ||
from middleware.primary_resource_logic.metrics_logic import get_metrics | ||
from resources.PsycopgResource import PsycopgResource | ||
from resources.endpoint_schema_config import SchemaConfigs | ||
from resources.resource_helpers import ResponseInfo | ||
from utilities.namespace import AppNamespaces, create_namespace | ||
|
||
namespace_metrics = create_namespace(AppNamespaces.METRICS) | ||
|
||
|
||
@namespace_metrics.route("") | ||
class Metrics(PsycopgResource): | ||
|
||
@endpoint_info( | ||
namespace=namespace_metrics, | ||
auth_info=GET_AUTH_INFO, | ||
schema_config=SchemaConfigs.METRICS_GET, | ||
description="Returns the metrics for the application.", | ||
response_info=ResponseInfo( | ||
success_message="Returns the metrics for the application." | ||
), | ||
) | ||
def get(self, access_info: AccessInfoPrimary) -> Response: | ||
Check warning on line 26 in resources/Metrics.py GitHub Actions / flake8[flake8] resources/Metrics.py#L26 <102>
Raw output
|
||
return self.run_endpoint( | ||
wrapper_function=get_metrics, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from tests.helper_scripts.helper_classes.TestDataCreatorFlask import ( | ||
Check warning on line 1 in tests/integration/test_metrics.py GitHub Actions / flake8[flake8] tests/integration/test_metrics.py#L1 <100>
Raw output
|
||
TestDataCreatorFlask, | ||
) | ||
from conftest import test_data_creator_flask, monkeysession | ||
Check warning on line 4 in tests/integration/test_metrics.py GitHub Actions / flake8[flake8] tests/integration/test_metrics.py#L4 <401>
Raw output
Check warning on line 4 in tests/integration/test_metrics.py GitHub Actions / flake8[flake8] tests/integration/test_metrics.py#L4 <401>
Raw output
|
||
|
||
|
||
def test_metrics(test_data_creator_flask: TestDataCreatorFlask): | ||
Check warning on line 7 in tests/integration/test_metrics.py GitHub Actions / flake8[flake8] tests/integration/test_metrics.py#L7 <103>
Raw output
Check warning on line 7 in tests/integration/test_metrics.py GitHub Actions / flake8[flake8] tests/integration/test_metrics.py#L7 <811>
Raw output
|
||
|
||
tdc = test_data_creator_flask | ||
metrics = tdc.request_validator.get_metrics( | ||
headers=tdc.get_admin_tus().jwt_authorization_header | ||
) | ||
|
||
assert metrics["source_count"] > 0 | ||
assert metrics["agency_count"] > 0 | ||
assert metrics["county_count"] > 0 | ||
assert metrics["state_count"] > 0 |