"""
Unit tests for the database operations.
"""
import unittest
import os
from datetime import datetime
from src.ice_locator_mcp.database.models import Detainee, Facility, DetaineeLocationHistory
from src.ice_locator_mcp.database.manager import DatabaseManager
class TestDatabaseModels(unittest.TestCase):
"""Test cases for database models."""
def test_detainee_model(self):
"""Test Detainee model creation."""
detainee = Detainee(
id=1,
first_name="John",
last_name="Doe",
created_at=datetime.now(),
updated_at=datetime.now()
)
self.assertEqual(detainee.id, 1)
self.assertEqual(detainee.first_name, "John")
self.assertEqual(detainee.last_name, "Doe")
def test_facility_model(self):
"""Test Facility model creation."""
facility = Facility(
id=1,
name="Test Facility",
latitude=34.0522,
longitude=-118.2437,
address="123 Test St, Los Angeles, CA",
created_at=datetime.now(),
updated_at=datetime.now()
)
self.assertEqual(facility.id, 1)
self.assertEqual(facility.name, "Test Facility")
self.assertEqual(facility.latitude, 34.0522)
self.assertEqual(facility.longitude, -118.2437)
def test_detainee_location_history_model(self):
"""Test DetaineeLocationHistory model creation."""
location_history = DetaineeLocationHistory(
id=1,
detainee_id=1,
facility_id=1,
start_date=datetime.now(),
end_date=None,
created_at=datetime.now()
)
self.assertEqual(location_history.id, 1)
self.assertEqual(location_history.detainee_id, 1)
self.assertEqual(location_history.facility_id, 1)
self.assertIsNone(location_history.end_date)
class TestDatabaseManager(unittest.TestCase):
"""Test cases for database manager."""
def setUp(self):
"""Set up test database."""
# Use in-memory SQLite for testing
self.database_url = "sqlite:///:memory:"
self.db_manager = DatabaseManager(self.database_url)
# For a real PostgreSQL test, you would connect to a test database
def test_database_manager_initialization(self):
"""Test DatabaseManager initialization."""
self.assertEqual(self.db_manager.database_url, self.database_url)
self.assertIsNone(self.db_manager.connection)
# Note: The following tests would require a real database connection
# For a complete implementation, you would set up a test database
# and test actual database operations
def test_create_tables(self):
"""Test table creation (would require actual database)."""
# This test would connect to a test database and verify table creation
pass
def test_insert_detainee(self):
"""Test inserting a detainee (would require actual database)."""
# This test would insert a detainee and verify it was stored correctly
pass
def test_insert_facility(self):
"""Test inserting a facility (would require actual database)."""
# This test would insert a facility and verify it was stored correctly
pass
def test_insert_location_history(self):
"""Test inserting location history (would require actual database)."""
# This test would insert location history and verify it was stored correctly
pass
if __name__ == "__main__":
unittest.main()