#21466: override_settings(LOGIN_URL=…) does not work when not first test
-----------------------------------+--------------------------------------
     Reporter:  jnns               |                    Owner:  nobody
         Type:  Bug                |                   Status:  closed
    Component:  Testing framework  |                  Version:  1.6
     Severity:  Normal             |               Resolution:  invalid
     Keywords:  settings           |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------

Comment (by matthewf@…):

 I think I'm hitting the same issue as well. In my project, I have set a
 variable called `REGISTRATION_ENABLED`. However, when I try to override
 this setting in my tests, it's never read. Changing the setting beforehand
 in my settings.py makes the test pass, however. This is how it's used in
 my tests:

 {{{
 def test_auth(self):
         """
         Test that a user can register using the API, login and logout
         """
         # test registration workflow
         submit = {
             'username': 'Otto',
             'password': 'password',
             'first_name': 'first_name',
             'last_name': 'last_name',
             'email': 'em...@email.com',
             'is_superuser': False,
             'is_staff': False,
         }
         url = '/api/auth/register'
         response = self.client.post(url, json.dumps(submit),
 content_type='application/json')
         self.assertEqual(response.status_code, 201)
         # test disabled registration
         with self.settings(REGISTRATION_ENABLED=False):
             submit['username'] = 'anothernewuser'
             response = self.client.post(url, json.dumps(submit),
 content_type='application/json')
             self.assertEqual(response.status_code, 403)
 }}}

 And the code block in my views:

 {{{
 class HasRegistrationAuth(permissions.BasePermission):
     """
     Checks to see if registration is enabled
     """
     def has_permission(self, request, view):
         return settings.REGISTRATION_ENABLED
 }}}

 Note that I'm using https://github.com/tomchristie/django-rest-framework
 in my application.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21466#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.a8213b4934a2e66c9f8bfda70b5996df%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to