Opened 5 years ago

Last modified 5 years ago

#26122 closed Bug

Weird test regression in 1.8.5 — at Initial Version

Reported by: Tom Carrick Owned by: nobody
Component: Utilities Version: 1.8
Severity: Release blocker Keywords:
Cc: Ben Kraft Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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', 'x@example.com', 'pw')
        data = {'email': 'test@example.com'}
        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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top