"""Fan Model unit tests.""" import pytest from src.models.fan import ProfileUpdatedV1 from src.models.fan import ProfileDeletedV1 from src.models.fan import SForceFanUpdate def test_profile_updated_full(fan_updated_full): """Test ProfileUpdatedV1 model with a full message.""" profile_updated = ProfileUpdatedV1(**fan_updated_full) assert len(profile_updated.updatedFields) == 11 def test_profile_updated_partial(fan_updated_email_only): """Test ProfileUpdatedV1 model with a partial message.""" profile_updated = ProfileUpdatedV1(**fan_updated_email_only) assert len(profile_updated.updatedFields) == 1 def test_sforce_update_from_profile_update_full(fan_updated_full): """Test creation of SForceFanUpdate model from a full ProfileUpdatedV1.""" profile_updated = ProfileUpdatedV1(**fan_updated_full) sforce_update = SForceFanUpdate.from_profile_update(profile_updated) assert sforce_update.First_Name__c == 'Mary' assert sforce_update.Delete_My_Information__c is None def test_sforce_update_from_profile_update_partial(fan_updated_email_only): """Test creation of SForceFanUpdate model from a partial ProfileUpdatedV1.""" profile_updated = ProfileUpdatedV1(**fan_updated_email_only) sforce_update = SForceFanUpdate.from_profile_update(profile_updated) assert sforce_update.Email__c == 'new@mail.com' # Assert that only the email field is updated assert sforce_update.to_dict() == {'Email__c': 'new@mail.com'} def test_sforce_update_from_profile_update_partial_with_nullables(fan_updated_with_nullables): """Test creation of SForceFanUpdate model from a partial ProfileUpdatedV1.""" profile_updated = ProfileUpdatedV1(**fan_updated_with_nullables) sforce_update = SForceFanUpdate.from_profile_update(profile_updated) assert sforce_update.Mobile_Phone__c is None # Assert empty phone number is kept in dict representation as None assert sforce_update.to_dict() == {'Mobile_Phone__c': None} @pytest.mark.parametrize('updated_gender, sforce_gender', [ ('MALE', 'Male'), ('FEMALE', 'Female'), ('PREFER_NOT_TO_ANSWER', 'Prefer not to answer'), ('NON_BINARY_OTHER', 'Non-binary/Other'), ]) def test_profile_updated_gender(updated_gender: str, sforce_gender: str): """Test ProfileUpdatedV1 model with a partial message.""" profile_updated = ProfileUpdatedV1(**{ 'id': '5fb6ed75-f775-4384-9021-e6c9fabb7ce7', 'crmId': 'arUQAvjFGaKEesRUXnkI', 'updatedAt': '2010-12-09T14:47:04', 'updatedFields': [ { 'fieldName': 'gender', 'oldValue': 'MALE', 'newValue': updated_gender } ] }) sforce_update = SForceFanUpdate.from_profile_update(profile_updated) assert sforce_update.Gender__c == sforce_gender def test_sforce_update_from_profile_delete(): """Test creation of SForceFanUpdate model for a deletion message.""" profile_deleted = ProfileDeletedV1(**{ 'id': '5fb6ed75-f775-4384-9021-e6c9fabb7ce7', 'crmId': 'arUQAvjFGaKEesRUXnkI', 'deletedAt': '2010-12-09T14:47:04' }) sforce_delete = SForceFanUpdate.from_profile_delete(profile_deleted) assert sforce_delete.Delete_My_Information__c is True assert sforce_delete.Delete_Reason__c == 'Fan Requested' assert sforce_delete.Delete_Request_Date__c == '2010-12-09T14:47:04'