from django.test import TestCase from access_core.identity.models import ( Beneficiary, BeneficiaryIdentifier, Role, User, UserRole, ) class UserTest(TestCase): def test_create_user(self): user = User.objects.create(email="test@example.com", full_name="Test User") self.assertEqual(user.email, "test@example.com") self.assertTrue(user.is_active) self.assertIsNotNone(user.id) class RoleTest(TestCase): def test_create_role(self): role = Role.objects.create(role_name="admin", description="Administrator") self.assertEqual(role.role_name, "admin") self.assertTrue(role.is_active) class UserRoleTest(TestCase): def setUp(self): self.user = User.objects.create(email="test@example.com", full_name="Test User") self.role = Role.objects.create(role_name="admin") def test_assign_role(self): ur = UserRole.objects.create(user=self.user, role=self.role) self.assertEqual(ur.user, self.user) self.assertEqual(ur.role, self.role) self.assertIsNone(ur.revoked_at) class BeneficiaryTest(TestCase): def test_create_beneficiary(self): from access_core.intake.models import IntakeRecord intake = IntakeRecord.objects.create( external_form_id="synth-001", first_name="Jane", last_name="Doe", dob="1960-01-15", sex="female", is_synthetic=True, ) ben = Beneficiary.objects.create( intake_record=intake, first_name="Jane", last_name="Doe", dob="1960-01-15", sex="female", is_synthetic=True, ) self.assertEqual(ben.first_name, "Jane") self.assertTrue(ben.is_synthetic) self.assertEqual(str(ben), "Jane Doe (synthetic=True)") class BeneficiaryIdentifierTest(TestCase): def test_create_identifier(self): from access_core.intake.models import IntakeRecord intake = IntakeRecord.objects.create( external_form_id="synth-002", first_name="John", last_name="Smith", dob="1955-06-20", sex="male", ) ben = Beneficiary.objects.create( intake_record=intake, first_name="John", last_name="Smith", dob="1955-06-20", sex="male", is_synthetic=True, ) ident = BeneficiaryIdentifier.objects.create( beneficiary=ben, identifier_type="email", identifier_value="synthetic@example.com", is_primary=True, ) self.assertTrue(ident.is_primary)