Esempio n. 1
0
    def test_edit(self, start: int, end: int, value_to_modify: str,
                  expected_strings: List[str]):
        """Test: That run variables can be edited for upcoming runs."""
        upcoming_panel = self.page.panels[1]
        # makes sure the value we are going to modify is present in the initial values
        assert value_to_modify in upcoming_panel.get_attribute("textContent")

        self.page.click_run_edit_button_for(start, end)

        new_runs_page = ConfigureNewRunsPage(self.driver, self.instrument_name,
                                             start, end)
        assert new_runs_page.run_start_val == str(start)

        assert new_runs_page.variable1_field_val == value_to_modify
        new_runs_page.variable1_field = "some new value"
        new_runs_page.submit_button.click()
        new_runs_page.replace_confirm.click()

        upcoming_panel = self.page.panels[1]
        # make sure the value we are modifying is no longer visible
        assert value_to_modify not in upcoming_panel.get_attribute(
            "textContent")

        # checks that the newly edited value is present, but also that the unaffected ones are still there
        for expected in expected_strings:
            assert expected in upcoming_panel.get_attribute("textContent")
Esempio n. 2
0
 def _submit_var_value(self, value, start=None, experiment_number=None):
     self.page = ConfigureNewRunsPage(
         self.driver,
         self.instrument_name,
         run_start=start,
         experiment_reference=experiment_number)
     self.page.launch()
     self.page.variable1_field = value
     self.page.submit_button.click()
