-
-
Notifications
You must be signed in to change notification settings - Fork 22
Run the entire test suite using pytest #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,6 @@ | |
"DJANGO_SECRET_KEY", | ||
default="AcnZMguCngDeMgbwXf6l9d2arow2lU9ZkDweNnoCZmZ2qH6pinB4tLhEYI4Fgf6Y", | ||
) | ||
# https://docs.djangoproject.com/en/dev/ref/settings/#test-runner | ||
TEST_RUNNER = "django.test.runner.DiscoverRunner" | ||
|
||
# CACHES | ||
# ------------------------------------------------------------------------------ | ||
|
@@ -27,11 +25,6 @@ | |
} | ||
} | ||
|
||
# PASSWORDS | ||
# ------------------------------------------------------------------------------ | ||
# https://docs.djangoproject.com/en/dev/ref/settings/#password-hashers | ||
PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I've done this is because the passwords in the fixture files were encrypted using the default hasher, so this was causing all the auth-based tests to fail (the hashes didn't match). This didn't manifest when running the tests with django's own runner because it wasn't set up to use this file at all - it was using Another approach would have been to rebuild all the fixtures, but this was easier (and makes a minimal difference to test suite speed). If you end up switching all your tests to create test data on-the-fly using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have a community discussion about which hashing method we want to use for passwords in the DB - we're using Argon2 ATM (recommended in the Django docs - but not the default, which is PBKDF2), which is why the fixutres have the hashes they do. So I recommend using |
||
|
||
# TEMPLATES | ||
# ------------------------------------------------------------------------------ | ||
TEMPLATES[0]["OPTIONS"]["loaders"] = [ # noqa F405 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[pytest] | ||
python_files = tests.py test_*.py *_tests.py | ||
norecursedirs = staticfiles .git templates __pycache__ | ||
DJANGO_SETTINGS_MODULE = config.settings.test | ||
FAIL_INVALID_TEMPLATE_VARS = 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from rest_framework import status, serializers | ||
from rest_framework.test import APITestCase | ||
from rest_framework_jwt.settings import api_settings | ||
from django.core.management import call_command | ||
from django.contrib.auth import get_user_model | ||
|
||
|
||
|
@@ -12,14 +10,16 @@ | |
|
||
class UserauthTests(APITestCase): | ||
|
||
fixtures = ['users'] | ||
|
||
def setUp(self): | ||
""" | ||
Loads users.json fixture into test DB and directly creates a new user. | ||
""" | ||
call_command('loaddata', 'users.json', verbosity=0) | ||
# create a new user | ||
model = get_user_model() | ||
self.person = model.objects.create_user(username='PetuniaPig', email='[email protected]', | ||
password='codebuddies') | ||
self.person = model.objects.create_user( | ||
username='PetuniaPig', | ||
email='[email protected]', | ||
password='codebuddies' | ||
) | ||
|
||
|
||
def test_jwt_not_authed(self): | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -10,6 +10,5 @@ class User(AbstractUser): | |||
# around the globe. | ||||
name = CharField(_("Name of User"), blank=True, max_length=255) | ||||
|
||||
@property | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we need to remove this decorator, out of curiosity? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is explained in the commit message for 03770f4 To work through a more concrete example of the problem this causes: property:
method:
Side note: It doesn't issue a redirect to a useful URL because of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On closer inspection, we should remove the redirect method altogether, & also remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll open an issue for that (and probably chuck it into the PR for our testing re-write)...unless there are any objections?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 'view on site' button is probably not that helpful for an API project, but I picked it as an example of an internal call that expects If you reeeally want a property version, we could also declare @property
def absolute_url(self):
return self.get_absolute_url()
It can be done as its own PR - should be no dependency/merge conflict there |
||||
def get_absolute_url(self): | ||||
return reverse("users:detail", kwargs={"username": self.username}) |
Uh oh!
There was an error while loading. Please reload this page.