diff --git a/greg/migrations/0002_auto_20210902_2159.py b/greg/migrations/0002_auto_20210902_2159.py new file mode 100644 index 0000000000000000000000000000000000000000..343e2095c6989ec0f8bf05f70d540601805a44c0 --- /dev/null +++ b/greg/migrations/0002_auto_20210902_2159.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.7 on 2021-09-02 21:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('greg', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='personidentity', + name='verified_when', + ), + migrations.AddField( + model_name='personidentity', + name='verified_at', + field=models.DateTimeField(null=True), + ), + ] diff --git a/greg/models.py b/greg/models.py index c523f781997ce24cb3eef3e4aff35e68fb555dd2..63a354ccd10dab94827a7ef9ee7ff48fa04f7c93 100644 --- a/greg/models.py +++ b/greg/models.py @@ -3,6 +3,8 @@ from datetime import ( datetime, ) +from greg.utils import utcnow + from dirtyfields import DirtyFieldsMixin from django.db import models from django.db.models import Lookup @@ -109,8 +111,8 @@ class Person(BaseModel): # the requirement is minimum one personal identity return ( self.identities.filter( - verified_when__isnull=False, - verified_when__lte=datetime.now(), + verified_at__isnull=False, + verified_at__lte=utcnow(), ).count() >= 1 ) @@ -221,17 +223,17 @@ class PersonIdentity(BaseModel): verified_by = models.ForeignKey( "Sponsor", on_delete=models.PROTECT, related_name="sponsor", null=True ) - verified_when = models.DateField(null=True) + verified_at = models.DateTimeField(null=True) def __repr__(self): - return "{}(id={!r}, type={!r}, source={!r}, value={!r}, verified_by={!r}, verified_when={!r})".format( + return "{}(id={!r}, type={!r}, source={!r}, value={!r}, verified_by={!r}, verified_at={!r})".format( self.__class__.__name__, self.pk, self.type, self.source, self.value, self.verified_by, - self.verified_when, + self.verified_at, ) class Meta: diff --git a/greg/tests/conftest.py b/greg/tests/conftest.py index 15c03b927e3141abc69b58216bbc283a0b4c3fe4..b1d6ff947e9d3ba87de460168f8f3783fd255ee2 100644 --- a/greg/tests/conftest.py +++ b/greg/tests/conftest.py @@ -83,7 +83,7 @@ def person_foo_verified(person_foo, sponsor_guy) -> PersonIdentity: value="12345", verified=PersonIdentity.Verified.MANUAL, verified_by=sponsor_guy, - verified_when="2021-06-15", + verified_at="2021-06-15T12:34:56Z", ) return PersonIdentity.objects.get(id=pi.id) diff --git a/greg/tests/models/test_person.py b/greg/tests/models/test_person.py index 950820667e386cfd0c4e9cf1c23ead0ef4e3ae99..8be21856704c8d1e3207820dd255fda3ac550ce4 100644 --- a/greg/tests/models/test_person.py +++ b/greg/tests/models/test_person.py @@ -1,7 +1,4 @@ -from datetime import ( - datetime, - timedelta, -) +from datetime import datetime, timedelta from functools import partial import pytest @@ -14,6 +11,7 @@ from greg.models import ( RoleType, Sponsor, ) +from greg.utils import utcnow role_with = partial( Role.objects.create, @@ -23,8 +21,8 @@ role_with = partial( available_in_search=True, ) -_a_year_ago = (datetime.now() - timedelta(days=365)).date() -_a_year_into_future = (datetime.now() + timedelta(days=365)).date() +_a_year_ago = utcnow() - timedelta(days=365) +_a_year_into_future = utcnow() + timedelta(days=365) @pytest.fixture @@ -57,7 +55,7 @@ def person_registered_future() -> Person: def feide_id() -> PersonIdentity: return PersonIdentity( type=PersonIdentity.IdentityType.FEIDE_ID, - verified_when=_a_year_ago, + verified_at=_a_year_ago, ) @@ -65,7 +63,7 @@ def feide_id() -> PersonIdentity: def passport() -> PersonIdentity: return PersonIdentity( type=PersonIdentity.IdentityType.PASSPORT, - verified_when=_a_year_ago, + verified_at=_a_year_ago, ) @@ -78,7 +76,7 @@ def unverified_passport() -> PersonIdentity: def future_identity() -> PersonIdentity: return PersonIdentity( type=PersonIdentity.IdentityType.NATIONAL_ID_CARD, - verified_when=_a_year_into_future, + verified_at=_a_year_into_future, ) @@ -135,7 +133,7 @@ def test_is_registered_completed_in_future(person_registered_future): @pytest.mark.django_db @pytest.mark.parametrize("identity_type", PersonIdentity.IdentityType) def test_is_verified(identity_type, person): - identity = PersonIdentity(type=identity_type, verified_when=_a_year_ago) + identity = PersonIdentity(type=identity_type, verified_at=_a_year_ago) person.identities.add(identity, bulk=False) assert person.is_verified @@ -147,7 +145,7 @@ def test_test_is_verified_multiple_identities(person, feide_id, passport): @pytest.mark.django_db -def test_is_verified_when_identity_is_unverified(person, unverified_passport): +def test_is_verified_at_identity_is_unverified(person, unverified_passport): person.identities.add(unverified_passport, bulk=False) assert not person.is_verified diff --git a/greg/tests/models/test_personidentity.py b/greg/tests/models/test_personidentity.py index e88e82a566a7fbdfb9b65a47c6fe95ea5767d50e..b2414bf604d2fa15dbad8d6357152cf61f14e8ac 100644 --- a/greg/tests/models/test_personidentity.py +++ b/greg/tests/models/test_personidentity.py @@ -5,5 +5,5 @@ import pytest def test_personidentity_repr(person_foo_verified): assert ( repr(person_foo_verified) - == "PersonIdentity(id=1, type='PASSPORT', source='Test', value='12345', verified_by=Sponsor(id=1, feide_id='guy@example.org', first_name='Sponsor', last_name='Guy'), verified_when=datetime.date(2021, 6, 15))" + == "PersonIdentity(id=1, type='PASSPORT', source='Test', value='12345', verified_by=Sponsor(id=1, feide_id='guy@example.org', first_name='Sponsor', last_name='Guy'), verified_at=datetime.datetime(2021, 6, 15, 12, 34, 56, tzinfo=<UTC>))" ) diff --git a/greg/tests/populate_database.py b/greg/tests/populate_database.py index 38103ad354ed965230c3d66bb6df49e7f2d9a4fd..b39f1104214b2e43f4ac52fa1041fbd11ef8a800 100644 --- a/greg/tests/populate_database.py +++ b/greg/tests/populate_database.py @@ -108,12 +108,12 @@ class DatabasePopulation: if self.random.random() > 0.5: sponsor = random.choice(self.sponsors) - verified_when = self.faker.date_this_year() + verified_at = self.faker.date_time_this_year() identity_type = random.choice(PersonIdentity.IdentityType.choices)[0] verified = self.faker.text(max_nb_chars=50) else: sponsor = None - verified_when = None + verified_at = None verified = "" PersonIdentity.objects.create( @@ -123,7 +123,7 @@ class DatabasePopulation: value=self.faker.numerify("##################"), verified_by=sponsor, verified=verified, - verified_when=verified_when, + verified_at=verified_at, ) person_identifier_count += 1 diff --git a/greg/tests/test_notifications.py b/greg/tests/test_notifications.py index ac4cf3d71e54704e18df2554d3fe8754371f160f..8e0798b37c1a4a070d63b40c8d5a4edb4596a4b8 100644 --- a/greg/tests/test_notifications.py +++ b/greg/tests/test_notifications.py @@ -204,7 +204,7 @@ def test_person_identity_update_notification( ): person_identity.verified = PersonIdentity.Verified.MANUAL person_identity.verified_by = sponsor - person_identity.verified_when = "2021-08-02" + person_identity.verified_at = "2021-08-02T12:34:56Z" person_identity.save() notifications = Notification.objects.filter(object_type="PersonIdentity")