Esempio n. 3
0
class TestConfigureNewRunsPageSkippedOnly(NavbarTestMixin, BaseTestCase,
                                          FooterTestMixin):
    fixtures = BaseTestCase.fixtures + ["skipped_run"]

    @classmethod
    def setUpClass(cls):
        """Makes test data archive and sets instrument for all test cases"""
        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,
            """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"

    @classmethod
    def tearDownClass(cls) -> None:
        """Destroys the data archive"""
        cls.data_archive.delete()
        super().tearDownClass()

    def setUp(self) -> None:
        """Sets up the ConfigureNewRunsPage before each test case"""
        super().setUp()
        self.page = ConfigureNewRunsPage(self.driver, self.instrument_name)
        self.page.launch()

    def test_configure_skipped_only_run_vars(self):
        """Test that configuring new runs works even with only skipped runs present"""
        self.page.variable1_field = "the new value in the field"

        self.page.submit_button.click()
        summary = VariableSummaryPage(self.driver, self.instrument_name)
        assert summary.current_variables_by_run.is_displayed()
        assert summary.current_variables_by_run.text == "Current Variables\nNo current variables found"
        assert "Runs\n100000\nOngoing" in summary.upcoming_variables_by_run.text

    def test_configure_skipped_only_exp_vars(self):
        """Test that configuring new runs works even with only skipped runs present"""
        self.page = ConfigureNewRunsPage(self.driver,
                                         self.instrument_name,
                                         experiment_reference=1234567)
        self.page.launch()
        self.page.variable1_field = "the new value in the field"

        self.page.submit_button.click()
        summary = VariableSummaryPage(self.driver, self.instrument_name)
        assert summary.current_variables_by_run.is_displayed()
        assert summary.current_variables_by_run.text == "Current Variables\nNo current variables found"
        assert summary.upcoming_variables_by_experiment.is_displayed()
        assert "Experiment\n#1234567" in summary.upcoming_variables_by_experiment.text
Esempio n. 4
0
    def test_go_to_other_goes_to_run_range(self):
        """Test: Clicking the link to configure by run range goes to run range"""
        self.page = ConfigureNewRunsPage(self.driver,
                                         self.instrument_name,
                                         experiment_reference=1234567)
        self.page.launch()

        self.page.go_to_other.click()
        url = reverse("instrument:variables",
                      kwargs={
                          "instrument": self.instrument_name,
                          "start": 100001
                      })
        assert url in self.driver.current_url
Esempio n. 5
0
    def test_configure_skipped_only_exp_vars(self):
        """Test that configuring new runs works even with only skipped runs present"""
        self.page = ConfigureNewRunsPage(self.driver,
                                         self.instrument_name,
                                         experiment_reference=1234567)
        self.page.launch()
        self.page.variable1_field = "the new value in the field"

        self.page.submit_button.click()
        summary = VariableSummaryPage(self.driver, self.instrument_name)
        assert summary.current_variables_by_run.is_displayed()
        assert summary.current_variables_by_run.text == "Current Variables\nNo current variables found"
        assert summary.upcoming_variables_by_experiment.is_displayed()
        assert "Experiment\n#1234567" in summary.upcoming_variables_by_experiment.text
Esempio n. 6
0
    def test_submit_submit_same_variables_does_not_add_new_variables(self):
        """
        Test: Just opening the submit page and clicking rerun
        """
        self.page = ConfigureNewRunsPage(self.driver,
                                         self.instrument_name,
                                         run_start=self.run_number + 1)
        self.page.launch()
        self.page.submit_button.click()
        assert InstrumentVariable.objects.count() == 1

        summary = VariableSummaryPage(self.driver, self.instrument_name)
        assert summary.current_variables_by_run.is_displayed()

        with self.assertRaises(NoSuchElementException):
            summary.upcoming_variables_by_run.is_displayed()
        with self.assertRaises(NoSuchElementException):
            summary.upcoming_variables_by_experiment.is_displayed()
Esempio n. 7
0
    def test_edit_experiment(self, experiment_reference):
        """Tests: Variables can be edited for upcoming runs for an experiment"""
        experiment_panel = self.page.panels[2]
        # makes sure the value we are going to modify is present in the initial values
        assert f"experiment {experiment_reference} var" in experiment_panel.get_attribute(
            "textContent")

        self.page.click_experiment_edit_button_for(experiment_reference)
        new_runs_page = ConfigureNewRunsPage(
            self.driver,
            self.instrument_name,
            experiment_reference=experiment_reference)

        assert new_runs_page.variable1_field_val == f"experiment {experiment_reference} var"

        new_runs_page.variable1_field = "some new value"
        new_runs_page.submit_button.click()

        experiment_panel = self.page.panels[2]
        assert f"experiment {experiment_reference} var" not in experiment_panel.get_attribute(
            "textContent")
        assert "some new value" in experiment_panel.get_attribute(
            "textContent")
Esempio n. 8
0
 def setUp(self) -> None:
     """Sets up the ConfigureNewRunsPage before each test case"""
     super().setUp()
     self.page = ConfigureNewRunsPage(self.driver, self.instrument_name)
     self.page.launch()
Esempio n. 9
0
class TestConfigureNewRunsPage(NavbarTestMixin, BaseTestCase, FooterTestMixin,
                               AccessibilityTestMixin):
    fixtures = BaseTestCase.fixtures + ["two_runs"]

    accessibility_test_ignore_rules = {
        # https://github.com/ISISScientificComputing/autoreduce/issues/1267
        "duplicate-id-aria": "input",
    }

    @classmethod
    def setUpClass(cls):
        """Sets up the data archive to be shared across test cases"""
        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,
            """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"

    @classmethod
    def tearDownClass(cls) -> None:
        """Destroys the data archive"""
        cls.data_archive.delete()
        super().tearDownClass()

    def setUp(self) -> None:
        """Sets up the ConfigureNewRunsPage before each test case"""
        super().setUp()
        self.page = ConfigureNewRunsPage(self.driver, self.instrument_name)
        self.page.launch()

    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
        assert self.page.variable1_field_val == "test_variable_value_123"  # pylint:disable=no-member

    def test_back_to_instruments_goes_back(self):
        """
        Test: Clicking back goes back to the instrument
        """
        back = self.page.cancel_button
        assert back.is_displayed()
        assert back.text == "Cancel"
        back.click()
        assert reverse("runs:list",
                       kwargs={"instrument": self.instrument_name
                               }) in self.driver.current_url

    def test_go_to_other_goes_to_experiment(self):
        """Test: clicking the link to configure by experiment goes to configure by experiment"""
        self.page.go_to_other.click()
        url = reverse("instrument:variables_by_experiment",
                      kwargs={
                          "instrument": self.instrument_name,
                          "experiment_reference": 1234567
                      })
        assert url in self.driver.current_url

    def test_go_to_other_goes_to_run_range(self):
        """Test: Clicking the link to configure by run range goes to run range"""
        self.page = ConfigureNewRunsPage(self.driver,
                                         self.instrument_name,
                                         experiment_reference=1234567)
        self.page.launch()

        self.page.go_to_other.click()
        url = reverse("instrument:variables",
                      kwargs={
                          "instrument": self.instrument_name,
                          "start": 100001
                      })
        assert url in self.driver.current_url
