|
1 | 1 | from datetime import datetime, timedelta |
2 | 2 | from unittest.mock import ANY, patch |
3 | 3 |
|
| 4 | +import django |
4 | 5 | from django.contrib.admin import AdminSite |
5 | 6 | from django.contrib.admin.utils import quote |
6 | 7 | from django.contrib.auth import get_user_model |
@@ -621,6 +622,7 @@ def test_history_form_view_without_getting_history(self): |
621 | 622 | context = { |
622 | 623 | **admin_site.each_context(request), |
623 | 624 | # Verify this is set for original object |
| 625 | + "log_entries": ANY, |
624 | 626 | "original": poll, |
625 | 627 | "change_history": False, |
626 | 628 | "title": "Revert %s" % force_str(poll), |
@@ -650,9 +652,9 @@ def test_history_form_view_without_getting_history(self): |
650 | 652 | "save_on_top": admin.save_on_top, |
651 | 653 | "root_path": getattr(admin_site, "root_path", None), |
652 | 654 | } |
653 | | - # This key didn't exist prior to Django 4.2 |
654 | | - if "log_entries" in context: |
655 | | - context["log_entries"] = ANY |
| 655 | + # DEV: Remove this when support for Django 4.2 has been dropped |
| 656 | + if django.VERSION < (5, 0): |
| 657 | + del context["log_entries"] |
656 | 658 |
|
657 | 659 | mock_render.assert_called_once_with( |
658 | 660 | request, admin.object_history_form_template, context |
@@ -680,6 +682,7 @@ def test_history_form_view_getting_history(self): |
680 | 682 | context = { |
681 | 683 | **admin_site.each_context(request), |
682 | 684 | # Verify this is set for history object not poll object |
| 685 | + "log_entries": ANY, |
683 | 686 | "original": history.instance, |
684 | 687 | "change_history": True, |
685 | 688 | "title": "Revert %s" % force_str(history.instance), |
@@ -709,9 +712,9 @@ def test_history_form_view_getting_history(self): |
709 | 712 | "save_on_top": admin.save_on_top, |
710 | 713 | "root_path": getattr(admin_site, "root_path", None), |
711 | 714 | } |
712 | | - # This key didn't exist prior to Django 4.2 |
713 | | - if "log_entries" in context: |
714 | | - context["log_entries"] = ANY |
| 715 | + # DEV: Remove this when support for Django 4.2 has been dropped |
| 716 | + if django.VERSION < (5, 0): |
| 717 | + del context["log_entries"] |
715 | 718 |
|
716 | 719 | mock_render.assert_called_once_with( |
717 | 720 | request, admin.object_history_form_template, context |
@@ -739,6 +742,7 @@ def test_history_form_view_getting_history_with_setting_off(self): |
739 | 742 | context = { |
740 | 743 | **admin_site.each_context(request), |
741 | 744 | # Verify this is set for history object not poll object |
| 745 | + "log_entries": ANY, |
742 | 746 | "original": poll, |
743 | 747 | "change_history": False, |
744 | 748 | "title": "Revert %s" % force_str(poll), |
@@ -768,9 +772,9 @@ def test_history_form_view_getting_history_with_setting_off(self): |
768 | 772 | "save_on_top": admin.save_on_top, |
769 | 773 | "root_path": getattr(admin_site, "root_path", None), |
770 | 774 | } |
771 | | - # This key didn't exist prior to Django 4.2 |
772 | | - if "log_entries" in context: |
773 | | - context["log_entries"] = ANY |
| 775 | + # DEV: Remove this when support for Django 4.2 has been dropped |
| 776 | + if django.VERSION < (5, 0): |
| 777 | + del context["log_entries"] |
774 | 778 |
|
775 | 779 | mock_render.assert_called_once_with( |
776 | 780 | request, admin.object_history_form_template, context |
@@ -798,6 +802,7 @@ def test_history_form_view_getting_history_abstract_external(self): |
798 | 802 | context = { |
799 | 803 | **admin_site.each_context(request), |
800 | 804 | # Verify this is set for history object |
| 805 | + "log_entries": ANY, |
801 | 806 | "original": history.instance, |
802 | 807 | "change_history": True, |
803 | 808 | "title": "Revert %s" % force_str(history.instance), |
@@ -829,9 +834,9 @@ def test_history_form_view_getting_history_abstract_external(self): |
829 | 834 | "save_on_top": admin.save_on_top, |
830 | 835 | "root_path": getattr(admin_site, "root_path", None), |
831 | 836 | } |
832 | | - # This key didn't exist prior to Django 4.2 |
833 | | - if "log_entries" in context: |
834 | | - context["log_entries"] = ANY |
| 837 | + # DEV: Remove this when support for Django 4.2 has been dropped |
| 838 | + if django.VERSION < (5, 0): |
| 839 | + del context["log_entries"] |
835 | 840 |
|
836 | 841 | mock_render.assert_called_once_with( |
837 | 842 | request, admin.object_history_form_template, context |
@@ -862,6 +867,7 @@ def test_history_form_view_accepts_additional_context(self): |
862 | 867 | context = { |
863 | 868 | **admin_site.each_context(request), |
864 | 869 | # Verify this is set for original object |
| 870 | + "log_entries": ANY, |
865 | 871 | "anything_else": "will be merged into context", |
866 | 872 | "original": poll, |
867 | 873 | "change_history": False, |
@@ -892,9 +898,9 @@ def test_history_form_view_accepts_additional_context(self): |
892 | 898 | "save_on_top": admin.save_on_top, |
893 | 899 | "root_path": getattr(admin_site, "root_path", None), |
894 | 900 | } |
895 | | - # This key didn't exist prior to Django 4.2 |
896 | | - if "log_entries" in context: |
897 | | - context["log_entries"] = ANY |
| 901 | + # DEV: Remove this when support for Django 4.2 has been dropped |
| 902 | + if django.VERSION < (5, 0): |
| 903 | + del context["log_entries"] |
898 | 904 |
|
899 | 905 | mock_render.assert_called_once_with( |
900 | 906 | request, admin.object_history_form_template, context |
|
0 commit comments