def test_count(self):
        """
        Tests if the counter can be set proprely.
        """

        expected = self.__preset_counters_and_get_expected()

        for element in ["up", "down", "invalid"]:
            Percentage(domain_status=PyFunceble.STATUS.official[element],
                       init=None).count()

            expected[element] += 1
            expected["tested"] += 1
            actual = PyFunceble.INTERN["counter"]["number"]

            self.assertEqual(expected, actual)

        PyFunceble.CONFIGURATION.syntax = True

        expected = self.__preset_counters_and_get_expected()

        for element in ["up", "down", "invalid"]:
            Percentage(domain_status=PyFunceble.STATUS.official[element],
                       init=None).count()

            expected[element] += 1
            expected["tested"] += 1
            actual = PyFunceble.INTERN["counter"]["number"]

            self.assertEqual(expected, actual)
    def test_log_reputation_test(self):
        """
        Tests the logging of the percentage for a reputation check.
        """

        PyFunceble.CONFIGURATION.reputation = True
        PyFunceble.CONFIGURATION.syntax = False

        expected = """

Status      Percentage   Numbers%s
----------- ------------ ------------
SANE        95%%          45%s
MALICIOUS   4%%           2%s
""" % (
            " " * 5,
            " " * 10,
            " " * 11,
        )
        PyFunceble.INTERN["counter"]["number"].update({
            "up": 0,
            "down": 0,
            "invalid": 0,
            "sane": 45,
            "malicious": 2,
            "tested": 47
        })

        Percentage(domain_status=None, init=None).log()
        actual = sys.stdout.getvalue()

        self.assertEqual(expected, actual)

        # Test for the case that we do not show_percentage
        PyFunceble.CONFIGURATION.show_percentage = False
        PyFunceble.INTERN["counter"]["number"].update({
            "up": 0,
            "down": 0,
            "invalid": 0,
            "sane": 45,
            "malicious": 2,
            "tested": 47
        })

        Percentage(domain_status=None, init=None).log()

        actual = PyFunceble.INTERN["counter"]["percentage"]
        expected = {
            "up": 0,
            "down": 0,
            "invalid": 0,
            "sane": 95,
            "malicious": 4
        }

        self.assertEqual(expected, actual)

        PyFunceble.CONFIGURATION.reputation = False
        PyFunceble.CONFIGURATION.syntax = False
    def test_log(self):
        """
        Tests the log system.
        """

        expected = """

Status      Percentage   Numbers%s
----------- ------------ ------------
ACTIVE      36%%          45%s
INACTIVE    62%%          78%s
INVALID     1%%           2%s
""" % (
            " " * 5,
            " " * 10,
            " " * 10,
            " " * 11,
        )
        PyFunceble.INTERN["counter"]["number"].update({
            "up": 45,
            "down": 78,
            "invalid": 2,
            "tested": 125
        })

        Percentage(domain_status=None, init=None).log()
        actual = sys.stdout.getvalue()

        self.assertEqual(expected, actual)

        # Test for the case that we do not show_percentage
        PyFunceble.CONFIGURATION.show_percentage = False
        PyFunceble.INTERN["counter"]["number"].update({
            "up": 45,
            "down": 78,
            "invalid": 2,
            "tested": 125
        })

        Percentage(domain_status=None, init=None).log()

        actual = PyFunceble.INTERN["counter"]["percentage"]
        expected = {"up": 36, "down": 62, "invalid": 1}

        self.assertEqual(expected, actual)
    def test_init(self):
        """
        Tests if we are able to initiate the percentage
        system from outside.
        """

        expected = {"up": 15, "down": 2, "invalid": 0, "tested": 75}

        Percentage(domain_status=None, init=expected)

        self.assertEqual(expected, PyFunceble.INTERN["counter"]["number"])
    def test_calculate(self):
        """
        Tests the calculation method.
        """

        PyFunceble.INTERN["counter"]["number"].update({
            "up": 45,
            "down": 78,
            "invalid": 2,
            "tested": 125
        })

        expected = {"up": 36, "down": 62, "invalid": 1}

        Percentage(domain_status=None, init=None).calculate()
        actual = PyFunceble.INTERN["counter"]["percentage"]

        self.assertEqual(expected, actual)