django22: django.test.client.encode_multipart no longer accepts None

As seen here [1]. With this change, all test are passing with Django
2.2.

[1] https://github.com/django/django/commit/6fe9c45b725

Change-Id: Idef0bd9dff4b27d22cfb756fc248c5c6bd24e097
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2019-08-26 18:23:58 +01:00 committed by Akihiro Motoki
parent a96c6e34cf
commit f654c893ec
5 changed files with 49 additions and 46 deletions

View File

@ -431,9 +431,9 @@ class CreateFlavorWorkflowTests(BaseFlavorWorkflowTests):
workflow_data = self._get_workflow_data(flavor) workflow_data = self._get_workflow_data(flavor)
# Swap field empty # Swap field empty
workflow_data['swap'] = None del workflow_data['swap_mb']
# Ephemeral field empty # Ephemeral field empty
workflow_data['eph'] = None del workflow_data['eph_gb']
url = reverse(constants.FLAVORS_CREATE_URL) url = reverse(constants.FLAVORS_CREATE_URL)
res = self.client.post(url, workflow_data) res = self.client.post(url, workflow_data)

View File

@ -131,9 +131,9 @@ class RBACPolicyTests(test.BaseAdminViewTests):
self.mock_network_list.return_value = self.networks.list() self.mock_network_list.return_value = self.networks.list()
self.mock_is_extension_supported.return_value = False self.mock_is_extension_supported.return_value = False
# note that 'network_id' is not included
form_data = {'target_tenant': rbac_policy.target_tenant, form_data = {'target_tenant': rbac_policy.target_tenant,
'action_object_type': 'external_network', 'action_object_type': 'external_network'}
'network_id': None}
url = reverse('horizon:admin:rbac_policies:create') url = reverse('horizon:admin:rbac_policies:create')
res = self.client.post(url, form_data) res = self.client.post(url, form_data)
@ -161,9 +161,9 @@ class RBACPolicyTests(test.BaseAdminViewTests):
self.mock_policy_list.return_value = self.qos_policies.list() self.mock_policy_list.return_value = self.qos_policies.list()
self.mock_is_extension_supported.return_value = True self.mock_is_extension_supported.return_value = True
# note that 'qos_policy_id' is not included
form_data = {'target_tenant': rbac_policy.target_tenant, form_data = {'target_tenant': rbac_policy.target_tenant,
'action_object_type': 'shared_qos_policy', 'action_object_type': 'shared_qos_policy'}
'qos_policy_id': None}
url = reverse('horizon:admin:rbac_policies:create') url = reverse('horizon:admin:rbac_policies:create')
res = self.client.post(url, form_data) res = self.client.post(url, form_data)

View File

