From 61b91989e0d84eecfc9d1ce3d6103856399c4986 Mon Sep 17 00:00:00 2001 From: Raymond Penners Date: Wed, 5 Feb 2025 21:35:24 +0100 Subject: [PATCH] tests(headless): check authentication response during signup --- allauth/headless/account/tests/test_signup.py | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/allauth/headless/account/tests/test_signup.py b/allauth/headless/account/tests/test_signup.py index e689c27f0e..22c10926e8 100644 --- a/allauth/headless/account/tests/test_signup.py +++ b/allauth/headless/account/tests/test_signup.py @@ -3,6 +3,8 @@ from django.contrib.auth.models import User from allauth.account.models import EmailAddress, EmailConfirmationHMAC +from allauth.account.signals import user_logged_in +from allauth.headless.base.response import AuthenticationResponse from allauth.headless.constants import Flow @@ -15,17 +17,25 @@ def test_signup( headless_reverse, headless_client, ): - resp = client.post( - headless_reverse("headless:account:signup"), - data={ - "username": "wizard", - "email": email_factory(), - "password": password_factory(), - }, - content_type="application/json", - ) - assert resp.status_code == 200 - assert User.objects.filter(username="wizard").exists() + def on_user_logged_in(**kwargs): + response = kwargs["response"] + assert isinstance(response, AuthenticationResponse) + + user_logged_in.connect(on_user_logged_in) + try: + resp = client.post( + headless_reverse("headless:account:signup"), + data={ + "username": "wizard", + "email": email_factory(), + "password": password_factory(), + }, + content_type="application/json", + ) + assert resp.status_code == 200 + assert User.objects.filter(username="wizard").exists() + finally: + user_logged_in.disconnect(on_user_logged_in) def test_signup_with_email_verification(