Skip to content

Commit

Permalink
Add a test to demonstrate #92
Browse files Browse the repository at this point in the history
  • Loading branch information
macro1 committed Aug 9, 2014
1 parent 4fafa18 commit 80ae356
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
7 changes: 7 additions & 0 deletions simple_history/tests/other_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib.admin.sites import AdminSite
from simple_history.admin import SimpleHistoryAdmin
from .models import State

site = AdminSite(name="other_admin", app_name="other_admin")

site.register(State, SimpleHistoryAdmin)
28 changes: 20 additions & 8 deletions simple_history/tests/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@
from django.contrib.admin.util import quote
from django.conf import settings

from ..models import Book, Person, Poll
from ..models import Book, Person, Poll, State


today = datetime(2021, 1, 1, 10, 0)
tomorrow = today + timedelta(days=1)


def get_history_url(model, history_index=None):
def get_history_url(obj, history_index=None, site="admin"):
try:
info = model._meta.app_label, model._meta.module_name
app, model = obj._meta.app_label, obj._meta.module_name
except AttributeError:
info = model._meta.app_label, model._meta.model_name
app, model = obj._meta.app_label, obj._meta.model_name
if history_index is not None:
history = model.history.order_by('history_id')[history_index]
return reverse('admin:%s_%s_simple_history' % info,
args=[quote(model.pk), quote(history.history_id)])
history = obj.history.order_by('history_id')[history_index]
return reverse(
"{site}:{app}_{model}_simple_history".format(
site=site, app=app, model=model),
args=[quote(obj.pk), quote(history.history_id)],
)
else:
return reverse('admin:%s_%s_history' % info, args=[quote(model.pk)])
return reverse("{site}:{app}_{model}_history".format(
site=site, app=app, model=model), args=[quote(obj.pk)])


class AdminSiteTest(WebTest):
Expand Down Expand Up @@ -181,3 +185,11 @@ def test_middleware_saves_user(self):
self.assertEqual(historical_poll.history_user, self.user,
"Middleware should make the request available to "
"retrieve history_user.")

def test_other_admin(self):
"""Demonstrate error viewing the historical admin page for a
model not registered with the default site 'admin'.
"""
self.login()
state = State.objects.create()
self.app.get(get_history_url(state, site="other_admin"))
8 changes: 5 additions & 3 deletions simple_history/tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
from django.conf.urls.defaults import patterns, include, url

from django.contrib import admin
from . import other_admin

admin.autodiscover()

urlpatterns = patterns(
'',
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
)
url(r'^other-admin/', include(other_admin.site.urls)),
]

0 comments on commit 80ae356

Please sign in to comment.