test_context.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """
  2. -----------------------------------------------------------------------------------------
  3. INTERSEL - 4 cité d'Hauteville - 75010 PARIS
  4. RCS PARIS 488 379 660 - NAF 721Z
  5. File : tests/test_context.py
  6. Object : Tests for the context manager of the MCP server
  7. -----------------------------------------------------------------------------------------
  8. Modifications :
  9. - 2026/01/20 - Damien Lugagne-Delpon - V1.0.0- Creation
  10. -----------------------------------------------------------------------------------------
  11. @copyright : Intersel 2026
  12. @author : Damien Lugagne-Delpon - damien.lugagne-delpon@livinweb.fr
  13. @version : 1.0.0 (to be updated to the current_version of the developed software if file is touched)
  14. -----------------------------------------------------------------------------------------
  15. """
  16. from mcp_server.config.logger import LOGGER, init_logger
  17. from mcp_server.tests.test_manager import TestManager
  18. from mcp_server.core.context.context_manager import ContextManager
  19. from mcp_server.core.constants import ModxType, actionType
  20. init_logger()
  21. tm = TestManager()
  22. @tm.test("Context manager initializes")
  23. def test_context_initialization():
  24. cm = ContextManager()
  25. tm.assert_is_not_none(cm)
  26. @tm.test("Set and get context value")
  27. def test_set_get_context():
  28. cm = ContextManager()
  29. cm.add_to_context(ModxType.RESOURCE, {
  30. 1: {
  31. actionType.UPDATE: True,
  32. actionType.READ: True
  33. },
  34. 2: {
  35. actionType.READ: True
  36. }
  37. })
  38. context = cm.get_context()
  39. tm.assert_equal(len(context[ModxType.RESOURCE]), 2)
  40. if __name__ == "__main__":
  41. tm.run()