Skip to content

Conversation

sebashwa
Copy link

I recently worked on a Django project with a custom user model, which uses an email as the username field and does not use the original username field. To make pytest-django work I have locally overwritten some fixtures of pytest-django.

To eventually get rid of the overrides I added tests (extended the test_custom_user_model test in tests/test_fixtures.py) to the changes made in #246.

I hope the tests are sufficient to get this merged, if not I am open for hints to write some more.
Also I hope it's fine that I created a new pull request for this (didn't know how to proceed).
I'm pretty new to python still, so don't hesitate to nitpick on the changes made 😰

hoh and others added 3 commits June 21, 2019 11:52
This fixes usecases whith a custom User model that uses an email address as the username, but has no username field present. An example of such model is present in the [Django doc on customizing authentication](https://docs.djangoproject.com/en/1.7/topics/auth/customizing/#a-full-example).
The function to introspect user model fields changed
in Django 1.10
The admin_user fixture should handle user models without a username
present.
@sebashwa sebashwa force-pushed the email_based_usermodel branch from 05f960f to 09afa63 Compare June 21, 2019 20:42
sebashwa added 2 commits June 22, 2019 00:53
This method is available in all Django versions considered.
It should be sufficient to use , because we do not need to care
about relational fields in our usecase.
@codecov-io
Copy link

Codecov Report

Merging #748 into master will decrease coverage by 0.04%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #748      +/-   ##
==========================================
- Coverage   98.06%   98.02%   -0.05%     
==========================================
  Files          32       32              
  Lines        1862     1872      +10     
  Branches      147      151       +4     
==========================================
+ Hits         1826     1835       +9     
  Misses         24       24              
- Partials       12       13       +1
Impacted Files Coverage Δ
tests/test_fixtures.py 99.61% <100%> (+0.01%) ⬆️
pytest_django/fixtures.py 95.95% <87.5%> (-0.46%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 33aa666...ac7016d. Read the comment docs.

manjitkumar pushed a commit to lendingloop/pytest-django that referenced this pull request Aug 19, 2019
jnns added a commit to jnns/pytest-django that referenced this pull request May 19, 2020
jnns added a commit to jnns/pytest-django that referenced this pull request May 19, 2020
The previous test setup inherited from AbstractUser thus MyCustomUser
still had a username field.

The problems people are having when using the admin_client fixture in
combination with a custom user model are due to the username field
not being present.

This change accounts for the more realistic scenario.

See these tickets:
pytest-dev#246
pytest-dev#484
pytest-dev#748
jnns added a commit to jnns/pytest-django that referenced this pull request May 19, 2020
The previous test setup inherited from AbstractUser thus MyCustomUser
still had a username field.

The problems people are having when using the admin_client fixture in
combination with a custom user model are due to the username field
not being present.

This change accounts for the more realistic scenario.

See these tickets:
pytest-dev#246
pytest-dev#484
pytest-dev#748
jnns added a commit to jnns/pytest-django that referenced this pull request May 19, 2020
The previous test setup inherited from AbstractUser thus MyCustomUser
still had a username field.

The problems people are having when using the admin_client fixture in
combination with a custom user model are due to the username field
not being present.

This change accounts for the more realistic scenario.

See these tickets:
pytest-dev#246
pytest-dev#484
pytest-dev#748
jnns added a commit to jnns/pytest-django that referenced this pull request May 19, 2020
The previous test setup inherited from AbstractUser thus MyCustomUser
still had a username field.

The problems people are having when using the admin_client fixture in
combination with a custom user model are due to the username field
not being present.

This change accounts for the more realistic scenario.

See these tickets:
pytest-dev#246
pytest-dev#484
pytest-dev#748
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants