mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Fixed resource_url to work with non-id models (#147)
* Fixed resource_url to work with non-id models * Add tests for auditlog admin
This commit is contained in:
parent
4dee03497c
commit
96f2f3d93e
4 changed files with 70 additions and 4 deletions
|
|
@ -34,7 +34,8 @@ class LogEntryAdminMixin(object):
|
|||
app_label, model = obj.content_type.app_label, obj.content_type.model
|
||||
viewname = 'admin:%s_%s_change' % (app_label, model)
|
||||
try:
|
||||
link = urlresolvers.reverse(viewname, args=[obj.object_id])
|
||||
args = [obj.object_pk] if obj.object_id is None else [obj.object_id]
|
||||
link = urlresolvers.reverse(viewname, args=args)
|
||||
except NoReverseMatch:
|
||||
return obj.object_repr
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
"""
|
||||
Settings file for the Auditlog test suite.
|
||||
"""
|
||||
import os
|
||||
import django
|
||||
|
||||
SECRET_KEY = 'test'
|
||||
|
|
@ -8,18 +9,27 @@ SECRET_KEY = 'test'
|
|||
INSTALLED_APPS = [
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.admin',
|
||||
'auditlog',
|
||||
'auditlog_tests',
|
||||
'multiselectfield',
|
||||
]
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
middlewares = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware'
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'auditlog.middleware.AuditlogMiddleware',
|
||||
)
|
||||
|
||||
if django.VERSION < (1, 10):
|
||||
MIDDLEWARE_CLASSES = middlewares
|
||||
else:
|
||||
MIDDLEWARE = middlewares
|
||||
|
||||
if django.VERSION <= (1, 9):
|
||||
POSTGRES_DRIVER = 'django.db.backends.postgresql_psycopg2'
|
||||
else:
|
||||
|
|
@ -42,6 +52,20 @@ DATABASES = {
|
|||
}
|
||||
}
|
||||
|
||||
ROOT_URLCONF = []
|
||||
TEMPLATES = [
|
||||
{
|
||||
'APP_DIRS': True,
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
]
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'auditlog_tests.urls'
|
||||
|
||||
USE_TZ = True
|
||||
|
|
|
|||
|
|
@ -619,3 +619,31 @@ class CompatibilityTest(TestCase):
|
|||
else:
|
||||
assert not self.user.is_anonymous
|
||||
assert compat.is_authenticated(self.user)
|
||||
|
||||
|
||||
class AdminPanelTest(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.username = "test_admin"
|
||||
cls.password = User.objects.make_random_password()
|
||||
cls.user, created = User.objects.get_or_create(username=cls.username)
|
||||
cls.user.set_password(cls.password)
|
||||
cls.user.is_staff = True
|
||||
cls.user.is_superuser = True
|
||||
cls.user.is_active = True
|
||||
cls.user.save()
|
||||
cls.obj = SimpleModel.objects.create(text='For admin logentry test')
|
||||
|
||||
def test_auditlog_admin(self):
|
||||
self.client.login(username=self.username, password=self.password)
|
||||
log_pk = self.obj.history.latest().pk
|
||||
res = self.client.get("/admin/auditlog/logentry/")
|
||||
assert res.status_code == 200
|
||||
res = self.client.get("/admin/auditlog/logentry/add/")
|
||||
assert res.status_code == 200
|
||||
res = self.client.get("/admin/auditlog/logentry/{}/".format(log_pk), follow=True)
|
||||
assert res.status_code == 200
|
||||
res = self.client.get("/admin/auditlog/logentry/{}/delete/".format(log_pk))
|
||||
assert res.status_code == 200
|
||||
res = self.client.get("/admin/auditlog/logentry/{}/history/".format(log_pk))
|
||||
assert res.status_code == 200
|
||||
|
|
|
|||
13
src/auditlog_tests/urls.py
Normal file
13
src/auditlog_tests/urls.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import django
|
||||
from django.conf.urls import include, url
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
if django.VERSION < (1, 9):
|
||||
admin_urls = include(admin.site.urls)
|
||||
else:
|
||||
admin_urls = admin.site.urls
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^admin/', admin_urls),
|
||||
]
|
||||
Loading…
Reference in a new issue