@ -127,6 +127,12 @@ class UsersViewTests(test.BaseAdminViewTests):
'enabled': True, 'enabled': True,
'confirm_password': user.password, 'confirm_password': user.password,
'phone_num': phone_number} 'phone_num': phone_number}
# django.test.client doesn't like None fields in forms
for key in list(formData):
if formData[key] is None:
del formData[key]
res = self.client.post(USER_CREATE_URL, formData) res = self.client.post(USER_CREATE_URL, formData)
self.assertNoFormErrors(res) self.assertNoFormErrors(res)
@ -195,6 +201,12 @@ class UsersViewTests(test.BaseAdminViewTests):
'project': self.tenant.id, 'project': self.tenant.id,
'role_id': self.roles.first().id, 'role_id': self.roles.first().id,
'confirm_password': user.password} 'confirm_password': user.password}
# django.test.client doesn't like None fields in forms
for key in list(formData):
if formData[key] is None:
del formData[key]
res = self.client.post(USER_CREATE_URL, formData) res = self.client.post(USER_CREATE_URL, formData)
self.assertNoFormErrors(res) self.assertNoFormErrors(res)
@ -250,6 +262,11 @@ class UsersViewTests(test.BaseAdminViewTests):
'role_id': self.roles.first().id, 'role_id': self.roles.first().id,
'confirm_password': "doesntmatch"} 'confirm_password': "doesntmatch"}
# django.test.client doesn't like None fields in forms
for key in list(formData):
if formData[key] is None:
del formData[key]
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, "form", None, ['Passwords do not match.'])
@ -296,6 +313,11 @@ class UsersViewTests(test.BaseAdminViewTests):
'role_id': self.roles.first().id, 'role_id': self.roles.first().id,
'confirm_password': 'four'} 'confirm_password': 'four'}
# django.test.client doesn't like None fields in forms
for key in list(formData):
if formData[key] is None:
del formData[key]
res = self.client.post(USER_CREATE_URL, formData) res = self.client.post(USER_CREATE_URL, formData)
self.assertFormError( self.assertFormError(
@ -344,6 +366,11 @@ class UsersViewTests(test.BaseAdminViewTests):
'role_id': self.roles.first().id, 'role_id': self.roles.first().id,
'confirm_password': 'MoreThanEighteenChars'} 'confirm_password': 'MoreThanEighteenChars'}
# django.test.client doesn't like None fields in forms
for key in list(formData):
if formData[key] is None:
del formData[key]
res = self.client.post(USER_CREATE_URL, formData) res = self.client.post(USER_CREATE_URL, formData)
self.assertFormError( self.assertFormError(

View File

@ -5635,9 +5635,9 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
self.mock_instance_volume_attach.return_value = None self.mock_instance_volume_attach.return_value = None
volume = self.cinder_volumes.list()[1] volume = self.cinder_volumes.list()[1]
# note that 'device' is not passed
form_data = {"volume": volume.id, form_data = {"volume": volume.id,
"instance_id": server.id, "instance_id": server.id}
"device": None}
url = reverse('horizon:project:instances:attach_volume', url = reverse('horizon:project:instances:attach_volume',
args=[server.id]) args=[server.id])
@ -5647,7 +5647,7 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
self.assertRedirectsNoFollow(res, INDEX_URL) self.assertRedirectsNoFollow(res, INDEX_URL)
self.mock_volume_list.assert_called_once_with(helpers.IsHttpRequest()) self.mock_volume_list.assert_called_once_with(helpers.IsHttpRequest())
self.mock_instance_volume_attach.assert_called_once_with( self.mock_instance_volume_attach.assert_called_once_with(
helpers.IsHttpRequest(), volume.id, server.id, str(None)) helpers.IsHttpRequest(), volume.id, server.id, None)
@mock.patch.object(api.cinder, 'volume_list') @mock.patch.object(api.cinder, 'volume_list')
@mock.patch.object(api.cinder, 'volume_get') @mock.patch.object(api.cinder, 'volume_get')
@ -5665,9 +5665,9 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
mock_volume_list.return_value = volumes mock_volume_list.return_value = volumes
mock_volume_get.return_value = volume mock_volume_get.return_value = volume
# note that 'device' is not passed
form_data = {"volume": volume.id, form_data = {"volume": volume.id,
"instance_id": server.id, "instance_id": server.id}
"device": None}
url = reverse('horizon:project:instances:attach_volume', url = reverse('horizon:project:instances:attach_volume',
args=[server.id]) args=[server.id])
@ -5693,9 +5693,9 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
mock_volume_list.return_value = volumes mock_volume_list.return_value = volumes
mock_volume_get.return_value = volume mock_volume_get.return_value = volume
# note that 'device' is not passed
form_data = {"volume": volume.id, form_data = {"volume": volume.id,
"instance_id": server.id, "instance_id": server.id}
"device": None}
url = reverse('horizon:project:instances:attach_volume', url = reverse('horizon:project:instances:attach_volume',
args=[server.id]) args=[server.id])
@ -5724,9 +5724,9 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
self.mock_get_microversion.return_value = api_versions.APIVersion( self.mock_get_microversion.return_value = api_versions.APIVersion(
'2.60') '2.60')
# note that 'device' is not passed
form_data = {"volume": volume.id, form_data = {"volume": volume.id,
"instance_id": server1.id, "instance_id": server1.id}
"device": None}
url = reverse('horizon:project:instances:attach_volume', url = reverse('horizon:project:instances:attach_volume',
args=[server1.id]) args=[server1.id])
@ -5734,9 +5734,9 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
s1 = self.client.post(url, form_data) s1 = self.client.post(url, form_data)
self.assertNoFormErrors(s1) self.assertNoFormErrors(s1)
# note that device is not passed
form_data = {"volume": volume.id, form_data = {"volume": volume.id,
"instance_id": server2.id, "instance_id": server2.id}
"device": None}
url = reverse('horizon:project:instances:attach_volume', url = reverse('horizon:project:instances:attach_volume',
args=[server2.id]) args=[server2.id])

View File

@ -568,10 +568,10 @@ class SecurityGroupsViewTests(test.TestCase):
self.mock_security_group_list.return_value = sec_group_list self.mock_security_group_list.return_value = sec_group_list
self.mock_is_extension_supported.return_value = True self.mock_is_extension_supported.return_value = True
# note that 'port' is not passed
formData = {'method': 'AddRule', formData = {'method': 'AddRule',
'id': sec_group.id, 'id': sec_group.id,
'port_or_range': 'port', 'port_or_range': 'port',
'port': None,
'rule_menu': rule.ip_protocol, 'rule_menu': rule.ip_protocol,
'cidr': rule.ip_range['cidr'], 'cidr': rule.ip_range['cidr'],
'remote': 'cidr'} 'remote': 'cidr'}
@ -608,10 +608,10 @@ class SecurityGroupsViewTests(test.TestCase):
self.assertNoMessages() self.assertNoMessages()
self.assertContains(res, "greater than or equal to") self.assertContains(res, "greater than or equal to")
# note that 'from_port' is not passed
formData = {'method': 'AddRule', formData = {'method': 'AddRule',
'id': sec_group.id, 'id': sec_group.id,
'port_or_range': 'range', 'port_or_range': 'range',
'from_port': None,
'to_port': rule.to_port, 'to_port': rule.to_port,
'rule_menu': rule.ip_protocol, 'rule_menu': rule.ip_protocol,
'cidr': rule.ip_range['cidr'], 'cidr': rule.ip_range['cidr'],
@ -621,11 +621,11 @@ class SecurityGroupsViewTests(test.TestCase):
self.assertContains(res, cgi.escape('"from" port number is invalid', self.assertContains(res, cgi.escape('"from" port number is invalid',
quote=True)) quote=True))
# note that 'to_port' is not passed
formData = {'method': 'AddRule', formData = {'method': 'AddRule',
'id': sec_group.id, 'id': sec_group.id,
'port_or_range': 'range', 'port_or_range': 'range',
'from_port': rule.from_port, 'from_port': rule.from_port,
'to_port': None,
'rule_menu': rule.ip_protocol, 'rule_menu': rule.ip_protocol,
'cidr': rule.ip_range['cidr'], 'cidr': rule.ip_range['cidr'],
'remote': 'cidr'} 'remote': 'cidr'}
@ -675,30 +675,6 @@ class SecurityGroupsViewTests(test.TestCase):
self.assertNoMessages() self.assertNoMessages()
self.assertContains(res, "The ICMP code not in range (-1, 255)") self.assertContains(res, "The ICMP code not in range (-1, 255)")
formData = {'method': 'AddRule',
'id': sec_group.id,
'port_or_range': 'port',
'icmp_type': icmp_rule.from_port,
'icmp_code': None,
'rule_menu': icmp_rule.ip_protocol,
'cidr': icmp_rule.ip_range['cidr'],
'remote': 'cidr'}
res = self.client.post(self.edit_url, formData)
self.assertNoMessages()
self.assertContains(res, "The ICMP code not in range (-1, 255)")
formData = {'method': 'AddRule',
'id': sec_group.id,
'port_or_range': 'port',
'icmp_type': None,
'icmp_code': icmp_rule.to_port,
'rule_menu': icmp_rule.ip_protocol,
'cidr': icmp_rule.ip_range['cidr'],
'remote': 'cidr'}
res = self.client.post(self.edit_url, formData)
self.assertNoMessages()
self.assertContains(res, "The ICMP type not in range (-1, 255)")
formData = {'method': 'AddRule', formData = {'method': 'AddRule',
'id': sec_group.id, 'id': sec_group.id,
'port_or_range': 'port', 'port_or_range': 'port',
@ -713,10 +689,10 @@ class SecurityGroupsViewTests(test.TestCase):
res, "ICMP code is provided but ICMP type is missing.") res, "ICMP code is provided but ICMP type is missing.")
self.assert_mock_multiple_calls_with_same_arguments( self.assert_mock_multiple_calls_with_same_arguments(
self.mock_security_group_list, 10, self.mock_security_group_list, 6,
mock.call(test.IsHttpRequest())) mock.call(test.IsHttpRequest()))
self.assert_mock_multiple_calls_with_same_arguments( self.assert_mock_multiple_calls_with_same_arguments(
self.mock_is_extension_supported, 10, self.mock_is_extension_supported, 6,
mock.call(test.IsHttpRequest(), 'standard-attr-description')) mock.call(test.IsHttpRequest(), 'standard-attr-description'))
@test.create_mocks({api.neutron: ('security_group_rule_create', @test.create_mocks({api.neutron: ('security_group_rule_create',