Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't raise UserWarning 'No request passed to the backend' during tests #41

Open
ciarancourtney opened this issue Jan 11, 2018 · 2 comments

Comments

@ciarancourtney
Copy link

What would be the accepted method to stop this from happening during mocked auth unit tests?

  • Wrap tests with ignore UserWarning?
  • Add setting to turn UserWarning on/off?

Thanks

@scjody
Copy link
Contributor

scjody commented Mar 14, 2018

This warning happens for us whenever we call self.client.login() during tests. Workaround:

from django.contrib.auth.models import AnonymousUser
from django.urls import reverse
from django.test import RequestFactory, TestCase

class SomethingTests(TestCase):
    def setUp(self):
        factory = RequestFactory()
        self.login_request = factory.get(reverse('login'))
        self.login_request.user = AnonymousUser

        super(TestCase, self).setUp()

    def test_method(self):
        self.client.login(username='user', password='pass', request=self.login_request)

@ciarancourtney
Copy link
Author

I ended up using this snippet in my testing.py settings

import warnings
# https://github.com/brutasse/django-ratelimit-backend/issues/41
warnings.filterwarnings('ignore', message="No request passed to the backend", category=UserWarning)

ciarancourtney added a commit to ciarancourtney/django-ratelimit-backend that referenced this issue Nov 19, 2018
ciarancourtney added a commit to ciarancourtney/django-ratelimit-backend that referenced this issue Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants