fix(test): ROOM_MAP_PATH-Patch in setUp/tearDown statt Decorator

This commit is contained in:
Bernd (Hermes)
2026-06-15 20:06:03 +02:00
parent 948666fcdd
commit 92697b5fff
+15 -16
View File
@@ -44,15 +44,23 @@ class TestAutoOnboarding(unittest.TestCase):
with open(self.temp_path, 'w') as f:
json.dump(self.test_data, f)
# Patch ROOM_MAP_PATH und DEFAULT_MAP_PATH auf den temporären Pfad
# (muss vor __init__ aktiv sein, weil _load_room_map() den Pfad sofort liest)
# ROOM_MAP_PATH → für _load_room_map() in adapter_integration
# DEFAULT_MAP_PATH → für reload()/save() ohne Pfad-Argument in room_map
self._path_patcher = patch('archivar.adapter_integration.ROOM_MAP_PATH', str(self.temp_path))
self._path_patcher.start()
self._default_path_patcher = patch('archivar.room_map.DEFAULT_MAP_PATH', str(self.temp_path))
self._default_path_patcher.start()
def tearDown(self):
"""Tear down test fixtures after each test method."""
self._default_path_patcher.stop()
self._path_patcher.stop()
self.temp_dir.cleanup()
@patch('archivar.adapter_integration.ROOM_MAP_PATH')
def test_single_room_auto_catch_all(self, mock_room_map_path):
def test_single_room_auto_catch_all(self):
"""Testet die Single-Room-Regel: 1 relevanter Raum → automatisch catch_all."""
mock_room_map_path.return_value = str(self.temp_path)
# Erstelle einen ArchivarMessageHandler
handler = ArchivarMessageHandler()
@@ -75,11 +83,8 @@ class TestAutoOnboarding(unittest.TestCase):
self.assertIn("single_room_id", handler._room_map.rooms)
self.assertTrue(handler._room_map.rooms["single_room_id"].catch_all)
@patch('archivar.adapter_integration.ROOM_MAP_PATH')
def test_multi_room_onboarding_triggered(self, mock_room_map_path):
def test_multi_room_onboarding_triggered(self):
"""Testet dass Onboarding bei mehreren fehlenden Räumen ausgelöst wird."""
mock_room_map_path.return_value = str(self.temp_path)
# Erstelle einen ArchivarMessageHandler
handler = ArchivarMessageHandler()
@@ -101,11 +106,8 @@ class TestAutoOnboarding(unittest.TestCase):
self.assertEqual(missing[0]["room_id"], "room1_id")
self.assertEqual(missing[1]["room_id"], "room2_id")
@patch('archivar.adapter_integration.ROOM_MAP_PATH')
def test_dm_rooms_ignored(self, mock_room_map_path):
def test_dm_rooms_ignored(self):
"""Testet dass DM-Räume ignoriert werden (außer Operator-DM)."""
mock_room_map_path.return_value = str(self.temp_path)
# Erstelle einen ArchivarMessageHandler
handler = ArchivarMessageHandler()
@@ -130,11 +132,8 @@ class TestAutoOnboarding(unittest.TestCase):
self.assertIn("channel_id", handler._room_map.rooms)
self.assertTrue(handler._room_map.rooms["channel_id"].catch_all)
@patch('archivar.adapter_integration.ROOM_MAP_PATH')
def test_map_already_complete_no_action(self, mock_room_map_path):
def test_map_already_complete_no_action(self):
"""Testet dass nichts passiert wenn die Map bereits vollständig ist."""
mock_room_map_path.return_value = str(self.temp_path)
# Erstelle Testdaten mit bereits vorhandenen Räumen
test_data_with_rooms = {
"version": 2,