|
13 | 13 |
|
14 | 14 | from simple_history.models import HistoricalRecords
|
15 | 15 | from simple_history.admin import SimpleHistoryAdmin, get_complete_version
|
16 |
| -from ..models import Book, Person, Poll, State, Employee, Choice |
| 16 | +from ..models import Book, Person, Poll, State, Employee, Choice, ConcreteExternal |
17 | 17 |
|
18 | 18 | try:
|
19 | 19 | from django.contrib.admin.utils import quote
|
@@ -551,3 +551,58 @@ def test_history_form_view_getting_history_with_setting_off(self):
|
551 | 551 | }
|
552 | 552 | mock_render.assert_called_once_with(
|
553 | 553 | request, admin.object_history_form_template, context, **extra_kwargs)
|
| 554 | + |
| 555 | + def test_history_form_view_getting_history_abstract_external(self): |
| 556 | + request = RequestFactory().post('/') |
| 557 | + request.session = 'session' |
| 558 | + request._messages = FallbackStorage(request) |
| 559 | + request.user = self.user |
| 560 | + request.POST = {'_change_history': True} |
| 561 | + |
| 562 | + obj = ConcreteExternal.objects.create(name='test') |
| 563 | + obj.name = "new_test" |
| 564 | + obj.save() |
| 565 | + history = obj.history.all()[0] |
| 566 | + |
| 567 | + admin_site = AdminSite() |
| 568 | + admin = SimpleHistoryAdmin(ConcreteExternal, admin_site) |
| 569 | + |
| 570 | + with patch('simple_history.admin.render') as mock_render: |
| 571 | + with patch('simple_history.admin.SIMPLE_HISTORY_EDIT', True): |
| 572 | + admin.history_form_view(request, obj.id, history.pk) |
| 573 | + |
| 574 | + context = { |
| 575 | + # Verify this is set for history object |
| 576 | + 'original': history.instance, |
| 577 | + 'change_history': True, |
| 578 | + |
| 579 | + 'title': 'Revert %s' % force_text(history.instance), |
| 580 | + 'adminform': ANY, |
| 581 | + 'object_id': obj.id, |
| 582 | + 'is_popup': False, |
| 583 | + 'media': ANY, |
| 584 | + 'errors': ANY, |
| 585 | + 'app_label': 'tests', |
| 586 | + 'original_opts': ANY, |
| 587 | + 'changelist_url': '/admin/tests/concreteexternal/', |
| 588 | + 'change_url': ANY, |
| 589 | + 'history_url': '/admin/tests/concreteexternal/{pk}/history/'.format( |
| 590 | + pk=obj.pk), |
| 591 | + 'add': False, |
| 592 | + 'change': True, |
| 593 | + 'has_add_permission': admin.has_add_permission(request), |
| 594 | + 'has_change_permission': admin.has_change_permission( |
| 595 | + request, obj), |
| 596 | + 'has_delete_permission': admin.has_delete_permission( |
| 597 | + request, obj), |
| 598 | + 'has_file_field': True, |
| 599 | + 'has_absolute_url': False, |
| 600 | + 'form_url': '', |
| 601 | + 'opts': ANY, |
| 602 | + 'content_type_id': ANY, |
| 603 | + 'save_as': admin.save_as, |
| 604 | + 'save_on_top': admin.save_on_top, |
| 605 | + 'root_path': getattr(admin_site, 'root_path', None), |
| 606 | + } |
| 607 | + mock_render.assert_called_once_with( |
| 608 | + request, admin.object_history_form_template, context, **extra_kwargs) |
0 commit comments