mirror of
https://github.com/Noettore/lagomareGateKeeperBot.git
synced 2025-10-15 19:46:40 +02:00
Refactor gates creating service, repository and tests
This commit is contained in:
51
tests/repository/test_gates_repository.py
Normal file
51
tests/repository/test_gates_repository.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import unittest
|
||||
|
||||
from models import Gate, Status
|
||||
from repository import GatesRepository
|
||||
|
||||
|
||||
class TestGatesRepository(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.mock_json_path = "../resources/mock_gates.json"
|
||||
self.repo = GatesRepository(self.mock_json_path)
|
||||
|
||||
def test_get_by_key_returns_gate_when_key_exists(self):
|
||||
gate_key = "gateA"
|
||||
expected_gate = Gate("1", "Gate A", Status.ENABLED)
|
||||
|
||||
result = self.repo.get_by_key(gate_key)
|
||||
|
||||
self.assertEqual(expected_gate.id, result.id)
|
||||
self.assertEqual(expected_gate.name, result.name)
|
||||
self.assertEqual(expected_gate.status, result.status)
|
||||
|
||||
def test_get_by_key_returns_none_when_key_does_not_exist(self):
|
||||
gate_key = "invalid_key"
|
||||
|
||||
result = self.repo.get_by_key(gate_key)
|
||||
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_get_all_enabled_returns_only_enabled_gates(self):
|
||||
enabled_gate_ids = ["1", "3", "5"]
|
||||
|
||||
result = self.repo.get_all_enabled()
|
||||
|
||||
self.assertEqual(len(enabled_gate_ids), len(result))
|
||||
self.assertEqual(
|
||||
sorted(enabled_gate_ids), sorted([gate.id for gate in result])
|
||||
)
|
||||
|
||||
for gate in result:
|
||||
self.assertTrue(gate.status == Status.ENABLED)
|
||||
print(gate.status)
|
||||
|
||||
# New Test
|
||||
def test_load_gates_handles_invalid_json_file_gracefully(self):
|
||||
repo = GatesRepository("./tests/invalid_mock_gates.json")
|
||||
|
||||
self.assertEqual(repo._gates, {})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Reference in New Issue
Block a user