Ejemplo n.º 1
0
    def setUp(self) -> None:
        """
        Setups everything we need.
        """

        self.status = CheckerStatusBase(subject="example.org",
                                        idna_subject="example.org")
Ejemplo n.º 2
0
    def __init__(
        self,
        subject: Optional[str] = None,
        *,
        do_syntax_check_first: Optional[bool] = None,
        db_session: Optional[Session] = None,
        use_collection: Optional[bool] = None,
    ) -> None:
        self.collection_query_tool = CollectionQueryTool()

        if self.params is None:
            self.params = CheckerParamsBase()

        if self.status is None:
            self.status = CheckerStatusBase()

        if subject is not None:
            self.subject = subject

        if do_syntax_check_first is not None:
            self.do_syntax_check_first = do_syntax_check_first
        else:
            self.do_syntax_check_first = self.STD_DO_SYNTAX_CHECK_FIRST

        if use_collection is not None:
            self.use_collection = use_collection
        else:
            self.guess_and_set_use_collection()

        self.db_session = db_session
Ejemplo n.º 3
0
    def run_inactive_backup(self, test_dataset: dict,
                            test_result: CheckerStatusBase) -> None:
        """
        Runs the backup or update of the Inactive dataset storage.

        The idea is that if the status is OK (active), we just remove it from
        the dataset storage. Otherwise, we just keep it in there :-)
        """

        if test_dataset["type"] != "single":
            dataset = test_result.to_dict()
            dataset.update(test_dataset)

            PyFunceble.facility.Logger.debug("Test Dataset: %r", test_dataset)
            PyFunceble.facility.Logger.debug("Test Result: %r", test_result)

            if "from_inactive" in dataset:
                if test_result.status in self.INACTIVE_STATUSES:
                    if dataset["destination"]:
                        # Note: This handles the case that someone try to test a
                        # single subject.
                        # In fact, we should not generate any file if the output
                        # directory is not given.
                        self.inactive_dataset.update(dataset)
                else:
                    self.inactive_dataset.remove(dataset)
            elif (test_result.status in self.INACTIVE_STATUSES
                  and dataset["destination"]):
                self.inactive_dataset.update(dataset)
Ejemplo n.º 4
0
    def should_we_ignore(test_result: CheckerStatusBase) -> bool:
        """
        Checks if we should ignore the given datasets.

        :param test_result:
            The test result to check.
        """

        return isinstance(test_result,
                          str) and test_result.startswith("ignored_")
Ejemplo n.º 5
0
    def run_continue_backup(self, test_dataset: dict,
                            test_result: CheckerStatusBase) -> None:
        """
        Runs the backup or update of the auto-continue dataset storage.
        """

        if test_dataset["type"] != "single":
            dataset = test_result.to_dict()
            dataset.update(test_dataset)

            if (isinstance(self.continue_dataset, CSVContinueDataset)
                    and dataset["output_dir"]):
                # Note: This handles the case that someone try to test a single subject.
                # In fact, we should not generate any file if the output directory
                # is not given.
                #
                # The exception handler is just there to catch the case that the
                # method is not implemented because we are more likely using an
                # alternative backup (for example mariadb).

                self.continue_dataset.set_base_directory(dataset["output_dir"])
            self.continue_dataset.update(dataset)
Ejemplo n.º 6
0
    def run_stdout_printer(self, test_result: CheckerStatusBase) -> None:
        """
        Runs the stdout printer (if necessary).

        :param test_result:
            The rest result dataset.
        """

        if not PyFunceble.storage.CONFIGURATION.cli_testing.display_mode.quiet:
            # pylint: disable=line-too-long

            if self.should_we_print_status_to_stdout(test_result.status):
                self.stdout_printer.template_to_use = get_template_to_use()

                if not self.header_already_printed:
                    self.stdout_printer.print_header()
                    self.header_already_printed = True

                self.stdout_printer.set_dataset(
                    test_result.to_dict()).print_interpolated_line()
            else:
                print_single_line()
        else:
            print_single_line()
Ejemplo n.º 7
0
class TestCheckerStatusBase(unittest.TestCase):
    """
    Tests of the base of all our status handler.
    """
    def setUp(self) -> None:
        """
        Setups everything we need.
        """

        self.status = CheckerStatusBase(subject="example.org",
                                        idna_subject="example.org")

    def tearDown(self) -> None:
        """
        Destroyes everything we don't need.
        """

        del self.status

    def test_to_dict(self) -> None:
        """
        Tests of the method which gives us the :py:class:`dict` representation
        of the current status object.
        """

        test_datetime = datetime.utcnow()

        self.status.status = "ACTIVE"
        self.status.status_source = "Funilrys"
        self.status.tested_at = test_datetime

        expected = {
            "subject": "example.org",
            "idna_subject": "example.org",
            "status": "ACTIVE",
            "status_source": "Funilrys",
            "tested_at": test_datetime,
            "params": None,
        }

        actual = self.status.to_dict()

        self.assertEqual(expected, actual)

    def test_to_json(self) -> None:
        """
        Tests the method which let us get the JSON representation of the
        current status object.
        """

        test_datetime = datetime.fromtimestamp(
            0, tz=pyf_test_helpers.get_timezone())

        self.status.status = "ACTIVE"
        self.status.status_source = "Funilrys"
        self.status.tested_at = test_datetime

        expected = """{
    "idna_subject": "example.org",
    "params": null,
    "status": "ACTIVE",
    "status_source": "Funilrys",
    "subject": "example.org",
    "tested_at": "1970-01-01T00:00:00+00:00"
}"""

        actual = self.status.to_json()

        self.assertEqual(expected, actual)