Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions tests/test_authtoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import patch

import pytest
from django.apps import apps
from django.contrib.admin import site
from django.contrib.auth.models import User
from django.core.management import CommandError, call_command
Expand All @@ -26,12 +27,21 @@ def setUp(self):
self.token = Token.objects.create(key='test token', user=self.user)

def test_authtoken_can_be_imported_when_not_included_in_installed_apps(self):
import rest_framework.authtoken.models
with modify_settings(INSTALLED_APPS={'remove': 'rest_framework.authtoken'}):
importlib.reload(rest_framework.authtoken.models)
# Set the proxy and abstract properties back to the version,
# where authtoken is among INSTALLED_APPS.
importlib.reload(rest_framework.authtoken.models)
import rest_framework.authtoken.models as authtoken_models
originals = (authtoken_models.Token, authtoken_models.TokenProxy)
try:
with modify_settings(INSTALLED_APPS={'remove': 'rest_framework.authtoken'}):
importlib.reload(authtoken_models)
finally:
# Set the proxy and abstract properties back to the version,
# where authtoken is among INSTALLED_APPS.
importlib.reload(authtoken_models)
# Reloading registered new classes; put the originals back so
# references held elsewhere stay valid.
for model in originals:
setattr(authtoken_models, model.__name__, model)
apps.all_models['authtoken'][model._meta.model_name] = model
apps.clear_cache()

def test_model_admin_displayed_fields(self):
mock_request = object()
Expand Down
Loading