-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix tests for login and registration auto login
- Loading branch information
Sascha Dobbelaere
committed
Dec 12, 2023
1 parent
230794e
commit d38e49f
Showing
9 changed files
with
64 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from strawberry_django.resolvers import django_resolver | ||
from asgiref.sync import async_to_sync | ||
from core.factories.multi_tenant import RegisterUserFactory | ||
from strawberry_django.utils.requests import get_request | ||
from channels import auth as channels_auth | ||
from django.contrib import auth | ||
|
||
from .mutation_classes import CleanupDataMixin | ||
|
||
|
||
@django_resolver | ||
def resolve_register_user(info, username: str, password: str, language: str): | ||
request = get_request(info) | ||
|
||
fac = RegisterUserFactory(username=username, password=password, language=language) | ||
fac.run() | ||
|
||
user = fac.user | ||
|
||
try: | ||
# We dont have any need for the classic django-auth outside of the | ||
# tests. So this is why this try except clause exists. | ||
auth.login(request, user) | ||
except AttributeError: | ||
# ASGI in combo with websockets needs the channels login functionality. | ||
# to ensure we're talking about channels, let's veriy that our | ||
# request is actually channelsrequest | ||
try: | ||
scope = request.consumer.scope # type: ignore | ||
async_to_sync(channels_auth.login)(scope, user) # type: ignore | ||
# According to channels docs you must save the session | ||
scope["session"].save() | ||
except (AttributeError, NameError): | ||
# When Django-channels is not installed, | ||
# this code will be non-existing | ||
pass | ||
|
||
# scope = request.consumer.scope | ||
# async_to_sync(channels_auth.login)(scope, user) | ||
# # According to channels docs you must save the session | ||
# scope["session"].save() | ||
|
||
return user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters