Adopt new usage of assertFormError
Passing a response object and a form/formset name to assertFormError was deprecated in Django 4.1[1] and was removed in Django 5.0[2]. [1] https://docs.djangoproject.com/en/4.2/releases/4.1/#id2 [2] https://docs.djangoproject.com/en/5.2/releases/5.0/#features-removed-in-5-0 Change-Id: Ic05fb55d6f3bd9d8374dc5eb5133c6d50065bbdc Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
@@ -258,7 +258,7 @@ class MetadataDefinitionsCreateViewTest(test.BaseAdminViewTests):
|
|||||||
|
|
||||||
err_msg = ('There was a problem loading the namespace: '
|
err_msg = ('There was a problem loading the namespace: '
|
||||||
'Expecting value: line 1 column 1 (char 0).')
|
'Expecting value: line 1 column 1 (char 0).')
|
||||||
self.assertFormError(res, "form", None, [err_msg])
|
self.assertFormError(res.context["form"], None, [err_msg])
|
||||||
|
|
||||||
def test_admin_metadata_defs_create_namespace_empty_json_post_raw(self):
|
def test_admin_metadata_defs_create_namespace_empty_json_post_raw(self):
|
||||||
form_data = {
|
form_data = {
|
||||||
@@ -269,8 +269,9 @@ class MetadataDefinitionsCreateViewTest(test.BaseAdminViewTests):
|
|||||||
res = self.client.post(reverse(constants.METADATA_CREATE_URL),
|
res = self.client.post(reverse(constants.METADATA_CREATE_URL),
|
||||||
form_data)
|
form_data)
|
||||||
|
|
||||||
self.assertFormError(res, "form", None, ['No input was provided for '
|
self.assertFormError(
|
||||||
'the namespace content.'])
|
res.context["form"], None,
|
||||||
|
['No input was provided for the namespace content.'])
|
||||||
|
|
||||||
def test_admin_metadata_defs_create_namespace_empty_json_post_file(self):
|
def test_admin_metadata_defs_create_namespace_empty_json_post_file(self):
|
||||||
form_data = {
|
form_data = {
|
||||||
@@ -281,8 +282,9 @@ class MetadataDefinitionsCreateViewTest(test.BaseAdminViewTests):
|
|||||||
res = self.client.post(reverse(constants.METADATA_CREATE_URL),
|
res = self.client.post(reverse(constants.METADATA_CREATE_URL),
|
||||||
form_data)
|
form_data)
|
||||||
|
|
||||||
self.assertFormError(res, "form", None, ['No input was provided for '
|
self.assertFormError(
|
||||||
'the namespace content.'])
|
res.context["form"], None,
|
||||||
|
['No input was provided for the namespace content.'])
|
||||||
|
|
||||||
|
|
||||||
class MetadataDefinitionsUpdateViewTest(test.BaseAdminViewTests):
|
class MetadataDefinitionsUpdateViewTest(test.BaseAdminViewTests):
|
||||||
|
@@ -263,7 +263,8 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
|
|
||||||
res = self.client.post(USER_CREATE_URL, formData)
|
res = self.client.post(USER_CREATE_URL, formData)
|
||||||
|
|
||||||
self.assertFormError(res, "form", None, ['Passwords do not match.'])
|
self.assertFormError(res.context["form"], None,
|
||||||
|
['Passwords do not match.'])
|
||||||
|
|
||||||
self.assert_mock_multiple_calls_with_same_arguments(
|
self.assert_mock_multiple_calls_with_same_arguments(
|
||||||
self.mock_get_default_domain, 2,
|
self.mock_get_default_domain, 2,
|
||||||
@@ -310,7 +311,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
res = self.client.post(USER_CREATE_URL, formData)
|
res = self.client.post(USER_CREATE_URL, formData)
|
||||||
|
|
||||||
self.assertFormError(
|
self.assertFormError(
|
||||||
res, "form", 'password',
|
res.context["form"], 'password',
|
||||||
['Password must be between 8 and 18 characters.'])
|
['Password must be between 8 and 18 characters.'])
|
||||||
|
|
||||||
self.assert_mock_multiple_calls_with_same_arguments(
|
self.assert_mock_multiple_calls_with_same_arguments(
|
||||||
@@ -358,7 +359,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
res = self.client.post(USER_CREATE_URL, formData)
|
res = self.client.post(USER_CREATE_URL, formData)
|
||||||
|
|
||||||
self.assertFormError(
|
self.assertFormError(
|
||||||
res, "form", 'password',
|
res.context["form"], 'password',
|
||||||
['Password must be between 8 and 18 characters.'])
|
['Password must be between 8 and 18 characters.'])
|
||||||
|
|
||||||
self.assert_mock_multiple_calls_with_same_arguments(
|
self.assert_mock_multiple_calls_with_same_arguments(
|
||||||
@@ -697,7 +698,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
|
|
||||||
res = self.client.post(USER_CHANGE_PASSWORD_URL, formData)
|
res = self.client.post(USER_CHANGE_PASSWORD_URL, formData)
|
||||||
|
|
||||||
self.assertFormError(res, "form", None,
|
self.assertFormError(res.context["form"], None,
|
||||||
['The admin password is incorrect.'])
|
['The admin password is incorrect.'])
|
||||||
self.mock_user_get.assert_called_with(test.IsHttpRequest(), '1',
|
self.mock_user_get.assert_called_with(test.IsHttpRequest(), '1',
|
||||||
admin=False)
|
admin=False)
|
||||||
@@ -720,7 +721,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
res = self.client.post(USER_CHANGE_PASSWORD_URL, formData)
|
res = self.client.post(USER_CHANGE_PASSWORD_URL, formData)
|
||||||
|
|
||||||
self.assertFormError(
|
self.assertFormError(
|
||||||
res, "form", 'password',
|
res.context["form"], 'password',
|
||||||
['Password must be between 8 and 18 characters.'])
|
['Password must be between 8 and 18 characters.'])
|
||||||
|
|
||||||
self.mock_user_get.assert_called_once_with(test.IsHttpRequest(), '1',
|
self.mock_user_get.assert_called_once_with(test.IsHttpRequest(), '1',
|
||||||
@@ -741,7 +742,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
res = self.client.post(USER_CHANGE_PASSWORD_URL, formData)
|
res = self.client.post(USER_CHANGE_PASSWORD_URL, formData)
|
||||||
|
|
||||||
self.assertFormError(
|
self.assertFormError(
|
||||||
res, "form", 'password',
|
res.context["form"], 'password',
|
||||||
['Password must be between 8 and 18 characters.'])
|
['Password must be between 8 and 18 characters.'])
|
||||||
|
|
||||||
self.mock_user_get.assert_called_once_with(test.IsHttpRequest(), '1',
|
self.mock_user_get.assert_called_once_with(test.IsHttpRequest(), '1',
|
||||||
|
@@ -1042,7 +1042,7 @@ class SecurityGroupsViewTests(test.TestCase):
|
|||||||
'etherype': 'IPv4',
|
'etherype': 'IPv4',
|
||||||
'remote': 'cidr'}
|
'remote': 'cidr'}
|
||||||
res = self.client.post(self.edit_url, formData)
|
res = self.client.post(self.edit_url, formData)
|
||||||
self.assertFormError(res, 'form', 'cidr',
|
self.assertFormError(res.context['form'], 'cidr',
|
||||||
'Invalid version for IP address')
|
'Invalid version for IP address')
|
||||||
self.assert_mock_multiple_calls_with_same_arguments(
|
self.assert_mock_multiple_calls_with_same_arguments(
|
||||||
self.mock_security_group_list, 2,
|
self.mock_security_group_list, 2,
|
||||||
|
@@ -653,7 +653,7 @@ class VolumeViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
|
|||||||
"snapshot_id=" + str(snapshot.id)]),
|
"snapshot_id=" + str(snapshot.id)]),
|
||||||
formData, follow=True)
|
formData, follow=True)
|
||||||
self.assertEqual(res.redirect_chain, [])
|
self.assertEqual(res.redirect_chain, [])
|
||||||
self.assertFormError(res, 'form', None,
|
self.assertFormError(res.context['form'], None,
|
||||||
"The volume size cannot be less than the "
|
"The volume size cannot be less than the "
|
||||||
"snapshot size (40GiB)")
|
"snapshot size (40GiB)")
|
||||||
self.assertEqual(3, self.mock_volume_type_list.call_count)
|
self.assertEqual(3, self.mock_volume_type_list.call_count)
|
||||||
@@ -830,7 +830,7 @@ class VolumeViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
|
|||||||
msg = ("The volume size cannot be less than the "
|
msg = ("The volume size cannot be less than the "
|
||||||
"image size (20.0\xa0GB)")
|
"image size (20.0\xa0GB)")
|
||||||
|
|
||||||
self.assertFormError(res, 'form', None, msg)
|
self.assertFormError(res.context['form'], None, msg)
|
||||||
|
|
||||||
self.assertEqual(3, self.mock_volume_type_list.call_count)
|
self.assertEqual(3, self.mock_volume_type_list.call_count)
|
||||||
self.assertEqual(2, self.mock_volume_type_default.call_count)
|
self.assertEqual(2, self.mock_volume_type_default.call_count)
|
||||||
@@ -874,7 +874,7 @@ class VolumeViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
|
|||||||
"image_id=" + str(image.id)]),
|
"image_id=" + str(image.id)]),
|
||||||
formData, follow=True)
|
formData, follow=True)
|
||||||
self.assertEqual(res.redirect_chain, [])
|
self.assertEqual(res.redirect_chain, [])
|
||||||
self.assertFormError(res, 'form', None,
|
self.assertFormError(res.context['form'], None,
|
||||||
"The volume size cannot be less than the "
|
"The volume size cannot be less than the "
|
||||||
"image minimum disk size (30GiB)")
|
"image minimum disk size (30GiB)")
|
||||||
self.assertEqual(3, self.mock_volume_type_list.call_count)
|
self.assertEqual(3, self.mock_volume_type_list.call_count)
|
||||||
@@ -1913,7 +1913,7 @@ class VolumeViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
|
|||||||
url = reverse('horizon:project:volumes:extend',
|
url = reverse('horizon:project:volumes:extend',
|
||||||
args=[volume.id])
|
args=[volume.id])
|
||||||
res = self.client.post(url, formData)
|
res = self.client.post(url, formData)
|
||||||
self.assertFormError(res, "form", "new_size",
|
self.assertFormError(res.context["form"], "new_size",
|
||||||
"Volume cannot be extended to 1000GiB as "
|
"Volume cannot be extended to 1000GiB as "
|
||||||
"the maximum size it can be extended to is "
|
"the maximum size it can be extended to is "
|
||||||
"120GiB.")
|
"120GiB.")
|
||||||
|
@@ -82,7 +82,8 @@ class ChangePasswordTests(test.TestCase):
|
|||||||
'confirm_password': 'doesnotmatch'}
|
'confirm_password': 'doesnotmatch'}
|
||||||
res = self.client.post(INDEX_URL, formData)
|
res = self.client.post(INDEX_URL, formData)
|
||||||
|
|
||||||
self.assertFormError(res, "form", None, ['Passwords do not match.'])
|
self.assertFormError(res.context["form"], None,
|
||||||
|
['Passwords do not match.'])
|
||||||
|
|
||||||
@test.create_mocks({
|
@test.create_mocks({
|
||||||
api.keystone: ['user_get']})
|
api.keystone: ['user_get']})
|
||||||
|
Reference in New Issue
Block a user