Ejemplo n.º 1
0
    def test_reset(self):
        limiter = Limiter("my_check", "names", 10)

        for _ in range(1, 20):
            limiter.is_reached("dummy1")
        assert limiter.get_status() == (1, 10, False)

        limiter.reset()
        assert limiter.get_status() == (0, 10, False)
        assert limiter.is_reached("dummy1") is False
        assert limiter.get_status() == (1, 10, False)
Ejemplo n.º 2
0
    def test_mixed(self):
        limiter = Limiter("my_check", "names", 10)

        for _ in range(0, 20):
            assert limiter.is_reached("dummy1") is False
        assert limiter.get_status() == (1, 10, False)

        for _ in range(0, 5):
            assert limiter.is_reached() is False
        assert limiter.get_status() == (6, 10, False)
Ejemplo n.º 3
0
    def test_with_uid(self):
        warning = mock.MagicMock()
        limiter = Limiter("my_check", "names", 10, warning_func=warning)
        for _ in range(0, 20):
            assert limiter.is_reached("dummy1") is False
        assert limiter.get_status() == (1, 10, False)

        for _ in range(0, 20):
            assert limiter.is_reached("dummy2") is False
        assert limiter.get_status() == (2, 10, False)
        warning.assert_not_called()
Ejemplo n.º 4
0
    def test_no_uid(self):
        warning = mock.MagicMock()
        limiter = Limiter("my_check", "names", 10, warning_func=warning)
        for _ in range(0, 10):
            assert limiter.is_reached() is False
        assert limiter.get_status() == (10, 10, False)

        # Reach limit
        assert limiter.is_reached() is True
        assert limiter.get_status() == (11, 10, True)

        # Make sure warning is only sent once
        assert limiter.is_reached() is True
        warning.assert_called_once_with(
            "Check %s exceeded limit of %s %s, ignoring next ones", "my_check",
            10, "names")
Ejemplo n.º 5
0
    def test_with_uid(self):
        warnings = []
        limiter = Limiter("my_check",
                          "names",
                          10,
                          warning_func=warnings.append)
        for _ in range(0, 20):
            assert limiter.is_reached("dummy1") is False
        assert limiter.get_status() == (1, 10, False)

        for _ in range(0, 20):
            assert limiter.is_reached("dummy2") is False
        assert limiter.get_status() == (2, 10, False)
        assert len(warnings) == 0
Ejemplo n.º 6
0
    def test_no_uid(self):
        warnings = []
        limiter = Limiter("my_check",
                          "names",
                          10,
                          warning_func=warnings.append)
        for _ in range(0, 10):
            assert limiter.is_reached() is False
        assert limiter.get_status() == (10, 10, False)

        # Reach limit
        assert limiter.is_reached() is True
        assert limiter.get_status() == (11, 10, True)
        assert warnings == [
            "Check my_check exceeded limit of 10 names, ignoring next ones"
        ]

        # Make sure warning is only sent once
        assert limiter.is_reached() is True
        assert len(warnings) == 1