diff options
author | 2017-03-23 05:30:10 +0000 | |
---|---|---|
committer | 2017-03-23 05:30:10 +0000 | |
commit | 974c15413a468eba0583538684fb526a49121267 (patch) | |
tree | a0b5f6ff85fd83fef510d75cb3dfc0a26c285026 /tests/unit/api | |
parent | 0f3cd47f142d94508419bb675119bce2cf08194c (diff) | |
parent | bef693f40ad87170b7233b9fef62f2fd8abfc8d8 (diff) |
Merge "Add unit tests for List and get in API."
Diffstat (limited to 'tests/unit/api')
-rw-r--r-- | tests/unit/api/conftest.py | 22 | ||||
-rw-r--r-- | tests/unit/api/metric_controller_test.py | 37 | ||||
-rw-r--r-- | tests/unit/api/plan_controller_test.py | 49 | ||||
-rw-r--r-- | tests/unit/api/qpi_controller_test.py | 43 |
4 files changed, 151 insertions, 0 deletions
diff --git a/tests/unit/api/conftest.py b/tests/unit/api/conftest.py new file mode 100644 index 00000000..23a3be82 --- /dev/null +++ b/tests/unit/api/conftest.py @@ -0,0 +1,22 @@ +############################################################################## +# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import pytest + +from qtip.api import __main__ + + +@pytest.fixture(scope="session") +def app(): + return __main__.get_app().app + + +@pytest.fixture(scope="session") +def app_client(app): + return app.test_client() diff --git a/tests/unit/api/metric_controller_test.py b/tests/unit/api/metric_controller_test.py new file mode 100644 index 00000000..caba7972 --- /dev/null +++ b/tests/unit/api/metric_controller_test.py @@ -0,0 +1,37 @@ +############################################################################## +# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import httplib +import json + +from qtip.base.constant import BaseProp + + +def test_get_list_metrics(app_client): + response_success = app_client.get("/v1.0/metrics") + assert response_success.status_code == httplib.OK + metric_list = json.loads(response_success.data)['metrics'] + assert len(metric_list) > 0 + assert metric_list[0].endswith('.yaml') + + +def test_get_metric(app_client): + response_success = app_client.get("/v1.0/metrics/dpi.yaml") + assert response_success.status_code == httplib.OK + metric_data = json.loads(response_success.data) + assert BaseProp.NAME in metric_data + assert BaseProp.WORKLOADS in metric_data + assert isinstance(metric_data[BaseProp.WORKLOADS], list) + + +def test_get_metric_not_found(app_client): + response_not_found = app_client.get("/v1.0/metrics/fake.yaml") + response_data = json.loads(response_not_found.data) + assert response_not_found.status_code == httplib.NOT_FOUND + assert response_data['title'] == "Metric not found" diff --git a/tests/unit/api/plan_controller_test.py b/tests/unit/api/plan_controller_test.py new file mode 100644 index 00000000..136bd3c6 --- /dev/null +++ b/tests/unit/api/plan_controller_test.py @@ -0,0 +1,49 @@ +############################################################################## +# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import httplib +import json + + +from qtip.loader.plan import PlanProp + + +def test_invalid_url(app_client): + response_url_not_found = app_client.get("/v1.0/fakeresource") + assert response_url_not_found.status_code == httplib.NOT_FOUND + + +def test_get_list_plans(app_client): + response_success = app_client.get("/v1.0/plans") + assert response_success.status_code == httplib.OK + plan_list = json.loads(response_success.data)['plans'] + assert len(plan_list) > 0 + assert plan_list[0].endswith('.yaml') + + +def test_get_plan(app_client): + response_success = app_client.get("/v1.0/plans/sample.yaml") + assert response_success.status_code == httplib.OK + plan_data = json.loads(response_success.data) + assert PlanProp.NAME in plan_data + assert PlanProp.DESCRIPTION in plan_data + assert PlanProp.CONFIG in plan_data + assert PlanProp.QPIS in plan_data + + +def test_get_plan_not_found(app_client): + response_not_found = app_client.get("/v1.0/plans/fake.yaml") + response_data = json.loads(response_not_found.data) + assert response_not_found.status_code == httplib.NOT_FOUND + assert response_data['title'] == "Plan not found" + + +def test_runner_not_implemented(app_client): + response_error = app_client.post("/v1.0/plans/fake.yaml?action=run", follow_redirects=False) + assert response_error.status_code == httplib.NOT_IMPLEMENTED diff --git a/tests/unit/api/qpi_controller_test.py b/tests/unit/api/qpi_controller_test.py new file mode 100644 index 00000000..6291dd9b --- /dev/null +++ b/tests/unit/api/qpi_controller_test.py @@ -0,0 +1,43 @@ +############################################################################## +# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import httplib +import json + +from qtip.base.constant import FormulaName +from qtip.base.constant import SpecProp + + +def test_get_list_qpis(app_client): + response_success = app_client.get("/v1.0/qpis") + assert response_success.status_code == httplib.OK + qpi_spec_list = json.loads(response_success.data)['qpis'] + assert len(qpi_spec_list) > 0 + assert qpi_spec_list[0].endswith('.yaml') + + +def test_get_qpi(app_client): + response_success = app_client.get("/v1.0/qpis/compute.yaml") + assert response_success.status_code == httplib.OK + qpi_data = json.loads(response_success.data) + assert SpecProp.DESCRIPTION in qpi_data + assert SpecProp.FORMULA in qpi_data + assert SpecProp.SECTIONS in qpi_data + assert qpi_data[SpecProp.FORMULA] in FormulaName.__dict__.values() + sections = qpi_data[SpecProp.SECTIONS] + assert isinstance(sections, list) + for section in sections: + assert SpecProp.NAME in section + + +def test_get_qpi_not_found(app_client): + response_not_found = app_client.get("/v1.0/qpis/fake.yaml") + response_data = json.loads(response_not_found.data) + assert response_not_found.status_code == httplib.NOT_FOUND + assert response_data['title'] == "QPI not found" |