PedroBern / django-graphql-auth

Django registration and authentication with GraphQL.

Home Page:https://django-graphql-auth.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to run test with register mutation

luis-amarquez opened this issue · comments

Prerequisites

  • Is it a bug?
  • Is it a new feature?
  • Is it a a question?
  • Can you reproduce the problem?
  • Are you running the latest version?
  • Did you check for similar issues?
  • Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Description

I am trying to run a test that includes registering a new user and being able to get a token. Currently however, whenever I try to run the test, I get an error:

Traceback (most recent call last):
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql\execution\executor.py", line 452, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql\execution\executors\sync.py", line 16, in execute
    return fn(*args, **kwargs)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphene\relay\mutation.py", line 70, in mutate
    result = cls.mutate_and_get_payload(root, info, **input)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql_auth\bases.py", line 45, in mutate_and_get_payload
    return cls.resolve_mutation(root, info, **kwargs)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql_auth\mixins.py", line 108, in resolve_mutation
    user.status.send_activation_email(info)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql_auth\models.py", line 74, in send_activation_email
    email_context = self.get_email_context(
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql_auth\models.py", line 59, in get_email_context
    site = get_current_site(info.context)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\django\contrib\sites\shortcuts.py", line 16, in get_current_site
    return RequestSite(request)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\django\contrib\sites\requests.py", line 10, in __init__
    self.domain = self.name = request.get_host()
AttributeError: 'NoneType' object has no attribute 'get_host'
Traceback (most recent call last):
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql\execution\executor.py", line 452, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql\execution\executors\sync.py", line 16, in execute
    return fn(*args, **kwargs)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphene\relay\mutation.py", line 70, in mutate
    result = cls.mutate_and_get_payload(root, info, **input)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql_auth\bases.py", line 45, in mutate_and_get_payload
    return cls.resolve_mutation(root, info, **kwargs)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql_auth\mixins.py", line 108, in resolve_mutation
    user.status.send_activation_email(info)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql_auth\models.py", line 74, in send_activation_email
    email_context = self.get_email_context(
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\graphql_auth\models.py", line 59, in get_email_context
    site = get_current_site(info.context)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\django\contrib\sites\shortcuts.py", line 16, in get_current_site
    return RequestSite(request)
  File "C:\Users\luism\Desktop\Projects\KeySportTechnologies\Backend\venv\lib\site-packages\django\contrib\sites\requests.py", line 10, in __init__
    self.domain = self.name = request.get_host()
graphql.error.located_error.GraphQLLocatedError: 'NoneType' object has no attribute 'get_host'
# tests.py
from django.test.testcases import TestCase
from graphene.test import Client
from mixer.backend.django import Mixer

from schema.schema import schema
from user.models import User

mixer = Mixer(commit=False)


class AccountTests(TestCase):
    def setUp(self):
        self.client = Client(schema)
        ...

    def test_authorized_user_change(self):
        request = self.client.execute(self.REGISTER_USER_MUTATION, variables=self.data)
        ...

I know that the issue has to do with sending the account activation email because when I go into settings.py and set SEND_ACTIVATION_EMAIL to False, I get no error.

Is the best way to bypass this issue leaving SEND_ACTIVATION_EMAIL to False, manually verifying the user or is there a way to include the Host header in the request so that I do not get the error? Is there a better way to create a user and have him verified in the graphql_auth_userstatus table?