Esempio n. 10
0
 def setUp(self) -> None:
     """Sets up the ConfigureNewRunsPage before each test case"""
     super().setUp()
     self.page = ConfigureNewRunsPage(self.driver,
                                      self.instrument_name,
                                      run_start=self.run_number + 1)
Esempio n. 11
0
class TestConfigureNewRunsPageIntegration(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):
        """
        Sets up the Datarchive complete with scripts, the database client and checks the queue client and listerner
        are running for all testcases
        """
        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,
            f"""standard_vars={{"variable1":"{REDUCE_VARS_DEFAULT_VALUE}"}}""")
        cls.rb_number = 1234567
        cls.run_number = 99999

    @classmethod
    def tearDownClass(cls) -> None:
        """
        Destroys the created data-archive and disconnects the database and queue clients
        """
        cls.queue_client.disconnect()
        cls.data_archive.delete()
        super().tearDownClass()

    def setUp(self) -> None:
        """Sets up the ConfigureNewRunsPage before each test case"""
        super().setUp()
        self.page = ConfigureNewRunsPage(self.driver,
                                         self.instrument_name,
                                         run_start=self.run_number + 1)

    def _find_run_in_database(self):
        """
        Find a ReductionRun record in the database
        This includes a timeout to wait for several seconds to ensure the database has received
        the record in question
        :return: The resulting record
        """
        instrument = db.get_instrument(self.instrument_name)
        return instrument.reduction_runs.filter(run_number=self.run_number)

    def _submit_var_value(self, value, start=None, experiment_number=None):
        self.page = ConfigureNewRunsPage(
            self.driver,
            self.instrument_name,
            run_start=start,
            experiment_reference=experiment_number)
        self.page.launch()
        self.page.variable1_field = value
        self.page.submit_button.click()

    @staticmethod
    def assert_expected_var(var: InstrumentVariable, expected_run_number,
                            expected_reference, expected_value):
        """
        Assert that a var has the expected values
        :param var: The var to check
        :param expected_run_number: The expected run_number
        :param expected_reference: The expected reference
        :param expected_value: The expected var value
        """
        if expected_run_number is not None:
            assert var.start_run == expected_run_number
        else:
            assert var.start_run is None
        if expected_reference is not None:
            assert var.experiment_reference == expected_reference
        else:
            assert var.experiment_reference is None
        assert var.value == expected_value

    def test_submit_submit_same_variables_does_not_add_new_variables(self):
        """
        Test: Just opening the submit page and clicking rerun
        """
        self.page = ConfigureNewRunsPage(self.driver,
                                         self.instrument_name,
                                         run_start=self.run_number + 1)
        self.page.launch()
        self.page.submit_button.click()
        assert InstrumentVariable.objects.count() == 1

        summary = VariableSummaryPage(self.driver, self.instrument_name)
        assert summary.current_variables_by_run.is_displayed()

        with self.assertRaises(NoSuchElementException):
            summary.upcoming_variables_by_run.is_displayed()
        with self.assertRaises(NoSuchElementException):
            summary.upcoming_variables_by_experiment.is_displayed()

    def test_submit_new_value(self):
        """
        Test: Just opening the submit page and clicking rerun
        """
        self._submit_var_value("new_value", self.run_number + 1)
        assert InstrumentVariable.objects.count() == 2
        new_var = InstrumentVariable.objects.last()
        self.assert_expected_var(new_var, self.run_number + 1, None,
                                 "new_value")

        summary = VariableSummaryPage(self.driver, self.instrument_name)
        assert summary.current_variables_by_run.is_displayed()
        assert summary.upcoming_variables_by_run.is_displayed()

        with self.assertRaises(NoSuchElementException):
            summary.upcoming_variables_by_experiment.is_displayed()

    def test_submit_experiment_var(self):
        """Tests the functionality foe submitting a new variable for an experiment"""
        self._submit_var_value("new_value", experiment_number=self.rb_number)

        assert InstrumentVariable.objects.count() == 2
        new_var = InstrumentVariable.objects.last()
        self.assert_expected_var(new_var, None, self.rb_number, "new_value")

        summary = VariableSummaryPage(self.driver, self.instrument_name)
        assert summary.current_variables_by_run.is_displayed()
        assert summary.upcoming_variables_by_experiment.is_displayed()

        with self.assertRaises(NoSuchElementException):
            summary.upcoming_variables_by_run.is_displayed()

    def test_submit_multiple_run_ranges(self):
        """
        Test submitting variables for multiple run ranges, and that they show up correctly
        in 'see instrument variables'
        """
        self._submit_var_value("new_value", self.run_number + 1)
        self._submit_var_value("the newest value", self.run_number + 101)

        assert InstrumentVariable.objects.count() == 3
        first_var, second_var, third_var = InstrumentVariable.objects.all()
        self.assert_expected_var(first_var, self.run_number, None, "value1")
        self.assert_expected_var(second_var, self.run_number + 1, None,
                                 "new_value")
        self.assert_expected_var(third_var, self.run_number + 101, None,
                                 "the newest value")

        summary = VariableSummaryPage(self.driver, self.instrument_name)
        assert summary.current_variables_by_run.is_displayed()
        assert summary.upcoming_variables_by_run.is_displayed()

        with self.assertRaises(NoSuchElementException):
            assert summary.upcoming_variables_by_experiment.is_displayed()

    def test_submit_multiple_run_ranges_with_ends(self):
        """
        Test submitting variables for multiple run ranges, and that they show up correctly
        in 'see instrument variablers'
        """
        self._submit_var_value("new_value", self.run_number + 1)
        self._submit_var_value("the newest value", self.run_number + 201)

        assert InstrumentVariable.objects.count() == 3
        first_var, second_var, fourth_var = InstrumentVariable.objects.all()
        self.assert_expected_var(first_var, self.run_number, None, "value1")
        self.assert_expected_var(second_var, self.run_number + 1, None,
                                 "new_value")
        self.assert_expected_var(fourth_var, self.run_number + 201, None,
                                 "the newest value")

    def test_submit_multiple_experiments(self):
        """Test submitting vars for multiple experiments"""
        self._submit_var_value("new_value", experiment_number=self.rb_number)
        self._submit_var_value("the newest value",
                               experiment_number=self.rb_number + 100)

        assert InstrumentVariable.objects.count() == 3
        first_var, second_var, third_var = InstrumentVariable.objects.all()
        self.assert_expected_var(first_var, self.run_number, None, "value1")
        self.assert_expected_var(second_var, None, self.rb_number, "new_value")
        self.assert_expected_var(third_var, None, self.rb_number + 100,
                                 "the newest value")

        summary = VariableSummaryPage(self.driver, self.instrument_name)
        assert summary.current_variables_by_run.is_displayed()
        assert summary.upcoming_variables_by_experiment.is_displayed()

        with self.assertRaises(NoSuchElementException):
            summary.upcoming_variables_by_run.is_displayed()

    def test_submit_multiple_run_ranges_and_then_experiment(self):
        """Test submitting both run range vars and experiment vars"""
        self._submit_var_value("new_value", self.run_number + 1)
        self._submit_var_value("the newest value", self.run_number + 201)
        self._submit_var_value("some value for experiment",
                               experiment_number=self.rb_number)
        self._submit_var_value("some different value for experiment",
                               experiment_number=self.rb_number + 100)

        assert InstrumentVariable.objects.count() == 5
        first_var, second_var, fourth_var, exp_var1, exp_var2 = InstrumentVariable.objects.all(
        )

        self.assert_expected_var(first_var, self.run_number, None, "value1")
        self.assert_expected_var(second_var, self.run_number + 1, None,
                                 "new_value")
        self.assert_expected_var(fourth_var, self.run_number + 201, None,
                                 "the newest value")
        self.assert_expected_var(exp_var1, None, self.rb_number,
                                 "some value for experiment")
        self.assert_expected_var(exp_var2, None, self.rb_number + 100,
                                 "some different value for experiment")

        summary = VariableSummaryPage(self.driver, self.instrument_name)
        assert summary.current_variables_by_run.is_displayed()
        assert summary.upcoming_variables_by_experiment.is_displayed()
        assert summary.upcoming_variables_by_run.is_displayed()

    def test_submit_then_edit_then_delete_run_vars(self):
        """Test submitting new variables for run ranges, then editing them, then deleting them"""
        self._submit_var_value("new_value", self.run_number + 1)
        self._submit_var_value("the newest value", self.run_number + 101)
        self._submit_var_value("value for 201", self.run_number + 201)
        self._submit_var_value("value for 301", self.run_number + 301)

        summary = VariableSummaryPage(self.driver, self.instrument_name)

        summary.click_run_edit_button_for(self.run_number + 1,
                                          self.run_number + 100)

        self.page.variable1_field = "a new test value 123"
        self.page.submit_button.click()
        self.page.replace_confirm.click()

        upcoming_panel = summary.panels[1]

        assert "new_value" not in upcoming_panel.get_attribute("textContent")
        assert "a new test value 123" in upcoming_panel.get_attribute(
            "textContent")

        summary.click_run_delete_button_for(self.run_number + 1,
                                            self.run_number + 100)

        upcoming_panel = summary.panels[1]
        assert "a new test value 123" not in upcoming_panel.get_attribute(
            "textContent")

        incoming_run_numbers = upcoming_panel.find_elements_by_class_name(
            "run-numbers")

        assert "100100" in incoming_run_numbers[0].text
        assert "100199" in incoming_run_numbers[0].text
        assert "100200" in incoming_run_numbers[1].text
        assert "100299" in incoming_run_numbers[1].text
        assert "100300" in incoming_run_numbers[2].text
        assert "Ongoing" in incoming_run_numbers[2].text

        # now for the 2nd variable we made
        summary.click_run_edit_button_for(self.run_number + 201,
                                          self.run_number + 300)
        self.page.variable1_field = "another new test value 321"
        self.page.submit_button.click()
        self.page.replace_confirm.click()

        upcoming_panel = summary.panels[1]

        assert "new_value" not in upcoming_panel.get_attribute("textContent")
        assert "another new test value 321" in upcoming_panel.get_attribute(
            "textContent")

        summary.click_run_delete_button_for(self.run_number + 201,
                                            self.run_number + 300)

        upcoming_panel = summary.panels[1]
        assert "another new test value 321" not in upcoming_panel.get_attribute(
            "textContent")

        incoming_run_numbers = upcoming_panel.find_elements_by_class_name(
            "run-numbers")

        # there's a few leftover default variables, but that's OK because the user can remove them
        assert "100100" in incoming_run_numbers[0].text
        assert "100299" in incoming_run_numbers[0].text
        assert "100300" in incoming_run_numbers[1].text
        assert "Ongoing" in incoming_run_numbers[1].text

    def test_submit_then_edit_then_delete_experiment_vars(self):
        """Test submitting new variables for experiment reference, then editing them, then deleting them"""
        self._submit_var_value("new_value", experiment_number=1234567)
        self._submit_var_value("the newest value", experiment_number=2345678)
        summary = VariableSummaryPage(self.driver, self.instrument_name)
        summary.click_experiment_edit_button_for(1234567)

        self.page.variable1_field = "a new test value 123"
        self.page.submit_button.click()

        experiment_panel = summary.panels[1]

        assert "new_value" not in experiment_panel.get_attribute("textContent")
        assert "a new test value 123" in experiment_panel.get_attribute(
            "textContent")

        summary.click_experiment_delete_button_for(1234567)

        experiment_panel = summary.panels[1]
        incoming_exp_numbers = experiment_panel.find_elements_by_class_name(
            "run-numbers")

        assert "2345678" in incoming_exp_numbers[0].text

        summary.click_experiment_edit_button_for(2345678)

        self.page.variable1_field = "a new value for experiment 2345678"
        self.page.submit_button.click()

        experiment_panel = summary.panels[1]

        assert "the newest value" not in experiment_panel.get_attribute(
            "textContent")
        assert "a new value for experiment 2345678" in experiment_panel.get_attribute(
            "textContent")

        summary.click_experiment_delete_button_for(2345678)

        # only the current variables panel left
        assert len(summary.panels) == 1
        assert "Runs\n99999\nOngoing\nvariable1: value1" in summary.panels[
            0].text