diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/qtip_server_test.py | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/tests/qtip_server_test.py b/tests/qtip_server_test.py index c2b12974..3f70a1f6 100644 --- a/tests/qtip_server_test.py +++ b/tests/qtip_server_test.py @@ -1,6 +1,8 @@ import restful_server.qtip_server as server import pytest import json +import mock +import time @pytest.fixture @@ -14,6 +16,14 @@ def app_client(app): return client +def side_effect_sleep(sleep_time): + time.sleep(sleep_time) + + +def side_effect_pass(): + pass + + class TestClass: @pytest.mark.parametrize("body, expected", [ ({'installer_type': 'fuel', @@ -22,11 +32,15 @@ class TestClass: 'installer_type': 'fuel', 'installer_ip': '10.20.0.2', 'pod_name': 'default', - 'suite_name': 'all', - 'max-minutes': 10, + 'suite_name': 'compute', + 'max-minutes': 60, 'type': 'BM', - 'state': 'processing', - 'state_detail': [], + 'state': 'finished', + 'state_detail': [{'state': 'finished', 'benchmark': 'dhrystone_bm.yaml'}, + {'state': 'finished', 'benchmark': 'whetstone_bm.yaml'}, + {'state': 'finished', 'benchmark': 'ramspeed_bm.yaml'}, + {'state': 'finished', 'benchmark': 'dpi_bm.yaml'}, + {'state': 'finished', 'benchmark': 'ssl_bm.yaml'}], 'result': []}), ({'installer_type': 'fuel', 'installer_ip': '10.20.0.2', @@ -41,17 +55,26 @@ class TestClass: 'suite_name': 'compute', 'max-minutes': 20, 'type': 'VM', - 'state': 'processing', - 'state_detail': [], + 'state': 'finished', + 'state_detail': [{u'state': u'finished', u'benchmark': u'dhrystone_vm.yaml'}, + {u'state': u'finished', u'benchmark': u'whetstone_vm.yaml'}, + {u'state': u'finished', u'benchmark': u'ramspeed_vm.yaml'}, + {u'state': u'finished', u'benchmark': u'dpi_vm.yaml'}, + {u'state': u'finished', u'benchmark': u'ssl_vm.yaml'}], 'result': []}) ]) - def test_post_get_delete_job_successful(self, app_client, body, expected): + @mock.patch('restful_server.qtip_server.args_handler.prepare_and_run_benchmark') + def test_post_get_delete_job_successful(self, mock_args_handler, app_client, body, expected): reply = app_client.post("/api/v1.0/jobs", data=body) - print reply.data + 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) + post_process = '' + while post_process != 'finished': + get_reply = app_client.get("/api/v1.0/jobs/%s" % id) + reply_data = json.loads(get_reply.data) + post_process = reply_data['state'] + print(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 @@ -62,15 +85,11 @@ class TestClass: {'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']) + 'It already has one job running now!']) ]) - def test_post_two_jobs_unsuccessful(self, app_client, body, expected): + @mock.patch('restful_server.qtip_server.args_handler.prepare_and_run_benchmark', + side_effect=[side_effect_sleep(0.5), side_effect_pass]) + def test_post_two_jobs_unsuccessful(self, mock_args_hanler, 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() |