|
6 | 6 | from django.contrib.messages.storage.fallback import FallbackStorage
|
7 | 7 | from django.test.utils import override_settings
|
8 | 8 | from django.test.client import RequestFactory
|
9 |
| -from django import VERSION |
10 | 9 | from django.core.urlresolvers import reverse
|
11 | 10 | from django.conf import settings
|
12 | 11 | from django.utils.encoding import force_text
|
|
22 | 21 | from django.contrib.admin.util import quote
|
23 | 22 |
|
24 | 23 | from simple_history.models import HistoricalRecords
|
25 |
| -from simple_history.admin import SimpleHistoryAdmin |
| 24 | +from simple_history.admin import SimpleHistoryAdmin, get_complete_version |
26 | 25 | from ..models import Book, Person, Poll, State, Employee
|
27 | 26 |
|
28 | 27 |
|
29 | 28 | today = datetime(2021, 1, 1, 10, 0)
|
30 | 29 | tomorrow = today + timedelta(days=1)
|
31 | 30 |
|
| 31 | +extra_kwargs = {} |
| 32 | +if get_complete_version() < (1, 8): |
| 33 | + extra_kwargs = {'current_app': 'admin'} |
| 34 | + |
32 | 35 |
|
33 | 36 | def get_history_url(obj, history_index=None, site="admin"):
|
34 | 37 | app, model = obj._meta.app_label, obj._meta.model_name
|
@@ -107,12 +110,8 @@ def test_history_form(self):
|
107 | 110 | response.form['pub_date_0'] = "2021-01-02"
|
108 | 111 | response = response.form.submit()
|
109 | 112 | self.assertEqual(response.status_code, 302)
|
110 |
| - if VERSION < (1, 4, 0): |
111 |
| - self.assertTrue(response.headers['location'] |
112 |
| - .endswith(get_history_url(poll))) |
113 |
| - else: |
114 |
| - self.assertTrue(response.headers['location'] |
115 |
| - .endswith(reverse('admin:tests_poll_changelist'))) |
| 113 | + self.assertTrue(response.headers['location'] |
| 114 | + .endswith(reverse('admin:tests_poll_changelist'))) |
116 | 115 |
|
117 | 116 | # Ensure form for second version is correct
|
118 | 117 | response = self.app.get(get_history_url(poll, 1))
|
@@ -424,9 +423,8 @@ def test_history_form_view_without_getting_history(self):
|
424 | 423 | 'save_on_top': admin.save_on_top,
|
425 | 424 | 'root_path': getattr(admin_site, 'root_path', None),
|
426 | 425 | }
|
427 |
| - |
428 | 426 | mock_render.assert_called_once_with(
|
429 |
| - request, admin.object_history_form_template, context) |
| 427 | + request, admin.object_history_form_template, context, **extra_kwargs) |
430 | 428 |
|
431 | 429 | def test_history_form_view_getting_history(self):
|
432 | 430 | request = RequestFactory().post('/')
|
@@ -480,9 +478,8 @@ def test_history_form_view_getting_history(self):
|
480 | 478 | 'save_on_top': admin.save_on_top,
|
481 | 479 | 'root_path': getattr(admin_site, 'root_path', None),
|
482 | 480 | }
|
483 |
| - |
484 | 481 | mock_render.assert_called_once_with(
|
485 |
| - request, admin.object_history_form_template, context) |
| 482 | + request, admin.object_history_form_template, context, **extra_kwargs) |
486 | 483 |
|
487 | 484 | def test_history_form_view_getting_history_with_setting_off(self):
|
488 | 485 | request = RequestFactory().post('/')
|
@@ -535,6 +532,5 @@ def test_history_form_view_getting_history_with_setting_off(self):
|
535 | 532 | 'save_on_top': admin.save_on_top,
|
536 | 533 | 'root_path': getattr(admin_site, 'root_path', None),
|
537 | 534 | }
|
538 |
| - |
539 | 535 | mock_render.assert_called_once_with(
|
540 |
| - request, admin.object_history_form_template, context) |
| 536 | + request, admin.object_history_form_template, context, **extra_kwargs) |
0 commit comments