diff options
author | zhifeng.jiang <jiang.zhifeng@zte.com.cn> | 2016-08-04 12:14:20 +0800 |
---|---|---|
committer | zhifeng.jiang <jiang.zhifeng@zte.com.cn> | 2016-08-13 11:09:30 +0800 |
commit | 2c78b093d68e901d3f768029b2818f856f74e118 (patch) | |
tree | dab4894b70a2fb9d3078e88c77c6e40ea325caf7 /tests | |
parent | 9197285af7b9ffe49eb22902477c559cef35b43f (diff) |
Add restful server API in QTIP which can be called by Yardstick.
modification:
Add restful server API.
Include needed packages in requirement file.
Add unit tests for restful server api.
JIRA:QTIP-97
Change-Id: I5306d5dd76ee818fef46d0e7b7392f2df2982552
Signed-off-by: zhifeng.jiang <jiang.zhifeng@zte.com.cn>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/qtip_server_test.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/qtip_server_test.py b/tests/qtip_server_test.py new file mode 100644 index 00000000..31aa96dc --- /dev/null +++ b/tests/qtip_server_test.py @@ -0,0 +1,78 @@ +import restful_server.qtip_server as server +import pytest +import json + + +@pytest.fixture +def app(): + return server.app + + +@pytest.fixture +def app_client(app): + client = app.test_client() + return client + + +class TestClass: + @pytest.mark.parametrize("body, expected", [ + ({'installer_type': 'fuel', + 'installer_ip': '10.20.0.2'}, + {'job_id': '', + 'installer_type': 'fuel', + 'installer_ip': '10.20.0.2', + 'pod_name': 'default', + 'suite_name': 'all', + 'deadline': 10, + 'type': 'BM', + 'state': 'processing', + 'state_detail': [], + 'result': []}), + ({'installer_type': 'fuel', + 'installer_ip': '10.20.0.2', + 'pod_name': 'zte-pod1', + 'deadline': 20, + 'suite_name': 'compute', + 'type': 'VM'}, + {'job_id': '', + 'installer_type': 'fuel', + 'installer_ip': '10.20.0.2', + 'pod_name': 'zte-pod1', + 'suite_name': 'compute', + 'deadline': 20, + 'type': 'VM', + 'state': 'processing', + 'state_detail': [], + 'result': []}) + ]) + def test_post_get_delete_job_successful(self, app_client, body, expected): + reply = app_client.post("/api/v1.0/jobs", data=body) + print reply.data + id = json.loads(reply.data)['job_id'] + expected['job_id'] = id + get_reply = app_client.get("/api/v1.0/jobs/%s" % id) + reply_data = json.loads(get_reply.data) + assert len(filter(lambda x: reply_data[x] == expected[x], expected.keys())) == len(expected) + delete_reply = app_client.delete("/api/v1.0/jobs/%s" % id) + assert "successful" in delete_reply.data + + @pytest.mark.parametrize("body, expected", [ + ([{'installer_type': 'fuel', + 'installer_ip': '10.20.0.2'}, + {'installer_type': 'compass', + 'installer_ip': '192.168.20.50'}], + ['job_id', + 'It already has one job running now!']), + ([{'installer_type': 'fuel', + 'installer_ip': '10.20.0.2'}, + {'installer_type': 'compass', + 'insta_ip': '192.168.20.50'}], + ['job_id', + 'Installer_ip is required']) + ]) + def test_post_two_jobs_unsuccessful(self, app_client, body, expected): + reply_1 = app_client.post("/api/v1.0/jobs", data=body[0]) + reply_2 = app_client.post("/api/v1.0/jobs", data=body[1]) + assert expected[0] in json.loads(reply_1.data).keys() + app_client.delete("/api/v1.0/jobs/%s" % json.loads(reply_1.data)['job_id']) + assert expected[1] in json.dumps(reply_2.data) |