#26122: Weird test regression in 1.8.5
-----------------------------------+--------------------------------------
     Reporter:  knyghty            |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  1.9
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------
Changes (by knyghty):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> Smallest example I could get to:
>
> {{{
> # forms.py
> from django import forms
> from django.contrib.auth import get_user_model
>

> class InlineEditEmailForm(forms.ModelForm):
>     class Meta:
>         model = get_user_model()
>         fields = ['email']
>

> # views.py
> import copy
>
> from django.http import HttpResponse
>
> from .forms import InlineEditEmailForm
>

> def edit_user_email(request):
>     user = request.user
>     old_user_data = copy.copy(user)
>     form = InlineEditEmailForm(data=request.POST, instance=user)
>     if form.is_valid():
>         new_user_data = form.cleaned_data
>         user = form.save()
>
>         if old_user_data.email != new_user_data['email']:
>             response = HttpResponse()
>             response.status_code = 200
>             return response
>
>     response = HttpResponse()
>     response.status_code = 400
>     return response
>

> # tests.py
> from django.contrib.auth import get_user_model
> from django.test import TestCase
>

> class EditUserEmailTestCase(TestCase):
>
>     def test_post(self):
>         get_user_model().objects.create_user('test', '[email protected]',
> 'pw')
>         data = {'email': '[email protected]'}
>         self.client.login(username='test', password='pw')
>         response = self.client.post('/', data)
>         self.assertEqual(response.status_code, 200)
>
> }}}
>

> * Works in 1.8.4, doesn't work in 1.8.5+ or 1.9.
> * Works when using a browser, only fails during tests.
> * Changing first line of the view to {{{user =
> get_user_model().objects.create_user(...)}}} makes the test pass again.

New description:

 Smallest example I could get to:

 {{{#!python
 # forms.py
 from django import forms
 from django.contrib.auth import get_user_model


 class InlineEditEmailForm(forms.ModelForm):
     class Meta:
         model = get_user_model()
         fields = ['email']


 # views.py
 import copy

 from django.http import HttpResponse

 from .forms import InlineEditEmailForm


 def edit_user_email(request):
     user = request.user
     old_user_data = copy.copy(user)
     form = InlineEditEmailForm(data=request.POST, instance=user)
     if form.is_valid():
         new_user_data = form.cleaned_data
         user = form.save()

         if old_user_data.email != new_user_data['email']:
             response = HttpResponse()
             response.status_code = 200
             return response

     response = HttpResponse()
     response.status_code = 400
     return response


 # tests.py
 from django.contrib.auth import get_user_model
 from django.test import TestCase


 class EditUserEmailTestCase(TestCase):

     def test_post(self):
         get_user_model().objects.create_user('test', '[email protected]',
 'pw')
         data = {'email': '[email protected]'}
         self.client.login(username='test', password='pw')
         response = self.client.post('/', data)
         self.assertEqual(response.status_code, 200)

 }}}


 * Works in 1.8.4, doesn't work in 1.8.5+ or 1.9.
 * Works when using a browser, only fails during tests.
 * Changing first line of the view to {{{user =
 get_user_model().objects.create_user(...)}}} makes the test pass again.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26122#comment:1>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.83c655d44e5a99243e8eb966721cb533%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to