Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#10908 closed (fixed)

Information about proper way of user creation for testing

Reported by: gruszczy Owned by: nobody
Component: Documentation Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I have created user using User.objects.create and then tried Client().login and it constantly fails. The proper way was to user User.objects.create_user, but there was not a word in testing docs! There should be such information. Here is the link: http://docs.djangoproject.com/en/dev/topics/testing/#django.test.client.Client.login

Attachments (2)

docs.patch (671 bytes) - added by gruszczy 6 years ago.
10908.diff (843 bytes) - added by timo 6 years ago.
slightly updated patch with links to methods

Download all attachments as: .zip

Change History (10)

comment:1 Changed 6 years ago by gruszczy

  • Component changed from Uncategorized to Documentation
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 in reply to: ↑ description ; follow-up: Changed 6 years ago by ramiro

Replying to gruszczy:

I have created user using User.objects.create and then tried Client().login and it constantly fails. The proper way was to user User.objects.create_user, but there was not a word in testing docs! There should be such information. Here is the link: http://docs.djangoproject.com/en/dev/topics/testing/#django.test.client.Client.login

Are you sure you are correctly using create()? This test shows an user can be created without having to resort to use create_user() and the documentation says it is "The most basic way" not that it is the proper or exclusive way to add an user.

comment:3 in reply to: ↑ 2 Changed 6 years ago by timo

+1. I had this problem recently as well. I think the issue is that using create() doesn't hash the password. I had to use set_password() until I discovered create_user().

comment:4 Changed 6 years ago by gruszczy

I don't know, if it's useful, but I have written this additional line and I am uploading diff.

Changed 6 years ago by gruszczy

comment:5 Changed 6 years ago by gruszczy

  • Has patch set

Changed 6 years ago by timo

slightly updated patch with links to methods

comment:6 Changed 6 years ago by timo

  • Triage Stage changed from Unreviewed to Ready for checkin
  • Version changed from 1.0 to SVN

comment:7 Changed 6 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [11248]) Fixed #10908 -- Clarified the procedure for creating test users in the testing docs. Thanks to gruszczy and timo.

comment:8 Changed 6 years ago by russellm

(In [11254]) [1.0.X] Fixed #10908 -- Clarified the procedure for creating test users in the testing docs. Thanks to gruszczy and timo.

Merge of r11248 from trunk.

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