Пример #1
0
    def test_extensions(self):
        kwargs = dict(extensions=["epsilon", "gamma", "mu", "phi"],
                      outputsubfolder="",
                      numberofrules=5,
                      skipstatichosts=True)
        write_opening_header(self.final_file, **kwargs)

        contents = self.final_file.getvalue()
        contents = contents.decode("UTF-8")

        # Expected contents.
        for expected in (
                ", ".join(kwargs["extensions"]),
                "# Extensions added to this file:",
                "# This hosts file is a merged collection",
                "# with a dash of crowd sourcing via Github",
                "# Number of unique domains: {count}".format(
                    count=kwargs["numberofrules"]),
                "Fetch the latest version of this file:",
                "Project home page: https://github.com/StevenBlack/hosts",
        ):
            self.assertIn(expected, contents)

        # Expected non-contents.
        for expected in (
                "127.0.0.1 localhost",
                "127.0.0.1 local",
                "127.0.0.53",
                "127.0.1.1",
        ):
            self.assertNotIn(expected, contents)
Пример #2
0
    def test_basic_include_static_hosts_linux(self):
        kwargs = dict(extensions="",
                      outputsubfolder="",
                      numberofrules=5,
                      skipstatichosts=False)
        with self.mock_property("platform.system") as system:
            system.return_value = "Linux"

            with self.mock_property("socket.gethostname") as hostname:
                hostname.return_value = "steven-hosts"
                write_opening_header(self.final_file, **kwargs)

        contents = self.final_file.getvalue()
        contents = contents.decode("UTF-8")

        # Expected contents.
        for expected in (
                "127.0.1.1",
                "127.0.0.53",
                "steven-hosts",
                "127.0.0.1 local",
                "127.0.0.1 localhost",
                "# This hosts file is a merged collection",
                "# with a dash of crowd sourcing via Github",
                "# Number of unique domains: {count}".format(
                    count=kwargs["numberofrules"]),
                "Fetch the latest version of this file:",
                "Project home page: https://github.com/StevenBlack/hosts",
        ):
            self.assertIn(expected, contents)

        # Expected non-contents.
        expected = "# Extensions added to this file:"
        self.assertNotIn(expected, contents)
Пример #3
0
    def test_preamble(self):
        hosts_file = os.path.join(self.test_dir, "myhosts")
        with open(hosts_file, "w") as f:
            f.write("peter-piper-picked-a-pepper")

        kwargs = dict(extensions="",
                      outputsubfolder="",
                      numberofrules=5,
                      skipstatichosts=True)

        with self.mock_property("updateHostsFile.BASEDIR_PATH"):
            updateHostsFile.BASEDIR_PATH = self.test_dir
            write_opening_header(self.final_file, **kwargs)

        contents = self.final_file.getvalue()
        contents = contents.decode("UTF-8")

        # Expected contents.
        for expected in (
                "peter-piper-picked-a-pepper",
                "# This hosts file is a merged collection",
                "# with a dash of crowd sourcing via Github",
                "# Number of unique domains: {count}".format(
                    count=kwargs["numberofrules"]),
                "Fetch the latest version of this file:",
                "Project home page: https://github.com/StevenBlack/hosts",
        ):
            self.assertIn(expected, contents)

        # Expected non-contents.
        for expected in (
                "# Extensions added to this file:",
                "127.0.0.1 localhost",
                "127.0.0.1 local",
                "127.0.0.53",
                "127.0.1.1",
        ):
            self.assertNotIn(expected, contents)