def test_run_model_taskrunner_error(self): mock_taskrunner = MockTaskRunnerError() hub = Hub("example_sw_product", 111, image="image") hub._taskrunner = mock_taskrunner publisher = PublisherStub(*[None]*4) hub._publishers._publishers.append(publisher) hub.run() self.assertTrue(isinstance(publisher.exception, OTSException))
def test_run_results_missing(self): mock_taskrunner = MockTaskRunnerResultsMissing() hub = Hub("example_sw_product", 111, image="image") hub._taskrunner = mock_taskrunner publisher = PublisherStub(*[None]*4) hub._publishers._publishers.append(publisher) hub.run() self.assertTrue(isinstance(publisher.exception, PackageException))
def test_no_image(self): mock_taskrunner = MockTaskRunnerResultsPass() hub = Hub("example_sw_product", 111) hub._taskrunner = mock_taskrunner ret_val = hub.run() testrun_id = hub.testrun_uuid self.assert_has_latest(testrun_id) content = self.get_log_content(testrun_id) string = "Missing `image` parameter" self.assert_log_contains_string(content, testrun_id, string)
def test_non_existent_sw_product(self): mock_taskrunner = MockTaskRunnerResultsPass() hub = Hub("None", 111, image="image") hub._taskrunner = mock_taskrunner ret_val = hub.run() testrun_id = hub.testrun_uuid self.assert_has_latest(testrun_id) content = self.get_log_content(testrun_id) string = "not found in sw products" self.assert_log_contains_string(content, testrun_id, string)
def demo(image): """ A Demo that run the full tool chain downstream of the hub @type: C{str} @param: The image url """ options_dict["image"] = image hub = Hub("example_sw_product", 1111, **options_dict) hub.run()
def test_fail_run(self): mock_taskrunner = MockTaskRunnerResultsFail() hub = Hub("example_sw_product", 111, image="image") hub._taskrunner = mock_taskrunner ret_val = hub.run() testrun_id = hub.testrun_uuid self.assert_has_latest(testrun_id) content = self.get_log_content(testrun_id) string = "Testrun finished with result: FAIL" self.assert_log_contains_string(content, testrun_id, string)
def test_run_global_timeout(self): #Not really a test more an illustration of behaviour mock_taskrunner = MockTaskRunnerTimeout() hub = Hub("example_sw_product", 111, image="image") hub._taskrunner = mock_taskrunner publisher = PublisherStub(*[None]*4) hub._publishers._publishers.append(publisher) hub.run() self.assertTrue(isinstance(publisher.exception, OtsExecutionTimeoutError))
def demo(): """ A rough and ready demo """ taskrunner = taskrunner_factory("foo", 2, 1) taskrunner.add_task(["sleep", "1"]) taskrunner.add_task(["echo", "hello world"]) hub = Hub("example_sw_product", 1111, **options_dict) hub._taskrunner = taskrunner hub.run()
def test_timeout(self): mock_taskrunner = MockTaskRunnerTimeout() hub = Hub("example_sw_product", 111, image="image") hub._taskrunner = mock_taskrunner ret_val = hub.run() testrun_id = hub.testrun_uuid self.assert_has_latest(testrun_id) content = self.get_log_content(testrun_id) self.assertTrue(has_errors(content, testrun_id)) string = "Result set to ERROR" self.assertTrue(has_message(content, testrun_id, string))
def run(parent, text): """ Run a Stubbed Testrunner on the Hub @type parent : C{QWidget} @param parent : The Parent Widget @type text : C{str} @param text : Demonstrate extension of API """ mock_taskrunner = MockTaskRunnerResultsPass() options_dict["parent"] = parent options_dict["text"] = text hub = Hub("example_sw_product", 111, **options_dict) #The taskrunner is replaced by the Mock here! hub._taskrunner = mock_taskrunner print "Result", hub.run()
def _run_hub(queue, sw_product, request_id, options_dict): """ Function to run a hub and save the testrun result to queue. @param queue: Process queue @type queue: C{multiprocess.Queue} @param sw_product: Software product @type sw_product: C{str} @param request_id: request ID @type request_id: C{str} @param options_dict: Options dictionary for Hub @type options_dict: C{dict} """ hub = Hub(sw_product, request_id, **options_dict) result = hub.run() queue.put({hub.testrun_uuid : result})
def test_run_results_fail(self): mock_taskrunner = MockTaskRunnerResultsFail() hub = Hub("example_sw_product", 111, image="image") hub._taskrunner = mock_taskrunner ret_val = hub.run() self.assertFalse(ret_val.wasSuccessful())