Ejemplo n.º 1
0
    def tests_with_prefix(self):
        """
        Test the case that a line has a decorator.

        For example:
        ::

            127.0.0.1 google.com
        """

        for domain in self.domains:
            expected = domain

            data = "0.0.0.0 %s" % domain
            actual = FileCore._format_line(data)

            self.assertEqual(expected, actual)

        for domain in self.domains:
            expected = domain

            data = "127.0.0.1 %s" % domain
            actual = FileCore._format_line(data)

            self.assertEqual(expected, actual)
Ejemplo n.º 2
0
    def domain(self):
        """
        Handle the simple domain testing.
        """

        # We run the preset specific to this method.
        self.preset.simple_domain()
        # We print the header if it was not done yet.
        PyFunceble.CLICore.print_header()

        if self.subject:
            if PyFunceble.CONFIGURATION["syntax"]:
                # The syntax mode is activated.

                # We get the status from SyntaxStatus.
                status = SyntaxStatus(self.subject).get()["status"]
            else:
                # We test and get the status of the domain.
                status = Status(self.subject,
                                whois_db=self.whois_db).get()["status"]

            if PyFunceble.CONFIGURATION["simple"]:
                # The simple mode is activated.

                # We print the domain and the status.
                print("{0} {1}".format(
                    FileCore.get_simple_coloration(status) + self.subject,
                    status))
        else:
            PyFunceble.CLICore.print_nothing_to_test()
Ejemplo n.º 3
0
    def test_cyan_other(self):
        """
        Test the case that we give something ellse status.
        """

        expected = PyFunceble.Fore.CYAN + PyFunceble.Style.BRIGHT
        actual = FileCore.get_simple_coloration("funilrys")

        self.assertEqual(expected, actual)
Ejemplo n.º 4
0
    def tests_simple_line(self):
        """
        Test the case that we encouter a simple line without decorator.
        """

        for domain in self.domains:
            expected = domain
            actual = FileCore._format_line(domain)

            self.assertEqual(expected, actual)
Ejemplo n.º 5
0
    def test_cyan_invalid(self):
        """
        Test the case that we give the INVALID status.
        """

        expected = PyFunceble.Fore.CYAN + PyFunceble.Style.BRIGHT
        actual = FileCore.get_simple_coloration(
            PyFunceble.STATUS["official"]["invalid"])

        self.assertEqual(expected, actual)
Ejemplo n.º 6
0
    def test_red_inactive(self):
        """
        Test the case that we give the INACTIVE status.
        """

        expected = PyFunceble.Fore.RED + PyFunceble.Style.BRIGHT
        actual = FileCore.get_simple_coloration(
            PyFunceble.STATUS["official"]["down"])

        self.assertEqual(expected, actual)
Ejemplo n.º 7
0
    def test_green_up(self):
        """
        Test the case that we give the UP status.
        """

        expected = PyFunceble.Fore.GREEN + PyFunceble.Style.BRIGHT
        actual = FileCore.get_simple_coloration(
            PyFunceble.STATUS["official"]["up"])

        self.assertEqual(expected, actual)
Ejemplo n.º 8
0
    def tests_comment(self):
        """
        Test the case that we encouter a commented line.
        """

        for domain in self.domains:
            expected = ""

            data = "# %s" % domain
            actual = FileCore._format_line(data)

            self.assertEqual(expected, actual)
Ejemplo n.º 9
0
    def tests_with_multiple_tabs(self):
        """
        Test the case that we have multiple tabs as sparator between
        our domain end its prefix.
        """

        for domain in self.domains:
            expected = domain

            data = "0.0.0.0\t\t\t\t\t\t\t\t\t\t%s" % domain
            actual = FileCore._format_line(data)

            self.assertEqual(expected, actual)

        for domain in self.domains:
            expected = domain

            data = "127.0.0.1\t\t\t\t\t\t\t\t\t\t\t%s" % domain
            actual = FileCore._format_line(data)

            self.assertEqual(expected, actual)
Ejemplo n.º 10
0
    def tests_ends_with_comment(self):
        """
        Test the case that a line has a comment at the end of its line.
        """

        for domain in self.domains:
            expected = domain

            data = "%s # hello world" % domain
            actual = FileCore._format_line(data)

            self.assertEqual(expected, actual)
Ejemplo n.º 11
0
    def __init__(
        self,
        domain_or_ip=None,
        file_path=None,
        link_to_test=None,
        url_file_path=None,
        url_to_test=None,
    ):  # pylint: disable=too-many-branches
        if domain_or_ip or file_path or link_to_test or url_file_path or url_to_test:
            preset = PyFunceble.Preset()

            CLICore.logs_sharing()

            ExecutionTime("start")

            if domain_or_ip:
                SimpleCore(domain_or_ip).domain()
            elif file_path:
                PyFunceble.DirectoryStructure()

                if PyFunceble.CONFIGURATION["multiprocess"]:
                    preset.maximal_processes()
                    preset.multiprocess()

                    FileMultiprocessCore(
                        file_path, "domain"
                    ).read_and_test_file_content()
                else:
                    FileCore(file_path, "domain").read_and_test_file_content()
            elif link_to_test:
                PyFunceble.DirectoryStructure()

                if PyFunceble.CONFIGURATION["multiprocess"]:
                    preset.maximal_processes()
                    preset.multiprocess()

                    FileMultiprocessCore(
                        link_to_test, "domain"
                    ).read_and_test_file_content()
                else:
                    FileCore(link_to_test, "domain").read_and_test_file_content()
            elif url_file_path:
                PyFunceble.DirectoryStructure()
                preset.file_url()

                if PyFunceble.CONFIGURATION["multiprocess"]:
                    preset.maximal_processes()
                    preset.multiprocess()

                    FileMultiprocessCore(
                        url_file_path, "url"
                    ).read_and_test_file_content()
                else:
                    FileCore(url_file_path, "url").read_and_test_file_content()
            elif url_to_test:
                SimpleCore(url_to_test).url()

            Percentage().log()

            ExecutionTime("stop")

            PyFunceble.CLICore.stay_safe()
        else:
            PyFunceble.CLICore.print_nothing_to_test()