Skip to content

Commit

Permalink
add test about metrics API
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvaro Vega committed Jan 12, 2017
1 parent 507d851 commit f3d3a26
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions src/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down Expand Up @@ -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()

0 comments on commit f3d3a26

Please sign in to comment.