Esempio n. 1
0
    def test_logout_some_errors(self, logout_m, caplog, nerrors):
        caplog.set_level(10)
        logout_m.side_effect = [LogoutError("message")] * nerrors + [None]
        conn = Connection()
        conn._logout_response = mock.MagicMock(status_code=501, ok=False)
        conn.logout()

        logout_m.assert_called()
        assert logout_m.call_count == nerrors + 1

        records_expected: Any = [(10, "Logging out (%s retries)" % self.logout_retries)]
        for i in range(1, nerrors + 1):
            retries_left = self.logout_retries - i
            records_expected.append(
                (30, "Error during logout [501], %d retries left" % retries_left)
            )
        records_expected.append((20, "Logged out"))
        records_expected = [(self.logger_name,) + x for x in records_expected]
        assert caplog.record_tuples == records_expected
Esempio n. 2
0
    def test_logout_fatal(self, logout_m, caplog):
        caplog.set_level(10)
        logout_m.side_effect = [LogoutError("message")] * self.logout_retries + [None]
        conn = Connection()
        conn._logout_response = mock.MagicMock(status_code=501, ok=False)
        with pytest.raises(LogoutError, match="Logout retries expired"):
            conn.logout()

        logout_m.assert_called()
        assert logout_m.call_count == self.logout_retries

        records_expected: Any = [(10, "Logging out (%s retries)" % self.logout_retries)]
        for i in range(1, self.logout_retries + 1):
            retries_left = self.logout_retries - i
            records_expected.append(
                (30, "Error during logout [501], %d retries left" % retries_left)
            )
        records_expected.append((50, "Logout retries expired"))
        records_expected = [(self.logger_name,) + x for x in records_expected]
        assert caplog.record_tuples == records_expected