class TestRerunJobsPageIntegrationSkippedOnly(BaseTestCase): fixtures = BaseTestCase.fixtures + ["skipped_run"] @classmethod def setUpClass(cls): """Starts external services and sets instrument for all test cases""" super().setUpClass() cls.instrument_name = "TestInstrument" cls.data_archive, cls.queue_client, cls.listener = setup_external_services( cls.instrument_name, 21, 21) cls.data_archive.add_reduction_script( cls.instrument_name, """def main(input_file, output_dir): print('some text')""") cls.data_archive.add_reduce_vars_script( cls.instrument_name, """standard_vars={"variable1":"test_variable_value_123"}""") cls.instrument_name = "TestInstrument" cls.rb_number = 1234567 cls.run_number = 99999 @classmethod def tearDownClass(cls) -> None: """Stops external services.""" cls.queue_client.disconnect() cls.data_archive.delete() super().tearDownClass() def setUp(self) -> None: """Sets up RerunJobsPage before each test case""" super().setUp() self.page = RerunJobsPage(self.driver, self.instrument_name) self.page.launch() def test_submit_rerun_after_clicking_reset_current_script(self): """ Test: Submitting a run after clicking the "Reset to values in the current reduce_vars script" uses the values saved in the current reduce_vars script """ self.page.reset_to_current_values.click() result = submit_and_wait_for_result(self) assert len(result) == 2 assert result[0].run_version == 0 assert result[1].run_version == 1 for run0_var, run1_var in zip(result[0].run_variables.all(), result[1].run_variables.all()): # the value of the variable has been overwritten because it's the same run number assert run0_var.variable == run1_var.variable assert result[1].run_variables.first( ).variable.value == "test_variable_value_123"
class TestRerunJobsPage(NavbarTestMixin, BaseTestCase, FooterTestMixin, AccessibilityTestMixin): """ Test cases for the InstrumentSummary page when the Rerun form is NOT visible """ fixtures = BaseTestCase.fixtures + ["run_with_one_variable"] accessibility_test_ignore_rules = { # https://github.com/ISISScientificComputing/autoreduce/issues/1267 "duplicate-id-aria": "input", } @classmethod def setUpClass(cls): """Sets up DataArchive for all tests and sets instrument for all tests""" super().setUpClass() cls.instrument_name = "TestInstrument" cls.data_archive = DataArchive([cls.instrument_name], 21, 21) cls.data_archive.create() cls.data_archive.add_reduction_script(cls.instrument_name, """print('some text')""") cls.data_archive.add_reduce_vars_script( cls.instrument_name, """standard_vars={"variable1":"test_variable_value_123"}""") @classmethod def tearDownClass(cls) -> None: """Destroys created DataArchive""" cls.data_archive.delete() super().tearDownClass() def setUp(self) -> None: """Set up RerunJobsPage before each test case""" super().setUp() self.page = RerunJobsPage(self.driver, self.instrument_name) self.page.launch() def test_cancel_goes_back_to_runs_list(self): """Tests: Clicking canel button returns the runs list page""" self.page.cancel_button.click() assert reverse("runs:list", kwargs={"instrument": self.instrument_name }) in self.driver.current_url def test_reset_values_does_reset_the_values(self): """Test that the button to reset the variables to the values from the reduce_vars script works""" self.page.variable1_field = "the new value in the field" self.page.reset_to_current_values.click() # need to re-query the driver because resetting replaces the elements var_field = self.page.variable1_field assert var_field.get_attribute("value") == "test_variable_value_123"
class TestRerunJobsRangePageIntegration(BaseTestCase): fixtures = BaseTestCase.fixtures + ["two_runs"] accessibility_test_ignore_rules = { # https://github.com/ISISScientificComputing/autoreduce/issues/1267 "duplicate-id-aria": "input", } @classmethod def setUpClass(cls): """Starts all external services""" super().setUpClass() cls.instrument_name = "TestInstrument" cls.data_archive, cls.queue_client, cls.listener = setup_external_services( cls.instrument_name, 21, 21) cls.data_archive.add_reduction_script( cls.instrument_name, """def main(input_file, output_dir): print('some text')""") cls.data_archive.add_reduce_vars_script( cls.instrument_name, """standard_vars={"variable1":"test_variable_value_123"}""") cls.rb_number = 1234567 cls.run_number = [99999, 100000] @classmethod def tearDownClass(cls) -> None: """Stops all external services""" cls.queue_client.disconnect() cls.data_archive.delete() super().tearDownClass() def setUp(self) -> None: """Sets up and launches RerunJobsPage before each test case""" super().setUp() self.page = RerunJobsPage(self.driver, self.instrument_name) self.page.launch() def _verify_runs_exist_and_have_variable_value(self, variable_value): """ Verifies that the run with version 1 exists and has the expected value """ def make_run_url(run_number): """Constructs the url of the run summary with a django reverse""" return reverse("runs:summary", kwargs={ "instrument_name": self.instrument_name, "run_number": run_number, "run_version": 1 }) runs_list_page = RunsListPage(self.driver, self.instrument_name) for run in self.run_number: runs_list_page.launch() run_number_v1 = self.driver.find_element_by_css_selector( f'[href*="{make_run_url(run)}"]') assert run_number_v1.is_displayed() assert RunSummaryPage( self.driver, self.instrument_name, run, 1).launch().variable1_field_val == variable_value vars_for_run_v1 = InstrumentVariable.objects.filter(start_run=run) for var in vars_for_run_v1: assert var.value == variable_value def test_run_range_default_variable_value(self): """ Test setting a run range with the default variable value """ assert not self.page.form_validation_message.is_displayed() expected_run = "99999-100000" self.page.run_range_field = expected_run result = submit_and_wait_for_result(self, expected_runs=2) expected_url = reverse("run_confirmation", kwargs={"instrument": self.instrument_name}) assert expected_url in self.driver.current_url assert len(result) == 4 self._verify_runs_exist_and_have_variable_value("value2") def test_run_range_new_variable_value(self): """ Test setting a run range with a new variable value """ expected_run = "99999-100000" self.page.run_range_field = expected_run new_value = "some_new_value" self.page.variable1_field = new_value result = submit_and_wait_for_result(self, expected_runs=2) expected_url = reverse("run_confirmation", kwargs={"instrument": self.instrument_name}) assert expected_url in self.driver.current_url assert len(result) == 4 self._verify_runs_exist_and_have_variable_value(new_value)
class TestRerunJobsPageIntegrationMultiVar(BaseTestCase, NavbarTestMixin, FooterTestMixin, AccessibilityTestMixin): fixtures = BaseTestCase.fixtures + ["run_with_multiple_variables"] accessibility_test_ignore_rules = { # https://github.com/ISISScientificComputing/autoreduce/issues/1267 "duplicate-id-aria": "input", } @classmethod def setUpClass(cls): """Starts external services and sets instrument for all test cases""" super().setUpClass() cls.instrument_name = "TestInstrument" cls.data_archive, cls.queue_client, cls.listener = setup_external_services( cls.instrument_name, 21, 21) cls.data_archive.add_reduction_script(cls.instrument_name, SCRIPT) cls.data_archive.add_reduce_vars_script( cls.instrument_name, """standard_vars={"variable_str":"test_variable_value_123", "variable_int":123, "variable_float":123.321, "variable_listint":[1,2,3], "variable_liststr":["a","b","c"], "variable_none":None, "variable_empty":"", "variable_bool":True}""" ) cls.instrument_name = "TestInstrument" cls.rb_number = 1234567 cls.run_number = 99999 @classmethod def tearDownClass(cls) -> None: """Stops external services.""" cls.queue_client.disconnect() cls.data_archive.delete() super().tearDownClass() def setUp(self) -> None: """Sets up RerunJobsPage before each test case""" super().setUp() self.page = RerunJobsPage(self.driver, self.instrument_name) self.page.launch() def test_variables_appear_as_expected(self): """ Test: Just opening the submit page and clicking rerun """ assert self.page.variable_str_field_val == "value1" assert self.page.variable_int_field_val == "123" assert self.page.variable_float_field_val == "123.321" assert self.page.variable_listint_field_val == "[1, 2, 3]" assert self.page.variable_liststr_field_val == "['a', 'b', 'c']" assert self.page.variable_none_field_val == "None" assert self.page.variable_bool_field_val == "True" def test_submit_rerun_same_variables(self): """ Test: Just opening the submit page and clicking rerun """ result = submit_and_wait_for_result(self) assert len(result) == 2 assert result[0].run_version == 0 assert result[1].run_version == 1 for run0_var, run1_var in zip(result[0].run_variables.all(), result[1].run_variables.all()): assert run0_var.variable == run1_var.variable def test_submit_rerun_changed_variable_arbitrary_value(self): """ Test: Open submit page, change a variable, submit the run """ new_str_value = "the new value in the field" self.page.variable_str_field = new_str_value new_int = "42" self.page.variable_int_field = new_int new_float = "144.33" self.page.variable_float_field = new_float new_listint = "[111, 222]" self.page.variable_listint_field = new_listint new_liststr = "['string1', 'string2']" self.page.variable_liststr_field = new_liststr new_bool = "False" self.page.variable_bool_field = new_bool result = submit_and_wait_for_result(self) assert len(result) == 2 assert result[0].run_version == 0 assert result[1].run_version == 1 for run0_var, run1_var in zip(result[0].run_variables.all(), result[1].run_variables.all()): # the value of the variable has been overwritten because it's the same run number assert run0_var.variable == run1_var.variable run_vars = result[1].run_variables.all() assert run_vars[0].variable.value == new_str_value assert run_vars[1].variable.value == new_int assert run_vars[2].variable.value == new_float assert run_vars[3].variable.value == new_listint assert run_vars[4].variable.value == new_liststr assert run_vars[5].variable.value is None assert run_vars[6].variable.value == "" assert run_vars[7].variable.value == "False" with open(TEMP_OUT_FILE.name, 'r') as fil: contents = fil.read() for runvar in run_vars: assert runvar.variable.name in contents assert str(runvar.variable.value) in contents
class TestRerunJobsPageIntegration(BaseTestCase): fixtures = BaseTestCase.fixtures + ["run_with_one_variable"] accessibility_test_ignore_rules = { # https://github.com/ISISScientificComputing/autoreduce/issues/1267 "duplicate-id-aria": "input", } @classmethod def setUpClass(cls): """Starts external services and sets instrument for all test cases""" super().setUpClass() cls.instrument_name = "TestInstrument" cls.data_archive, cls.queue_client, cls.listener = setup_external_services( cls.instrument_name, 21, 21) cls.data_archive.add_reduction_script( cls.instrument_name, """def main(input_file, output_dir): print('some text')""") cls.data_archive.add_reduce_vars_script( cls.instrument_name, """standard_vars={"variable1":"test_variable_value_123"}""") cls.instrument_name = "TestInstrument" cls.rb_number = 1234567 cls.run_number = 99999 @classmethod def tearDownClass(cls) -> None: """Stops external services.""" cls.queue_client.disconnect() cls.data_archive.delete() super().tearDownClass() def setUp(self) -> None: """Sets up RerunJobsPage before each test case""" super().setUp() self.page = RerunJobsPage(self.driver, self.instrument_name) self.page.launch() def test_submit_rerun_same_variables(self): """ Test: Just opening the submit page and clicking rerun """ result = submit_and_wait_for_result(self) assert len(result) == 2 assert result[0].run_version == 0 assert result[1].run_version == 1 for run0_var, run1_var in zip(result[0].run_variables.all(), result[1].run_variables.all()): assert run0_var.variable == run1_var.variable def test_submit_rerun_changed_variable_arbitrary_value(self): """ Test: Open submit page, change a variable, submit the run """ # change the value of the variable field new_value = "the new value in the field" self.page.variable1_field = new_value result = submit_and_wait_for_result(self) assert len(result) == 2 assert result[0].run_version == 0 assert result[1].run_version == 1 for run0_var, run1_var in zip(result[0].run_variables.all(), result[1].run_variables.all()): # the value of the variable has been overwritten because it's the same run number assert run0_var.variable == run1_var.variable assert result[1].run_variables.first().variable.value == new_value def test_submit_rerun_after_clicking_reset_current_script(self): """ Test: Submitting a run after clicking the "Reset to values in the current reduce_vars script" uses the values saved in the current reduce_vars script """ self.page.reset_to_current_values.click() result = submit_and_wait_for_result(self) assert len(result) == 2 assert result[0].run_version == 0 assert result[1].run_version == 1 for run0_var, run1_var in zip(result[0].run_variables.all(), result[1].run_variables.all()): # the value of the variable has been overwritten because it's the same run number assert run0_var.variable == run1_var.variable assert result[1].run_variables.first( ).variable.value == "test_variable_value_123" def test_submit_confirm_page(self): """ Test: Submitting a run leads to the correct page """ result = submit_and_wait_for_result(self) expected_url = reverse("run_confirmation", kwargs={"instrument": self.instrument_name}) assert expected_url in self.driver.current_url assert len(result) == 2 def test_empty_run_range(self): """ Test form validation shown an error message when an empty run range is sent """ assert not self.page.form_validation_message.is_displayed() self.page.run_range_field = "" self.page.submit_button.click() assert self.page.form_validation_message.is_displayed() def test_invalid_run_range(self): """ Test form validation shown an error message when an invalid run range is sent """ assert not self.page.form_validation_message.is_displayed() self.page.run_range_field = "-1" self.page.submit_button.click() assert self.page.form_validation_message.is_displayed() def test_non_existent_run_range(self): """ Test form validation shown an error message when a non existent run range is sent """ assert not self.page.form_validation_message.is_displayed() expected_run = "123123123" self.page.run_range_field = expected_run self.page.submit_button.click() expected_url = reverse("run_confirmation", kwargs={"instrument": self.instrument_name}) assert expected_url in self.driver.current_url assert self.page.error_container.is_displayed() assert self.page.error_message_text( ) == f"Run number {expected_run} hasn't been ran by autoreduction yet."