def initialize(self, test_class): """Initialize the test runner. * Generates the test object for the given class. * Generates the test run data and links it to the test object. Args: test_class (type): test class inheriting from :class:`rotest.core.case.TestCase` or :class:`rotest.core.suite.TestSuite`. """ core_log.debug('Generating run data for %r', self.run_name) run_data = RunData(run_name=self.run_name, run_delta=self.run_delta) core_log.debug("Creating resource client") self.resource_manager = self.create_resource_manager() core_log.debug('Creating test object for %r', test_class.get_name()) self.test_item = test_class( run_data=run_data, config=self.config, skip_init=self.skip_init, save_state=self.save_state, enable_debug=self.enable_debug, resource_manager=self.resource_manager) run_data.main_test = self.test_item.data
def test_update_resources(self): """Test that the update_resources method updates the test's data.""" MockTestSuite.components = (SuccessCase,) run_data = RunData(run_name=None) main_test = MockTestSuite(run_data=run_data) test_case = next(iter(main_test)) test_case.locked_resources = {'test_resource': DemoResource( data=DemoResourceData.objects.get(name='available_resource1'))} self.client.start_test_run(main_test) self.client.start_test(test_case) self.client.update_resources(test_case) test_data = CaseData.objects.get(name=test_case.data.name) self.assertEqual(test_data.resources.count(), len(test_case.locked_resources), "Wrong resources count, (expected resources %r, " "actual resources %r)" % (test_case.locked_resources.values(), test_data.resources.all())) for resource in test_case.locked_resources.itervalues(): self.assertEqual( test_data.resources.filter(name=resource.name).count(), 1, "Resource %r wasn't found in %r" % (resource.name, test_data.resources.all()))
def test_add_result(self): """Test that the add_result method updates the test's data. This test simulates the workflow of running a test in server side: * Start a case and a case. * Assert that the result values are not yet set. * Stop the test and add a result. * Assert that the case's and case's results are as expected. """ MockTestSuite.components = (SuccessCase,) run_data = RunData(run_name=None) main_test = MockTestSuite(run_data=run_data) test_case = next(iter(main_test)) # Simulate starting the test. self.client.start_test_run(main_test) self.client.start_composite(main_test) self.client.start_test(test_case) # Check that the results are still None. self._validate_test_result(main_test, success=None) self._validate_test_result(test_case, success=None, error_tuple=(None, '')) # Simulate ending the test. self.client.stop_test(test_case) ERROR_STRING = 'test error' self.client.add_result(test_case, TestOutcome.ERROR, ERROR_STRING) self.client.stop_composite(main_test) # Check that the results are updated. self._validate_test_result(test_case, success=False, error_tuple=(TestOutcome.ERROR, ERROR_STRING)) self._validate_test_result(main_test, success=False)
def test_start_composite(self): """Test that the start_composite method starts the test's data.""" MockTestSuite.components = (SuccessCase,) run_data = RunData(run_name=None) main_test = MockTestSuite(run_data=run_data) self.client.start_test_run(main_test) self._validate_has_times(main_test, start_time=False) self.client.start_composite(main_test) self._validate_has_times(main_test, start_time=True)
def test_stop_test(self): """Test that the stop_test method ends the test's data.""" MockTestSuite.components = (SuccessCase,) run_data = RunData(run_name=None) main_test = MockTestSuite(run_data=run_data) test_case = next(iter(main_test)) self.client.start_test_run(main_test) self._validate_has_times(test_case, start_time=False, end_time=False) self.client.start_test(test_case) self._validate_has_times(test_case, start_time=True, end_time=False) self.client.stop_test(test_case) self._validate_has_times(test_case, start_time=True, end_time=True)
def test_tree_building(self): """Test that the manager can build the tests' tree properly.""" MockSuite1.components = (MockSuite2, MockTestSuite) MockSuite2.components = (MockCase, MockCase1, MockCase2) MockTestSuite.components = (SuccessCase,) run_data = RunData(run_name='test_run_name') main_test = MockSuite1(run_data=run_data) self.client.start_test_run(main_test) self._validate_tests_tree(main_test) try: db_run_data = RunData.objects.get() except RunData.DoesNotExist: self.fail("DB instance of the run data wasn't created") self.assertEqual(db_run_data.run_name, run_data.run_name)
def setUp(self): """Create a run data the enabled running in delta mode.""" super(TestRunDelta, self).setUp() self.run_data = RunData(run_delta=True)