Skip to content

Commit

Permalink
Use MD5 hashes for testing, remove unverified_user and make --reuse-d…
Browse files Browse the repository at this point in the history
…b default
  • Loading branch information
jochenklar committed Nov 15, 2024
1 parent 9ab5f44 commit 8c7959c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 57 deletions.
36 changes: 23 additions & 13 deletions daiquiri/auth/tests/test_accounts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.urls import reverse

from allauth.account.models import EmailAddress

from ..models import Profile


Expand All @@ -14,20 +16,20 @@ def test_login(db, client):


def test_login_unverified(db, client):
email = EmailAddress.objects.filter(user__username='user').first()
email.verified = False
email.save()

url = reverse('account_login')
response = client.post(url, {
'login': 'unverified_user',
'login': 'user',
'password': 'user'
})

# check that the signup redirects to the pending page or the confirm email page
assert response.status_code == 302
assert response.url == reverse('account_email_verification_sent')

# check that a profile is pending
profile = Profile.objects.get(user__username='unverified_user')
assert profile.is_pending is True


def test_invalid(db, client):
url = reverse('account_login')
Expand Down Expand Up @@ -71,12 +73,16 @@ def test_signup_post_email_exists_verified(db, client):


def test_signup_post_email_exists_unverified(db, client):
email = EmailAddress.objects.filter(user__username='user').first()
email.verified = False
email.save()

url = reverse('account_signup')
response = client.post(url, {
'email': 'user_unverif@example.com',
'username': 'unverified_user_2',
'first_name': 'Gregor2',
'last_name': 'Unverified',
'email': 'user@example.com',
'username': 'user2',
'first_name': 'Tanja',
'last_name': 'Test',
'password1': 'testing',
'password2': 'testing'
})
Expand All @@ -90,12 +96,16 @@ def test_signup_post_email_exists_unverified(db, client):


def test_signup_post_user_exists_unverified(db, client):
email = EmailAddress.objects.filter(user__username='user').first()
email.verified = False
email.save()

url = reverse('account_signup')
response = client.post(url, {
'email': 'user_unverif@example2.com',
'username': 'unverified_user',
'first_name': 'Gregor',
'last_name': 'Unverified',
'email': 'user@example.com',
'username': 'user',
'first_name': 'Tanja',
'last_name': 'Test',
'password1': 'testing',
'password2': 'testing'
})
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ DJANGO_SETTINGS_MODULE = "testing.config.settings"
testpaths = ["daiquiri"]
python_files = "test_*.py"
python_paths = ["testing/"]
addopts = '--reuse-db'

[tool.coverage.run]
source = ["daiquiri"]
Expand Down
4 changes: 4 additions & 0 deletions testing/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
SITE_URL = 'http://testserver'
SITE_CREATED = '2020-01-01'

PASSWORD_HASHERS = (
"django.contrib.auth.hashers.MD5PasswordHasher",
)

INSTALLED_APPS = [
*DJANGO_APPS,
'daiquiri.auth',
Expand Down
49 changes: 5 additions & 44 deletions testing/fixtures/auth.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"model": "auth.user",
"pk": 1,
"fields": {
"password": "pbkdf2_sha256$36000$MzIAc1btLrHn$B+ZI3NcjXPz71SHMAK0kTnqdimt/hhgM804G81MUlXI=",
"password": "md5$lr8O5CFP468eSEdIaRbADz$6cefb611a4b7c895117144a771235980",
"last_login": "2017-08-25T09:07:30.795Z",
"is_superuser": true,
"username": "admin",
Expand All @@ -72,7 +72,7 @@
"model": "auth.user",
"pk": 2,
"fields": {
"password": "pbkdf2_sha256$36000$DRsew4M8dce9$D17yYCxtzuDH/IG2REeu6mmjcLejcEpvJKI6HTxLTo8=",
"password": "md5$vtusJ6bdJfYygjOLlRCnXx$41f2a9edc3b41b04fcbd928145de7efe",
"last_login": null,
"is_superuser": false,
"username": "manager",
Expand All @@ -95,7 +95,7 @@
"model": "auth.user",
"pk": 3,
"fields": {
"password": "pbkdf2_sha256$36000$khl0d1DUOjkR$pdhGzZrVSOCUTHGQ7p74APWThoYuQS3UXdkrSYMxnVc=",
"password": "md5$CDDKAJ2QOVfImo1G1umPnS$13a3a34626aed4c36737ffe341ba44ed",
"last_login": "2017-08-25T08:54:14.798Z",
"is_superuser": false,
"username": "user",
Expand All @@ -113,7 +113,7 @@
"model": "auth.user",
"pk": 4,
"fields": {
"password": "pbkdf2_sha256$36000$i1mlhdLWujh0$9Ybq7TAOnLt7sS/ixCvmN/tZpN6rezrod/B6YVppIoQ=",
"password": "md5$DPfXK5C0vNyxbflQXPFUVx$2fc5f8cb23ed081e122a6b1b1ffd6254",
"last_login": null,
"is_superuser": false,
"username": "evil",
Expand All @@ -131,7 +131,7 @@
"model": "auth.user",
"pk": 5,
"fields": {
"password": "pbkdf2_sha256$36000$Dk6tClk3A9uL$zTetO/go3GXSaLODi9yxILy/30rD2fkHyQUXuUjQti8=",
"password": "md5$SmME0yurdI60fMfQt5wDlg$c2b1642d9908beddd0b27f1a81eb8095",
"last_login": null,
"is_superuser": false,
"username": "test",
Expand All @@ -147,24 +147,6 @@
"user_permissions": []
}
},
{
"model": "auth.user",
"pk": 6,
"fields": {
"password": "pbkdf2_sha256$36000$khl0d1DUOjkR$pdhGzZrVSOCUTHGQ7p74APWThoYuQS3UXdkrSYMxnVc=",
"last_login": "2017-08-25T08:54:14.798Z",
"is_superuser": false,
"username": "unverified_user",
"first_name": "Gregor",
"last_name": "Unverified",
"email": "[email protected]",
"is_staff": false,
"is_active": true,
"date_joined": "2016-10-11T16:36:53Z",
"groups": [],
"user_permissions": []
}
},
{
"model": "account.emailaddress",
"pk": 1,
Expand Down Expand Up @@ -214,16 +196,6 @@
"verified": true,
"primary": true
}
},
{
"model": "account.emailaddress",
"pk": 6,
"fields": {
"user": 6,
"email": "[email protected]",
"verified": false,
"primary": true
}
},
{
"model": "daiquiri_auth.profile",
Expand Down Expand Up @@ -279,16 +251,5 @@
"details": null,
"attributes": null
}
},
{
"model": "daiquiri_auth.profile",
"pk": 6,
"fields": {
"user": 6,
"is_pending": true,
"is_confirmed": false,
"details": null,
"attributes": null
}
}
]

0 comments on commit 8c7959c

Please sign in to comment.