From 20a310506da0fd28367002fff392022d36e15695 Mon Sep 17 00:00:00 2001 From: Sivert Kronen Hatteberg <skh@uio.no> Date: Wed, 10 Nov 2021 15:17:25 +0100 Subject: [PATCH] Fix tests after merge --- gregui/tests/api/test_invitation.py | 36 ++++++++----------- gregui/tests/api/test_invite_guest.py | 4 +-- .../tests/authentication/test_user_profile.py | 13 ++++--- gregui/tests/conftest.py | 20 +++++------ 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/gregui/tests/api/test_invitation.py b/gregui/tests/api/test_invitation.py index cfe46caa..4c026c62 100644 --- a/gregui/tests/api/test_invitation.py +++ b/gregui/tests/api/test_invitation.py @@ -55,7 +55,7 @@ def test_get_invited_info_session_okay( last_name=person.last_name, email=person.private_email.value, mobile_phone=None, - fnr=person.fnr.value, + fnr=None, passport=None, feide_id=None, ) @@ -102,13 +102,9 @@ def test_invited_guest_can_post_information( # post updated info to confirm from guest new_email = "private@example.org" - new_phone = "+4712345678" - data = dict( - mobile_phone=new_phone, - first_name=person_invited.first_name, - last_name=person_invited.last_name, - ) - data["email"] = new_email + new_phone = "+4790000000" + data = {"person": {"mobile_phone": new_phone, "new_email": new_email}} + response = client.post( reverse("gregui-v1:invited-info"), data, @@ -120,6 +116,7 @@ def test_invited_guest_can_post_information( # Check that the object was updated in the database assert Person.objects.count() == 1 assert person.private_mobile.value == new_phone + assert person.private_email.value == new_email @pytest.mark.django_db @@ -152,9 +149,8 @@ def test_post_invited_info_deleted_inv_link(client, invitation_link): @pytest.mark.django_db -def test_post_invited_info_invalid_national_id_number( - client, invitation_link, person_foo_data, person -): +def test_post_invited_info_invalid_national_id_number(client, invited_person): + person, invitation_link = invited_person data = { "person": { "mobile_phone": "+4707543001", @@ -179,9 +175,8 @@ def test_post_invited_info_invalid_national_id_number( @pytest.mark.django_db -def test_post_invited_info_valid_national_id_number( - client, invitation_link, person_foo_data, person -): +def test_post_invited_info_valid_national_id_number(client, invited_person): + person, invitation_link = invited_person fnr = "11120618212" data = { "person": { @@ -206,15 +201,11 @@ def test_post_invited_info_valid_national_id_number( @pytest.mark.django_db -def test_email_update(client, invitation_link, person_foo_data, person): - email_test = "test@example.com" +def test_email_update(client, invited_person): + person, invitation_link = invited_person + email_test = person.private_email.value url = reverse("gregui-v1:invited-info") - Identity.objects.create( - person=person, - type=Identity.IdentityType.PRIVATE_EMAIL, - value=email_test, - ) person.private_email.refresh_from_db() assert person.private_email.value == email_test @@ -231,7 +222,8 @@ def test_email_update(client, invitation_link, person_foo_data, person): @pytest.mark.django_db -def test_register_passport(client, invitation_link, person_foo_data, person): +def test_register_passport(client, invited_person): + person, invitation_link = invited_person passport_information = "EN-123456789" data = {"person": {"mobile_phone": "+4797543992", "passport": passport_information}} url = reverse("gregui-v1:invited-info") diff --git a/gregui/tests/api/test_invite_guest.py b/gregui/tests/api/test_invite_guest.py index 4c819f99..c070417e 100644 --- a/gregui/tests/api/test_invite_guest.py +++ b/gregui/tests/api/test_invite_guest.py @@ -61,9 +61,7 @@ def test_invite_guest(client, user_sponsor, unit_foo, role_type_foo): @pytest.mark.django_db -def test_invite_cancel( - client, invitation_link, invitation, role, log_in, sponsor_guy, user_sponsor -): +def test_invite_cancel(client, invitation_link, invitation, role, log_in, user_sponsor): # TODO: Should all sponsors be allowed to delete arbitrary invitations? log_in(user_sponsor) url = reverse("gregui-v1:invitation") diff --git a/gregui/tests/authentication/test_user_profile.py b/gregui/tests/authentication/test_user_profile.py index 98c5d478..0ea99b39 100644 --- a/gregui/tests/authentication/test_user_profile.py +++ b/gregui/tests/authentication/test_user_profile.py @@ -147,17 +147,16 @@ def test_invited_user(invited_person): backend = GregOIDCBackend() backend.request = auth_request - feide_id = ( - person.identities.filter(type=Identity.IdentityType.FEIDE_ID).first().value - ) - with pytest.raises(GregUserProfile.DoesNotExist): GregUserProfile.objects.get(person=person) + feide_id = "foo@bar.com" + nin = "12345678910" + claims = { "sub": "subsub", "connect-userid_sec": [f"feide:{feide_id}"], - "dataporten-userid_sec": [f"feide:{feide_id}", f"nin:{person.fnr.value}"], + "dataporten-userid_sec": [f"feide:{feide_id}", f"nin:{nin}"], "name": f"{person.first_name} {person.last_name}", "email": f"{person.private_email.value}", "email_verified": True, @@ -166,6 +165,8 @@ def test_invited_user(invited_person): user = backend.create_user(claims) user_profile = GregUserProfile.objects.get(user=user) + + person.refresh_from_db() assert user_profile.person == person assert user_profile.sponsor is None @@ -178,8 +179,10 @@ def test_invited_user(invited_person): ).all() assert len(person_nins) == 1 assert person_nins[0].verified == Identity.Verified.AUTOMATIC + assert person_nins[0].value == nin assert len(person_feide_ids) == 1 assert person_feide_ids[0].verified == Identity.Verified.AUTOMATIC + assert person_feide_ids[0].value == feide_id @pytest.mark.django_db diff --git a/gregui/tests/conftest.py b/gregui/tests/conftest.py index 7aefec5c..53b04a30 100644 --- a/gregui/tests/conftest.py +++ b/gregui/tests/conftest.py @@ -174,10 +174,10 @@ def create_role() -> Callable[[Person, Sponsor, OrganizationalUnit, RoleType], R ) -> Role: role = Role( person=person, - sponsor_id=sponsor, - orgunit_id=unit, + sponsor=sponsor, + orgunit=unit, end_date="2050-10-15", - type_id=role_type.id, + type=role_type, ) role.save() return Role.objects.get(id=role.id) @@ -321,10 +321,7 @@ def person_foo(create_person) -> Person: @pytest.fixture def person_invited(create_person) -> Person: """Invited person before registration.""" - person = create_person( - first_name="Foo", - last_name="Bar", - ) + person = create_person(first_name="Foo", last_name="Bar", email="foo@example.org") return Person.objects.get(id=person.id) @@ -333,7 +330,7 @@ def invited_person( create_role, create_invitation, create_invitation_link, - person_foo, + person_invited, sponsor_foo, unit_foo, role_type_foo, @@ -343,13 +340,16 @@ def invited_person( """ role = create_role( - person=person_foo, sponsor=sponsor_foo, unit=unit_foo, role_type=role_type_foo + person=person_invited, + sponsor=sponsor_foo, + unit=unit_foo, + role_type=role_type_foo, ) invitation = create_invitation(role=role) invitation_link = create_invitation_link(invitation=invitation) - return Person.objects.get(id=person_foo.id), InvitationLink.objects.get( + return Person.objects.get(id=person_invited.id), InvitationLink.objects.get( id=invitation_link.id ) -- GitLab