diff --git a/masakari/tests/unit/api/openstack/ha/test_hosts.py b/masakari/tests/unit/api/openstack/ha/test_hosts.py index f85fb358..dde9dcc8 100644 --- a/masakari/tests/unit/api/openstack/ha/test_hosts.py +++ b/masakari/tests/unit/api/openstack/ha/test_hosts.py @@ -15,6 +15,7 @@ """Tests for the hosts api.""" +import ddt import mock from oslo_serialization import jsonutils from six.moves import http_client as http @@ -66,6 +67,7 @@ HOST = { HOST = _make_host_obj(HOST) +@ddt.ddt class HostTestCase(test.TestCase): """Test Case for host api.""" @@ -199,32 +201,31 @@ class HostTestCase(test.TestCase): self.assertRaises(exc.HTTPBadRequest, self.controller.index, req, uuidsentinel.fake_segment1) + @ddt.data('sort_key', 'sort_dir') @mock.patch.object(segment_obj.FailoverSegment, 'get_by_uuid', return_value=mock.Mock()) - def test_index_invalid_sort_key(self, mock_segment): - - req = fakes.HTTPRequest.blank('/v1/segments/%s/hosts?sort_key=abcd' % ( - uuidsentinel.fake_segment1), use_admin_context=True) - self.assertRaises(exc.HTTPBadRequest, self.controller.index, req, - uuidsentinel.fake_segment1) - - @mock.patch.object(segment_obj.FailoverSegment, 'get_by_uuid', - return_value=mock.Mock()) - def test_index_invalid_sort_dir(self, mock_segment): - - req = fakes.HTTPRequest.blank('/v1/segments/%s/hosts?sort_dir=abcd' % ( - uuidsentinel.fake_segment1), use_admin_context=True) + def test_index_invalid(self, sort_by, mock_segment): + req = fakes.HTTPRequest.blank('/v1/segments/%s/hosts?%s=abcd' % ( + uuidsentinel.fake_segment1, sort_by), use_admin_context=True) self.assertRaises(exc.HTTPBadRequest, self.controller.index, req, uuidsentinel.fake_segment1) + @ddt.data([exception.MarkerNotFound, "/v1/segments/%s/hosts?marker=123456", + exc.HTTPBadRequest], + [exception.FailoverSegmentNotFound, "/v1/segments/%s/hosts", + exc.HTTPNotFound]) + @ddt.unpack @mock.patch.object(segment_obj.FailoverSegment, 'get_by_uuid') @mock.patch.object(ha_api.HostAPI, 'get_all') - def test_index_failover_segment_not_found(self, mock_get_all, - mock_segment): + def test_index_not_found(self, masakari_exc, url, exc, mock_get_all, + mock_segment): mock_segment.return_value = mock.Mock() - mock_get_all.side_effect = exception.FailoverSegmentNotFound - self.assertRaises(exc.HTTPNotFound, self.controller.index, - self.req, uuidsentinel.fake_segment1) + mock_get_all.side_effect = masakari_exc + + req = fakes.HTTPRequest.blank(url % uuidsentinel.fake_segment1, + use_admin_context=True) + self.assertRaises(exc, self.controller.index, req, + uuidsentinel.fake_segment1) @mock.patch.object(ha_api.HostAPI, 'create_host') def test_create(self, mock_create): @@ -277,74 +278,73 @@ class HostTestCase(test.TestCase): self.assertRaises(exc.HTTPConflict, self.controller.create, self.req, uuidsentinel.fake_segment1, body=body) - def test_create_with_no_host(self): - body = { + @ddt.data( + # no_host + {"body": { "name": "host-1", "type": "fake", "reserved": False, "on_maintenance": False, - "control_attributes": "fake-control_attributes" - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, uuidsentinel.fake_segment1, body=body) + "control_attributes": "fake-control_attributes"}}, - def test_create_with_no_name(self): - body = { + # no_name + {"body": { "host": { "type": "fake", "reserved": False, "on_maintenance": False, - "control_attributes": "fake-control_attributes" - } - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, uuidsentinel.fake_segment1, body=body) + "control_attributes": "fake-control_attributes"}}}, - def test_create_name_with_leading_trailing_spaces(self): - body = { + # name_with_leading_trailing_spaces + {"body": { "host": { "name": " host-1 ", "type": "fake", "reserved": False, "on_maintenance": False, - "control_attributes": "fake-control_attributes" - } - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, uuidsentinel.fake_segment1, body=body) + "control_attributes": "fake-control_attributes"}}}, - def test_create_with_null_name(self): - body = { + # null_name + {"body": { "host": { "name": "", "type": "fake", "reserved": False, "on_maintenance": False, - "control_attributes": "fake-control_attributes" - } - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, uuidsentinel.fake_segment1, body=body) + "control_attributes": "fake-control_attributes"}}}, - def test_create_with_name_too_long(self): - body = { + # name_too_long + {"body": { "host": { "name": "host-1" * 255, "type": "fake", "reserved": False, "on_maintenance": False, - "control_attributes": "fake-control_attributes" - } - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, uuidsentinel.fake_segment1, body=body) + "control_attributes": "fake-control_attributes"}}}, - def test_create_with_extra_invalid_arg(self): - body = { + # extra_invalid_arg + {"body": { "host": { "name": "host-1", "type": "fake", "reserved": False, "on_maintenance": False, "control_attributes": "fake-control_attributes", - "foo": "bar" - } - } + "foo": "bar"}}}, + + # type too long + {"body": { + "host": { + "name": "host-1", "type": "x" * 256, + "reserved": False, + "on_maintenance": False, + "control_attributes": "fake-control_attributes"}}}, + + # type special characters + {"body": { + "host": { + "name": "host-1", "type": "x_y", + "reserved": False, + "on_maintenance": False, + "control_attributes": "fake-control_attributes"}}} + ) + @ddt.unpack + def test_create_failure(self, body): self.assertRaises(self.bad_request, self.controller.create, self.req, uuidsentinel.fake_segment1, body=body) @@ -366,32 +366,21 @@ class HostTestCase(test.TestCase): self.controller.show, self.req, uuidsentinel.fake_segment1, "2") - @mock.patch.object(ha_api.HostAPI, 'update_host') - def test_update(self, mock_update_host): - - mock_update_host.return_value = HOST - - body = { + @ddt.data( + {"body": { "host": { "name": "host-1", "type": "fake", "reserved": False, "on_maintenance": False, - "control_attributes": "fake-control_attributes" - } - } - - result = self.controller.update(self.req, uuidsentinel.fake_segment1, - uuidsentinel.fake_host_1, - body=body) - - result = result['host'] - self._assert_host_data(HOST, _make_host_obj(result)) + "control_attributes": "fake-control_attributes"}}}, + # only name + {"body": {"host": {"name": "host-1"}}} + ) + @ddt.unpack @mock.patch.object(ha_api.HostAPI, 'update_host') - def test_update_with_only_name(self, mock_update_host): + def test_update(self, mock_update_host, body): mock_update_host.return_value = HOST - body = {"host": {"name": "host-1"}} - result = self.controller.update(self.req, uuidsentinel.fake_segment1, uuidsentinel.fake_host_1, body=body) @@ -399,36 +388,34 @@ class HostTestCase(test.TestCase): result = result['host'] self._assert_host_data(HOST, _make_host_obj(result)) - def test_update_with_no_updates(self): - test_data = {"host": {}} + @ddt.data( + # no updates + {"test_data": {"host": {}}}, + + # no update key + {"test_data": {"asdf": {}}}, + + # wrong updates + {"test_data": {"host": {"name": "disable", "foo": "bar"}}}, + + # null name + {"test_data": {"host": {"name": ""}}}, + + # name too long + {"test_data": {"host": {"name": "x" * 256}}}, + + # type too long + {"test_data": {"host": {"type": "x" * 256}}}, + + # type with special characters + {"test_data": {"host": {"type": "x_y"}}} + ) + @ddt.unpack + def test_update_failure(self, test_data): self.assertRaises(self.bad_request, self.controller.update, self.req, uuidsentinel.fake_segment1, uuidsentinel.fake_host_1, body=test_data) - def test_update_with_no_update_key(self): - test_data = {"asdf": {}} - self.assertRaises(self.bad_request, self.controller.update, - self.req, uuidsentinel.fake_segment1, - uuidsentinel.fake_host_1, body=test_data) - - def test_update_with_wrong_updates(self): - test_data = {"host": {"name": "disable", "foo": "bar"}} - self.assertRaises(self.bad_request, self.controller.update, - self.req, uuidsentinel.fake_segment1, - uuidsentinel.fake_host_1, body=test_data) - - def test_update_with_null_name(self): - test_metadata = {"host": {"name": ""}} - self.assertRaises(self.bad_request, self.controller.update, - self.req, uuidsentinel.fake_segment1, - uuidsentinel.fake_host_1, body=test_metadata) - - def test_update_with_name_too_long(self): - test_metadata = {"host": {"name": "x" * 256}} - self.assertRaises(self.bad_request, self.controller.update, - self.req, uuidsentinel.fake_segment1, - uuidsentinel.fake_host_1, body=test_metadata) - @mock.patch.object(ha_api.HostAPI, 'update_host') def test_update_with_non_exising_host(self, mock_update_host): @@ -473,42 +460,6 @@ class HostTestCase(test.TestCase): self.req, uuidsentinel.fake_segment1, uuidsentinel.fake_host_3) - def test_create_with_type_too_long(self): - body = { - "host": { - "name": "host-1", "type": "x" * 256, - "reserved": False, - "on_maintenance": False, - "control_attributes": "fake-control_attributes" - } - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, uuidsentinel.fake_segment1, body=body) - - def test_create_with_type_special_characters(self): - body = { - "host": { - "name": "host-1", "type": "x_y", - "reserved": False, - "on_maintenance": False, - "control_attributes": "fake-control_attributes" - } - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, uuidsentinel.fake_segment1, body=body) - - def test_update_with_type_too_long(self): - test_metadata = {"host": {"type": "x" * 256}} - self.assertRaises(self.bad_request, self.controller.update, - self.req, uuidsentinel.fake_segment1, - uuidsentinel.fake_host_1, body=test_metadata) - - def test_update_with_type_special_characters(self): - test_metadata = {"host": {"type": "x_y"}} - self.assertRaises(self.bad_request, self.controller.update, - self.req, uuidsentinel.fake_segment1, - uuidsentinel.fake_host_1, body=test_metadata) - class HostTestCasePolicyNotAuthorized(test.NoDBTestCase): """Test Case for host non admin.""" diff --git a/masakari/tests/unit/api/openstack/ha/test_notifications.py b/masakari/tests/unit/api/openstack/ha/test_notifications.py index a4d503f8..4b21460e 100644 --- a/masakari/tests/unit/api/openstack/ha/test_notifications.py +++ b/masakari/tests/unit/api/openstack/ha/test_notifications.py @@ -15,6 +15,7 @@ """Tests for the notifications api.""" +import ddt import mock from oslo_serialization import jsonutils from oslo_utils import timeutils @@ -77,6 +78,7 @@ NOTIFICATION_LIST = [ NOTIFICATION_LIST = _make_notifications_list(NOTIFICATION_LIST) +@ddt.ddt class NotificationTestCase(test.TestCase): """Test Case for notifications api.""" @@ -108,22 +110,19 @@ class NotificationTestCase(test.TestCase): self._assert_notification_data(NOTIFICATION_LIST, _make_notifications_list(result)) - def test_index_marker_negative(self): + @ddt.data( + # limit negative + "limit=-1", - req = fakes.HTTPRequest.blank('/v1/notifications?limit=-1', + # invalid sort key + "sort_key=abcd", + + # invalid sort dir + "sort_dir=abcd") + def test_index_invalid(self, param): + req = fakes.HTTPRequest.blank("/v1/notifications?%s" % param, use_admin_context=True) - self.assertRaises(exc.HTTPBadRequest, self.controller.index, req) - def test_index_invalid_sort_key(self): - - req = fakes.HTTPRequest.blank('/v1/notifications?sort_key=abcd', - use_admin_context=True) - self.assertRaises(exc.HTTPBadRequest, self.controller.index, req) - - def test_index_invalid_sort_dir(self): - - req = fakes.HTTPRequest.blank('/v1/notifications?sort_dir=abcd', - use_admin_context=True) self.assertRaises(exc.HTTPBadRequest, self.controller.index, req) @mock.patch.object(ha_api.NotificationAPI, 'get_all') @@ -187,17 +186,6 @@ class NotificationTestCase(test.TestCase): resp = fake_req.get_response(self.app) self.assertEqual(http.ACCEPTED, resp.status_code) - def test_create_invalid_type(self): - body = { - "notification": {"hostname": "fake_host", - "payload": {"event": "STOPPED", - "host_status": "NORMAL", - "cluster_status": "ONLINE"}, - "type": "Fake", - "generated_time": "2016-09-13T09:11:21.656788"}} - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) - @mock.patch.object(ha_api.NotificationAPI, 'create_notification') def test_create_host_not_found(self, mock_create): body = { @@ -211,74 +199,75 @@ class NotificationTestCase(test.TestCase): self.assertRaises(exc.HTTPBadRequest, self.controller.create, self.req, body=body) - def test_create_with_no_notification_in_body(self): - body = {"hostname": "fake_host", - "payload": {"event": "STOPPED", - "host_status": "NORMAL", - "cluster_status": "ONLINE"}, - "type": "VM", - "generated_time": "2016-09-13T09:11:21.656788"} - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + @ddt.data( + # invalid type + {"body": { + "notification": {"hostname": "fake_host", + "payload": {"event": "STOPPED", + "host_status": "NORMAL", + "cluster_status": "ONLINE"}, + "type": "Fake", + "generated_time": "2016-09-13T09:11:21.656788"}}}, - def test_create_with_no_payload(self): - body = {"notification": {"hostname": "fake_host", - "type": "VM", - "generated_time": - "2016-09-13T09:11:21.656788"}} - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + # no notification in body + {"body": {"hostname": "fake_host", + "payload": {"event": "STOPPED", + "host_status": "NORMAL", + "cluster_status": "ONLINE"}, + "type": "VM", + "generated_time": "2016-09-13T09:11:21.656788"}}, - def test_create_with_no_hostname(self): - body = {"notification": {"payload": {"event": "STOPPED", - "host_status": "NORMAL", - "cluster_status": "ONLINE"}, - "type": "VM", - "generated_time": - "2016-09-13T09:11:21.656788"}} - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + # no payload + {"body": {"notification": {"hostname": "fake_host", + "type": "VM", + "generated_time": + "2016-09-13T09:11:21.656788"}}}, - def test_create_with_no_type(self): - body = {"notification": {"hostname": "fake_host", - "payload": {"event": "STOPPED", - "host_status": "NORMAL", - "cluster_status": "ONLINE"}, - "generated_time": - "2016-09-13T09:11:21.656788"}} - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + # no hostname + {"body": {"notification": {"payload": {"event": "STOPPED", + "host_status": "NORMAL", + "cluster_status": "ONLINE"}, + "type": "VM", + "generated_time": + "2016-09-13T09:11:21.656788"}}}, - def test_create_with_no_generated_time(self): - body = {"notification": {"hostname": "fake_host", - "payload": {"event": "STOPPED", - "host_status": "NORMAL", - "cluster_status": "ONLINE"}, - "type": "VM", - }} - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + # no type + {"body": {"notification": {"hostname": "fake_host", + "payload": {"event": "STOPPED", + "host_status": "NORMAL", + "cluster_status": "ONLINE"}, + "generated_time": + "2016-09-13T09:11:21.656788"}}}, - def test_create_with_hostname_too_long(self): - body = { + # no generated time + {"body": {"notification": {"hostname": "fake_host", + "payload": {"event": "STOPPED", + "host_status": "NORMAL", + "cluster_status": "ONLINE"}, + "type": "VM", + }}}, + + # hostname too long + {"body": { "notification": {"hostname": "fake_host" * 255, "payload": {"event": "STOPPED", "host_status": "NORMAL", "cluster_status": "ONLINE"}, "type": "VM", - "generated_time": "2016-09-13T09:11:21.656788"}} - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + "generated_time": "2016-09-13T09:11:21.656788"}}}, - def test_create_with_extra_invalid_arg(self): - body = { + # extra invalid args + {"body": { "notification": {"hostname": "fake_host", "payload": {"event": "STOPPED", "host_status": "NORMAL", "cluster_status": "ONLINE"}, "type": "VM", "generated_time": "2016-09-13T09:11:21.656788", - "invalid_extra": "non_expected_parameter"}} + "invalid_extra": "non_expected_parameter"}}} + ) + @ddt.unpack + def test_create_failure(self, body): self.assertRaises(self.bad_request, self.controller.create, self.req, body=body) @@ -325,21 +314,13 @@ class NotificationTestCase(test.TestCase): self.assertRaises(exc.HTTPNotFound, self.controller.show, self.req, "2") + @ddt.data('DELETE', 'PUT') @mock.patch('masakari.rpc.get_client') - def test_delete_notification(self, mock_client): + def test_delete_and_update_notification(self, method, mock_client): url = '/v1/notifications/%s' % uuidsentinel.fake_notification fake_req = fakes.HTTPRequest.blank(url, use_admin_context=True) fake_req.headers['Content-Type'] = 'application/json' - fake_req.method = 'DELETE' - resp = fake_req.get_response(self.app) - self.assertEqual(http.METHOD_NOT_ALLOWED, resp.status_code) - - @mock.patch('masakari.rpc.get_client') - def test_update_notification(self, mock_client): - url = '/v1/notifications/%s' % uuidsentinel.fake_notification - fake_req = fakes.HTTPRequest.blank(url, use_admin_context=True) - fake_req.headers['Content-Type'] = 'application/json' - fake_req.method = 'PUT' + fake_req.method = method resp = fake_req.get_response(self.app) self.assertEqual(http.METHOD_NOT_ALLOWED, resp.status_code) diff --git a/masakari/tests/unit/api/openstack/ha/test_segments.py b/masakari/tests/unit/api/openstack/ha/test_segments.py index ff3d3e4e..55f5d0ce 100644 --- a/masakari/tests/unit/api/openstack/ha/test_segments.py +++ b/masakari/tests/unit/api/openstack/ha/test_segments.py @@ -15,6 +15,7 @@ """Tests for the failover segment api.""" +import ddt import mock from oslo_serialization import jsonutils from six.moves import http_client as http @@ -58,6 +59,7 @@ FAILOVER_SEGMENT = {"name": "segment1", "id": "1", FAILOVER_SEGMENT = _make_segment_obj(FAILOVER_SEGMENT) +@ddt.ddt class FailoverSegmentTestCase(test.TestCase): """Test Case for failover segment api.""" @@ -96,23 +98,19 @@ class FailoverSegmentTestCase(test.TestCase): self.assertRaises(exc.HTTPBadRequest, self.controller.index, fake_request) - def test_get_all_marker_negative(self): + @ddt.data( + # limit negative + 'limit=-1', - fake_request = fakes.HTTPRequest.blank('/v1/segments?limit=-1', - use_admin_context=True) - self.assertRaises(exc.HTTPBadRequest, self.controller.index, - fake_request) + # invalid sort key + 'sort_key=abcd', - def test_index_invalid_sort_key(self): - - req = fakes.HTTPRequest.blank('/v1/segments?sort_key=abcd', + # invalid sort dir + 'sort_dir=abcd') + def test_index_invalid(self, param): + req = fakes.HTTPRequest.blank("/v1/segments?%s" % param, use_admin_context=True) - self.assertRaises(exc.HTTPBadRequest, self.controller.index, req) - def test_index_invalid_sort_dir(self): - - req = fakes.HTTPRequest.blank('/v1/segments?sort_dir=abcd', - use_admin_context=True) self.assertRaises(exc.HTTPBadRequest, self.controller.index, req) @mock.patch.object(ha_api.FailoverSegmentAPI, 'create_segment') @@ -164,73 +162,56 @@ class FailoverSegmentTestCase(test.TestCase): resp = fake_req.get_response(self.app) self.assertEqual(http.CREATED, resp.status_code) - def test_create_with_no_segment(self): - body = { + @ddt.data( + # no segment + {"body": { "name": "segment1", "service_type": "COMPUTE", "recovery_method": "auto", - "description": "failover_segment for compute" - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + "description": "failover_segment for compute"}}, - def test_create_with_no_name(self): - body = { + # no name + {"body": { "segment": { "service_type": "COMPUTE", "recovery_method": "auto", - "description": "failover_segment for compute" - } - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + "description": "failover_segment for compute"}}}, - def test_create_name_with_leading_trailing_spaces(self): - body = { + # name with leading trailing spaces + {"body": { "segment": { "name": " segment1 ", "service_type": "COMPUTE", "recovery_method": "auto", - "description": "failover_segment for compute" - } - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + "description": "failover_segment for compute"}}}, - def test_create_with_null_name(self): - body = { + # null name + {"body": { "segment": { "name": "", "service_type": "COMPUTE", "recovery_method": "auto", - "description": "failover_segment for compute" - } - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + "description": "failover_segment for compute"}}}, - def test_create_with_name_too_long(self): - body = { + # name too long + {"body": { "segment": { "name": "segment1" * 255, "service_type": "COMPUTE", "recovery_method": "auto", - "description": "failover_segment for compute" - } - } - self.assertRaises(self.bad_request, self.controller.create, - self.req, body=body) + "description": "failover_segment for compute"}}}, - def test_create_with_extra_invalid_arg(self): - body = { + # extra invalid args + {"body": { "segment": { "name": "segment1" * 255, "service_type": "COMPUTE", "recovery_method": "auto", "description": "failover_segment for compute", - "foo": "fake_foo" - } - } + "foo": "fake_foo"}}} + ) + @ddt.unpack + def test_create_failure(self, body): self.assertRaises(self.bad_request, self.controller.create, self.req, body=body) @@ -250,59 +231,46 @@ class FailoverSegmentTestCase(test.TestCase): self.assertRaises(exc.HTTPNotFound, self.controller.show, self.req, "2") + @ddt.data( + {"body": {"segment": {"name": "segment1", "service_type": "COMPUTE", + "recovery_method": "auto"}}}, + + # with name only + {"body": {"segment": {"name": "segment1"}}} + + ) + @ddt.unpack @mock.patch.object(ha_api.FailoverSegmentAPI, 'update_segment') - def test_update(self, mock_update_segment): - + def test_update(self, mock_update_segment, body): mock_update_segment.return_value = FAILOVER_SEGMENT - body = {"segment": {"name": "segment1", "service_type": "COMPUTE", - "recovery_method": "auto"}} - result = self.controller.update(self.req, uuidsentinel.fake_segment, body=body) result = result['segment'] self._assert_segment_data(FAILOVER_SEGMENT, _make_segment_obj(result)) - @mock.patch.object(ha_api.FailoverSegmentAPI, 'update_segment') - def test_update_with_only_name(self, mock_update_segment): - mock_update_segment.return_value = FAILOVER_SEGMENT + @ddt.data( + # no updates + {"test_data": {"segment": {}}}, - body = {"segment": {"name": "segment1"}} + # no update key + {"test_data": {"asdf": {}}}, - result = self.controller.update(self.req, uuidsentinel.fake_segment, - body=body) + # wrong updates + {"test_data": {"segment": {"name": "disable", "foo": "bar"}}}, - result = result['segment'] - self._assert_segment_data(FAILOVER_SEGMENT, _make_segment_obj(result)) + # null name + {"test_data": {"segment": {"name": ""}}}, - def test_update_with_no_updates(self): - test_data = {"segment": {}} + # name too long + {"test_data": {"segment": {"name": "x" * 256}}} + ) + @ddt.unpack + def test_update_failure(self, test_data): self.assertRaises(self.bad_request, self.controller.update, self.req, uuidsentinel.fake_segment, body=test_data) - def test_update_with_no_update_key(self): - test_data = {"asdf": {}} - self.assertRaises(self.bad_request, self.controller.update, - self.req, uuidsentinel.fake_segment, body=test_data) - - def test_update_with_wrong_updates(self): - test_data = {"segment": {"name": "disable", "foo": "bar"}} - self.assertRaises(self.bad_request, self.controller.update, - self.req, uuidsentinel.fake_segment, body=test_data) - - def test_update_with_null_name(self): - test_metadata = {"segment": {"name": ""}} - self.assertRaises(self.bad_request, self.controller.update, - self.req, uuidsentinel.fake_segment, - body=test_metadata) - - def test_update_with_name_too_long(self): - test_metadata = {"segment": {"name": "x" * 256}} - self.assertRaises(self.bad_request, self.controller.update, - self.req, uuidsentinel.fake_segment, - body=test_metadata) - @mock.patch.object(ha_api.FailoverSegmentAPI, 'update_segment') def test_update_with_non_exising_segment(self, mock_update_segment): diff --git a/test-requirements.txt b/test-requirements.txt index 72f518a6..396faeaf 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,6 +5,7 @@ hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 coverage>=4.0 # Apache-2.0 +ddt>=1.0.1 # MIT psycopg2>=2.5 # LGPL/ZPL PyMySQL>=0.7.6 # MIT License python-subunit>=0.0.18 # Apache-2.0/BSD