mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +00:00
fix(accounts): knox creates no table of its own
knox's first migration creates its AuthToken table even when
KNOX_TOKEN_MODEL replaces it with accounts.ApiToken. The unused
knox_authtoken table references auth_user, and Django, which does not see
it, does not empty it with the others: on PostgreSQL every test that
empties the database failed ("cannot truncate a table referenced in a
foreign key constraint"). SQLite does not check this, so only CI's
PostgreSQL leg showed it. knox stays installed for its token code, with
its migrations turned off (MIGRATION_MODULES).
This commit is contained in:
parent
1c60696ea1
commit
d9088b410e
2 changed files with 10 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ from datetime import timedelta
|
|||
|
||||
from accounts.models import ApiToken
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import connection
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
|
@ -91,3 +92,9 @@ class ApiTokenTests(TestCase):
|
|||
response = self.client.post(reverse("accounts:api_token_create"), {"name": " ", "days": "30"})
|
||||
self.assertFalse(ApiToken.objects.exists())
|
||||
self.assertNotRegex(response.content.decode(), r"wvc_[0-9a-f]{64}")
|
||||
|
||||
def test_knox_makes_no_table_of_its_own(self):
|
||||
# accounts.ApiToken replaces knox's AuthToken; a knox_authtoken table
|
||||
# would reference auth_user unseen, and PostgreSQL could not empty
|
||||
# auth_user between tests
|
||||
self.assertNotIn("knox_authtoken", connection.introspection.table_names())
|
||||
|
|
|
|||
|
|
@ -381,6 +381,9 @@ REST_FRAMEWORK = {
|
|||
# "Authorization: Token wvc_..."; made and deleted on the profile page
|
||||
KNOX_TOKEN_MODEL = "accounts.ApiToken"
|
||||
REST_KNOX = {"TOKEN_PREFIX": "wvc_"}
|
||||
# knox stays installed for its token code, but its migrations would create a
|
||||
# knox_authtoken table that accounts.ApiToken replaces
|
||||
MIGRATION_MODULES = {"knox": None}
|
||||
|
||||
SPECTACULAR_SETTINGS = {
|
||||
"TITLE": "Webvirtcloud REST-API",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue