Skip to content

Commit

Permalink
✅ Add tests for several functions & Bump coverage (#540)
Browse files Browse the repository at this point in the history
✅  Add tests for several functions & Bump coverage
  • Loading branch information
yezz123 authored Feb 19, 2024
2 parents f699b29 + 1369fb3 commit 142bc99
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion authx/_internal/_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def save_store(self, session_id):
self.get_store(session_id)

def gc(self):
if len(self.raw_memory_store) >= 100:
if len(self.raw_memory_store) >= 100: # pragma: no cover
self.cleanup_old_sessions()

def cleanup_old_sessions(self):
Expand Down
4 changes: 2 additions & 2 deletions authx/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

try:
from typing import ParamSpecKwargs
except Exception:
from typing_extensions import ParamSpecKwargs
except Exception: # pragma: no cover
from typing_extensions import ParamSpecKwargs # pragma: no cover

T = TypeVar("T")
Numeric = Union[float, int]
Expand Down
21 changes: 21 additions & 0 deletions tests/internal/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import patch

from authx._internal._logger import (
_build_log_msg,
get_logger,
log_debug,
log_error,
Expand Down Expand Up @@ -39,3 +40,23 @@ def test_log_error(caplog):
assert "Error message" in caplog.text
assert "Traceback" in caplog.text
assert logging.getLevelName(caplog.records[0].levelno) == "ERROR"


def test_build_log_msg_no_loc_or_method():
result = _build_log_msg("Test message")
assert result == "Test message"


def test_build_log_msg_with_loc():
result = _build_log_msg("Test message", loc="test_location")
assert result == "[test_location] Test message"


def test_build_log_msg_with_method():
result = _build_log_msg("Test message", method="test_method")
assert result == "[None][test_method] Test message"


def test_build_log_msg_with_loc_and_method():
result = _build_log_msg("Test message", loc="test_location", method="test_method")
assert result == "[test_location][test_method] [test_location] Test message"
6 changes: 6 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ def test_handle_app_errors(app: FastAPI, authx: AuthX):
assert exc.AccessTokenRequiredError in app.exception_handlers
assert exc.RefreshTokenRequiredError in app.exception_handlers
assert exc.CSRFError in app.exception_handlers


def test_invalid_token_init():
errors = ["Invalid signature", "Expired token"]
exception = exc.InvalidToken(errors)
assert exception.errors == errors

0 comments on commit 142bc99

Please sign in to comment.