from datetime import date import faker from preference_center.profile.models import Profile from preference_center.profile.types import ProfileValues, ValueChange from tests.unit.types import BuildModel def test_profile_changed_fields(build_model: BuildModel) -> None: old_email = "old@mail.com" new_email = "new@mail.com" profile = build_model(Profile, email=old_email) profile.email = new_email assert profile.has_changed assert profile.changed_fields == { "email": ValueChange(old_value=old_email, new_value=new_email) } def test_profile_set_values(build_model: BuildModel, faker: faker.Faker) -> None: old_values = ProfileValues( first_name=faker.unique.first_name(), last_name=faker.unique.last_name(), ) new_values = ProfileValues( first_name=faker.unique.first_name(), last_name=faker.unique.last_name(), ) profile = build_model(Profile, **old_values) profile.set_values(new_values) assert profile.has_changed assert profile.changed_fields == { "first_name": ValueChange( old_value=old_values["first_name"], new_value=new_values["first_name"], ), "last_name": ValueChange( old_value=old_values["last_name"], new_value=new_values["last_name"], ), } def test_profile_birthday_not_set(build_model: BuildModel) -> None: profile = build_model( Profile, date_of_birth=date(1990, 6, 16), birthday=None, ) assert profile.birthday == "06/16" def test_profile_birthday_set(build_model: BuildModel) -> None: profile = build_model( Profile, date_of_birth=date(1990, 6, 16), birthday="03/15", ) assert profile.birthday == "03/15"