From f3d3a262978f8e8d7a1326fe3a5ada551288244d Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 12 Jan 2017 12:03:50 +0100 Subject: [PATCH] add test about metrics API --- README.md | 2 +- src/tests/api/test_api.py | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d9b15db..4c849084 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ A tipical scenario for IoT Platform can be [scenario_test](https://pdihub.hi.ine - Assign/unassign roles to users in a service - Create/List Trust Tokens - Activate / deactivate IoT Modules -- Retrieve statistics about API usage +- Retrieve statistics and metrics about API usage Orchestrator is based mainly on: - Python diff --git a/src/tests/api/test_api.py b/src/tests/api/test_api.py index 42ccb861..f43d3175 100644 --- a/src/tests/api/test_api.py +++ b/src/tests/api/test_api.py @@ -3259,7 +3259,49 @@ def test_change_log_level_bad(self): assert res.code == 400, (res.code, res.msg, res.raw_json) +class Test_Metrics_RestView(object): + def __init__(self): + self.suffix = str(uuid.uuid4())[:8] + self.TestRestOps = TestRestOperations(PROTOCOL=ORC_PROTOCOL, + HOST=ORC_HOST, + PORT=ORC_PORT) + + def test_get_metrics_ok(self): + res = self.TestRestOps.rest_request(method="GET", + url="/v1.0/admin/metrics", + json_data=True, + auth_token=None, + data=None) + assert res.code == 200, (res.code, res.msg, res.raw_json) + response = res.read() + json_body_response = json.loads(response) + assert "service" in json_body_response + assert "sum" in json_body_response + + def test_get_and_reset_metrics_ok(self): + res = self.TestRestOps.rest_request(method="GET", + url="/v1.0/admin/metrics?reset=true", + json_data=True, + auth_token=None, + data=None) + assert res.code == 200, (res.code, res.msg, res.raw_json) + response = res.read() + json_body_response = json.loads(response) + assert "service" in json_body_response + assert "sum" in json_body_response + + def test_reset_metrics_ok(self): + res = self.TestRestOps.rest_request(method="DELETE", + url="/v1.0/admin/metrics", + json_data=True, + auth_token=None, + data=None) + assert res.code == 204, (res.code, res.msg, res.raw_json) + response = res.read() + json_body_response = json.loads(response) + assert "service" in json_body_response + assert "sum" in json_body_response if __name__ == '__main__': @@ -3401,3 +3443,8 @@ def test_change_log_level_bad(self): test_LogLevel = Test_LogLevel_RestView() test_LogLevel.test_change_log_level_ok() test_LogLevel.test_change_log_level_bad() + + test_Metrics = Test_Metrics_RestView() + test_Metrics.test_get_metrics_ok() + test_Metrics.test_get_and_reset_metrics_ok() + test_Metrics.test_reset_metrics_ok()