| 4018 | |
| 4019 | |
| 4020 | @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) |
| 4021 | class AdminChangeListRedirectionTests(TestCase): |
| 4022 | urls = "regressiontests.admin_views.urls" |
| 4023 | fixtures = ['admin-views-users'] |
| 4024 | |
| 4025 | def setUp(self): |
| 4026 | Person.objects.create(name="Chris", gender=1, alive=True, age=25) |
| 4027 | Person.objects.create(name="Jack", gender=2, alive=False, age=47) |
| 4028 | Person.objects.create(name="Bob", gender=1, alive=True, age=36) |
| 4029 | |
| 4030 | self.client.login(username='super', password='secret') |
| 4031 | |
| 4032 | def get_data(self): |
| 4033 | return { |
| 4034 | 'name': 'Joe', 'gender': '1', 'alive': '1', 'age': '58' |
| 4035 | } |
| 4036 | |
| 4037 | def tearDown(self): |
| 4038 | self.client.logout() |
| 4039 | |
| 4040 | def get_filtered_changelist_url(self): |
| 4041 | querystring = '?' + urlencode({ |
| 4042 | 'alive': 1, |
| 4043 | }) |
| 4044 | return "%s%s" % (reverse('admin:admin_views_person_changelist'), querystring) |
| 4045 | |
| 4046 | def test_change_redirect(self): |
| 4047 | """ |
| 4048 | Ensure that we're correctly redirected to the filtered changelist |
| 4049 | after an existing object is saved. |
| 4050 | Refs #6903. |
| 4051 | """ |
| 4052 | # First open the changelist view with filters |
| 4053 | self.client.get(self.get_filtered_changelist_url()) |
| 4054 | |
| 4055 | # Save an object |
| 4056 | data = self.get_data() |
| 4057 | data['_save'] = 1 |
| 4058 | person = Person.objects.get(name='Chris') |
| 4059 | response = self.client.post(reverse('admin:admin_views_person_change', args=(person.pk,)), data) |
| 4060 | |
| 4061 | # Check that we return to the filtered changelist |
| 4062 | self.assertRedirects(response, self.get_filtered_changelist_url()) |
| 4063 | |
| 4064 | def test_change_popup_redirect(self): |
| 4065 | """ |
| 4066 | Ensure that we're correctly redirected to the filtered changelist |
| 4067 | after an existing object is saved, even if the changelist was opened |
| 4068 | in a popup in the meantime. |
| 4069 | Refs #6903. |
| 4070 | """ |
| 4071 | # First open the changelist view with filters |
| 4072 | self.client.get(self.get_filtered_changelist_url()) |
| 4073 | |
| 4074 | # Then open the non-filtered changelist view in a popup |
| 4075 | self.client.get('%s?%s' % (reverse('admin:admin_views_person_changelist'), IS_POPUP_VAR)) |
| 4076 | |
| 4077 | # Save an object |
| 4078 | data = self.get_data() |
| 4079 | data['_save'] = 1 |
| 4080 | person = Person.objects.get(name='Chris') |
| 4081 | response = self.client.post(reverse('admin:admin_views_person_change', args=(person.pk,)), data) |
| 4082 | |
| 4083 | # Check that we return to the filtered changelist |
| 4084 | self.assertRedirects(response, self.get_filtered_changelist_url()) |
| 4085 | |
| 4086 | def test_delete_redirect(self): |
| 4087 | """ |
| 4088 | Ensure that we're correctly redirected to the filtered changelist |
| 4089 | after an existing object is deleted. |
| 4090 | Refs #6903. |
| 4091 | """ |
| 4092 | # First open the changelist view with filters |
| 4093 | self.client.get(self.get_filtered_changelist_url()) |
| 4094 | |
| 4095 | # Delete an object |
| 4096 | person = Person.objects.get(name='Chris') |
| 4097 | response = self.client.post(reverse('admin:admin_views_person_delete', args=(person.pk,)), {'post': 'yes'}) |
| 4098 | |
| 4099 | # Check that we return to the filtered changelist |
| 4100 | self.assertRedirects(response, self.get_filtered_changelist_url()) |
| 4101 | |
| 4102 | def test_add_redirect(self): |
| 4103 | """ |
| 4104 | Ensure that we're correctly redirected to the non-filtered changelist |
| 4105 | after a new object is added. |
| 4106 | Refs #6903. |
| 4107 | """ |
| 4108 | # First open the changelist view with filters |
| 4109 | self.client.get(self.get_filtered_changelist_url()) |
| 4110 | |
| 4111 | # Add a new object |
| 4112 | data = self.get_data() |
| 4113 | data['_save'] = 1 |
| 4114 | response = self.client.post(reverse('admin:admin_views_person_add'), data) |
| 4115 | |
| 4116 | # Check that we return to the non-filtered changelist |
| 4117 | self.assertRedirects(response, reverse('admin:admin_views_person_changelist')) |