Re: [Django] #21466: override_settings(LOGIN_URL=…) does not work when not first test

2014-03-17 Thread Django
#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
---+--
Changes (by timo):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 I think it's more likely that your use of `override_settings()` is
 invalid. Please be sure you've read the caveats in
 [https://docs.djangoproject.com/en/1.6/topics/testing/tools/#overriding-
 settings the documentation] and ask questions using our
 [https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
 support channels]. If after doing those setps you still believe you've
 found a bug, please open a new ticket, thanks.

-- 
Ticket URL: 
Django 
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.2c0840ad9b511375c617fa41c2c045df%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #21466: override_settings(LOGIN_URL=…) does not work when not first test

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

 * status:  closed => new
 * resolution:  invalid =>


Comment:

 apologies, I forgot to add the output of my tests!

 {{{
 ./manage.py test api
 Creating test database for alias 'default'...
 ...F
 ==
 FAIL: test_auth (api.tests.test_auth.AuthTest)
 --
 Traceback (most recent call last):
   File "/api/tests/test_auth.py", line 64, in test_auth
 self.assertEqual(response.status_code, 403)
 AssertionError: 201 != 403

 --
 Ran 60 tests in 29.056s

 FAILED (failures=1)
 Destroying test database for alias 'default'...
 }}}

 When i modify the setting to `True` in settings.py, the test passes
 without failure.

-- 
Ticket URL: 
Django 
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.7246fcda048cb5966aefb156152e7732%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #21466: override_settings(LOGIN_URL=…) does not work when not first test

2014-03-14 Thread Django
#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: 
Django 
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.


Re: [Django] #21466: override_settings(LOGIN_URL=…) does not work when not first test

2013-11-19 Thread Django
#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 jnns):

 Sorry for opening this ticket. You're right that this has nothing to do
 with Django.

 I used django-braces' `LoginRequiredMixin` which sets `settings.LOGIN_URL`
 at import time and replicated this bug in my example project without
 further reflecting upon this issue.

-- 
Ticket URL: 
Django 
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.a185a4ff2c7d64f9395599d51aa44764%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Django] #21466: override_settings(LOGIN_URL=…) does not work when not first test

2013-11-19 Thread Django
#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
---+--
Changes (by claudep):

 * status:  new => closed
 * needs_docs:   => 0
 * resolution:   => invalid
 * needs_tests:   => 0
 * needs_better_patch:   => 0


Comment:

 I'm almost sure the problem is related to the way you are using
 `settings.LOGIN_URL`. In your sample project, it is used as a parameter of
 the `as_view` call in your URLConf, that means that it will be defined
 once and for all requests at import time.
 You can workaround this issue by subclassing `RedirectView` and overriding
 `get_redirect_url()` so that when `settings.LOGIN_URL` changes your view
 can take that change into account. I don't think we can do anything on
 Django's side.

-- 
Ticket URL: 
Django 
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.b48e99dcb1ca50cad6fb19a301890b48%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


[Django] #21466: override_settings(LOGIN_URL=…) does not work when not first test

2013-11-19 Thread Django
#21466: override_settings(LOGIN_URL=…) does not work when not first test
---+--
 Reporter:  jnns   |  Owner:  nobody
 Type:  Bug| Status:  new
Component:  Testing framework  |Version:  1.6
 Severity:  Normal |   Keywords:  settings
 Triage Stage:  Unreviewed |  Has patch:  0
Easy pickings:  0  |  UI/UX:  0
---+--
 Overriding `LOGIN_URL` in the tests does not work when another test is run
 beforehand.

 {{{#!python

 from django.test import TestCase
 from django.test.utils import override_settings
 from django.core.urlresolvers import reverse
 from django.conf import settings


 class OverrideSettingsTest(TestCase):
 def test_a(self):
 """
 Toggle this test by commenting it out and see whether test_b()
 passes.
 """
 response = self.client.get(reverse("harmless-view"))
 self.assertEqual(response.status_code, 301)

 @override_settings(LOGIN_URL="/THIS_IS_FINE/")
 def test_b(self):
 # settings appear to be overridden as expected
 self.assertEqual(settings.LOGIN_URL, "/THIS_IS_FINE/")
 response = self.client.get(reverse("redirect-to-login"))

 # The following assertion fails only when test_a() is run.
 self.assertRedirects(response, "/THIS_IS_FINE/",
 status_code=301,
 target_status_code=404
 )

 def test_c(self):
 response = self.client.get(reverse("harmless-view"))
 self.assertEqual(response.status_code, 301)
 }}}


 {{{
 .F.
 ==
 FAIL: test_b (override_bug.tests.OverrideSettingsTest)
 --
 Traceback (most recent call last):
   File "django/test/utils.py", line 224, in inner
 return test_func(*args, **kwargs)
   File "override_bug/override_bug/tests.py", line 24, in test_b
 target_status_code=404
   File "django/test/testcases.py", line 617, in assertRedirects
 (url, expected_url))
 AssertionError: Response redirected to
 'http://testserver/THIS/SHOULD/BE/OVERRIDDEN/IN/THE/TEST/', expected
 'http://testserver/THIS_IS_FINE/'

 --
 Ran 3 tests in 0.031s
 }}}

-- 
Ticket URL: 
Django 
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/047.13a8291a44a1d9b998f29edb04960e5b%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.