pytest-django
pytest-django copied to clipboard
Add fixtures for user request factories, clients
Fixes #565
This is based on conversations in issues #553, #554, and #284
-
Introduces a django_user fixture, which is a user with no additional priveleges. Similar to admin_user.
-
A user_client, based on django_user. Similar to admin_client.
-
3 new RequestFactory based fixtures, for unauthenticated, authenticated, and admin users:
- rf_unauth: relies on AnonymousUser, similar to django docs example.
- rf_admin: relies on admin_user fixture
- rf_user: relies on new django_user fixture
In addition, these 3 fixtures differ from rf in that they:
- Mimic AuthenticationMiddleware by add the user attribute to the request object
- Mimic SessionMiddleware by adding the 'session' attribute
to the request object. This is an in-memory session store object
from
django.contrib.sessions.backends.base.SessionBase.
This fills the gaps left over by not having normal and unauthenticated user objects, clients, and request factories (when admin ones were available), and also covers a common case likely present in Django projects - anonymous (not logged in), authenticated, and admin users.
Codecov Report
Merging #568 into master will increase coverage by
0.37%. The diff coverage is97.53%.
@@ Coverage Diff @@
## master #568 +/- ##
=========================================
+ Coverage 91.92% 92.3% +0.37%
=========================================
Files 33 33
Lines 1660 1741 +81
Branches 143 144 +1
=========================================
+ Hits 1526 1607 +81
Misses 95 95
Partials 39 39
| Flag | Coverage Δ | |
|---|---|---|
| #dj110 | 84.66% <97.53%> (+0.74%) |
:arrow_up: |
| #dj111 | 86.73% <97.53%> (+0.64%) |
:arrow_up: |
| #dj18 | 85.46% <97.53%> (+0.7%) |
:arrow_up: |
| #dj19 | 84.54% <97.53%> (+0.75%) |
:arrow_up: |
| #dj20 | 84.95% <97.53%> (+0.73%) |
:arrow_up: |
| #djmaster | 84.95% <97.53%> (+0.73%) |
:arrow_up: |
| #mysql_innodb | 84.95% <97.53%> (+0.73%) |
:arrow_up: |
| #mysql_myisam | 84.89% <97.53%> (+0.73%) |
:arrow_up: |
| #postgres | 88.16% <97.53%> (+0.57%) |
:arrow_up: |
| #py27 | 89.71% <97.53%> (+0.5%) |
:arrow_up: |
| #py34 | 84.54% <97.53%> (+0.75%) |
:arrow_up: |
| #py35 | 84.66% <97.53%> (+0.74%) |
:arrow_up: |
| #py36 | 85.41% <97.53%> (+0.71%) |
:arrow_up: |
| #sqlite | 86.61% <97.53%> (+0.65%) |
:arrow_up: |
| #sqlite_file | 84.54% <97.53%> (+0.75%) |
:arrow_up: |
| Impacted Files | Coverage Δ | |
|---|---|---|
| pytest_django/plugin.py | 85.96% <100%> (+0.2%) |
:arrow_up: |
| tests/test_fixtures.py | 100% <100%> (ø) |
:arrow_up: |
| pytest_django/fixtures.py | 96.6% <95.74%> (-0.26%) |
:arrow_down: |
| pytest_django_test/app/views.py | 100% <0%> (+20%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 927d6c1...0f7f6e9. Read the comment docs.
e.g. django_rf_user, django_rf_admin, django_rf_unauth?
Is it okay if i 1. rebase against master 2. squash 5fccb31 and 722feac into my commits?
Yes, yes, and yes, please.. :)
@blueyed Updates
- rebased against master
- renamed new fixtures use
django_, including in tests and documentation - squashed in typo fixes from 5fccb31 and 722feac