Skip to content
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

Fix bug that prevented BookLink from loading in admin #3583

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/utils/admin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ArticleFKModelAdmin(admin.ModelAdmin):
"""

def _journal(self, obj):
return obj.article.journal if obj else ''
return obj.article.journal if obj and obj.article else ''

def _article(self, obj):
return truncatewords_html(str(obj.article), 5) if obj else ''
Expand Down
21 changes: 18 additions & 3 deletions src/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.contrib.contenttypes.models import ContentType
from django.conf import settings
from django.template.engine import Engine
from django.shortcuts import reverse

import mock
from utils import (
Expand Down Expand Up @@ -964,21 +965,29 @@ def build_tests(cls):
def build_test_case(cls, model, admin_class):
raise NotImplementedError()


class AdminSearchTestMeta(AdminTestMeta):
def build_test_case(model, admin_class):
app_label = model._meta.app_label
model_name = model._meta.model_name
url_name = f'admin:{app_label}_{model_name}_changelist'
url = reverse(url_name)
url = reverse(url_name) + '?q=test'

def test_case(instance):
response = instance.client.get(url, SERVER_NAME=instance.press.domain)
response = instance.client.get(
url,
SERVER_NAME=instance.press.domain,
)
instance.assertEqual(response.status_code, 200)
test_name = f'test_admin_view_{app_label}_{model_name}'
return test_name, test_case


class TestAdmin(TestCase, metaclass=AdminSearchTestMeta):

@classmethod
def setUpTestData(cls):
def setUpClass(cls):
super().setUpClass()
user_model = get_user_model()
cls.superuser = user_model.objects.create_superuser(
username='super',
Expand All @@ -987,5 +996,11 @@ def setUpTestData(cls):
)
cls.press = helpers.create_press()

@classmethod
def tearDownClass(cls):
super().tearDownClass()
cls.press.delete()
cls.superuser.delete()

def setUp(self):
self.client.force_login(self.superuser)