Python unittest.mock.ANY Examples
The following are 30
code examples of unittest.mock.ANY().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
unittest.mock
, or try the search function
.

Example #1
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_get_one_by_uuid_all_projects(self, mock_container_get_by_uuid, mock_container_show, mock_policy): mock_policy.return_value = True test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_container_get_by_uuid.return_value = test_container_obj mock_container_show.return_value = test_container_obj response = self.get('/v1/containers/%s/?all_projects=1' % test_container['uuid']) mock_container_get_by_uuid.assert_called_once_with( mock.ANY, test_container['uuid']) context = mock_container_get_by_uuid.call_args[0][0] self.assertIs(True, context.all_projects) self.assertEqual(200, response.status_int) self.assertEqual(test_container['uuid'], response.json['uuid'])
Example #2
Source File: test_registries.py From zun with Apache License 2.0 | 6 votes |
def test_get_all_registries_all_projects(self, mock_registry_list, mock_policy): mock_policy.return_value = True test_registry = utils.get_test_registry() registries = [objects.Registry(self.context, **test_registry)] mock_registry_list.return_value = registries response = self.get('/v1/registries/?all_projects=1') mock_registry_list.assert_called_once_with(mock.ANY, 1000, None, 'id', 'asc', filters={}) context = mock_registry_list.call_args[0][0] self.assertIs(True, context.all_projects) self.assertEqual(200, response.status_int) actual_registries = response.json['registries'] self.assertEqual(1, len(actual_registries)) self.assertEqual(test_registry['uuid'], actual_registries[0].get('uuid'))
Example #3
Source File: test_report.py From zun with Apache License 2.0 | 6 votes |
def test_set_aggregates_for_provider(self): aggs = [uuids.agg1, uuids.agg2] self.ks_adap_mock.put.return_value = fake_requests.FakeResponse( 200, content=jsonutils.dumps({ 'aggregates': aggs, 'resource_provider_generation': 1})) # Prime the provider tree cache self.client._provider_tree.new_root('rp', uuids.rp, generation=0) self.assertEqual(set(), self.client._provider_tree.data(uuids.rp).aggregates) self.client.set_aggregates_for_provider(self.context, uuids.rp, aggs) exp_payload = {'aggregates': aggs, 'resource_provider_generation': 0} self.ks_adap_mock.put.assert_called_once_with( '/resource_providers/%s/aggregates' % uuids.rp, json=exp_payload, microversion='1.19', endpoint_filter=mock.ANY, logger=mock.ANY, headers={'X-Openstack-Request-Id': self.context.global_id}) # Cache was updated ptree_data = self.client._provider_tree.data(uuids.rp) self.assertEqual(set(aggs), ptree_data.aggregates) self.assertEqual(1, ptree_data.generation)
Example #4
Source File: test_report.py From zun with Apache License 2.0 | 6 votes |
def test_set_aggregates_for_provider_no_short_circuit(self): """Don't short-circuit if generation doesn't match, even if aggs have not changed. """ # Prime the provider tree cache self.client._provider_tree.new_root('rp', uuids.rp, generation=2) self.ks_adap_mock.put.return_value = fake_requests.FakeResponse( 200, content=jsonutils.dumps({ 'aggregates': [], 'resource_provider_generation': 5})) self.client.set_aggregates_for_provider(self.context, uuids.rp, [], generation=4) exp_payload = {'aggregates': [], 'resource_provider_generation': 4} self.ks_adap_mock.put.assert_called_once_with( '/resource_providers/%s/aggregates' % uuids.rp, json=exp_payload, microversion='1.19', endpoint_filter=mock.ANY, logger=mock.ANY, headers={'X-Openstack-Request-Id': self.context.global_id}) # Cache was updated ptree_data = self.client._provider_tree.data(uuids.rp) self.assertEqual(set(), ptree_data.aggregates) self.assertEqual(5, ptree_data.generation)
Example #5
Source File: test_images.py From zun with Apache License 2.0 | 6 votes |
def test_get_all_images(self, mock_image_list, mock_policy_enforce): test_image = utils.get_test_image() images = [objects.Image(self.context, **test_image)] mock_image_list.return_value = images response = self.get('/v1/images/') mock_image_list.assert_called_once_with(mock.ANY, 1000, None, 'id', 'asc', filters=None) self.assertEqual(200, response.status_int) actual_images = response.json['images'] self.assertEqual(1, len(actual_images)) self.assertEqual(test_image['uuid'], actual_images[0].get('uuid')) self.assertEqual(test_image['host'], actual_images[0].get('host'))
Example #6
Source File: test_availability_zones.py From zun with Apache License 2.0 | 6 votes |
def test_get_all_availability_zones(self, mock_availability_zone_list, mock_policy): mock_policy.return_value = True test_a_zone = utils.get_test_zun_service() availability_zones = [objects.ZunService(self.context, **test_a_zone)] mock_availability_zone_list.return_value = availability_zones response = self.get('/v1/availability_zones') mock_availability_zone_list.assert_called_once_with( mock.ANY, 1000, None, 'availability_zone', 'asc') self.assertEqual(200, response.status_int) actual_a_zones = response.json['availability_zones'] self.assertEqual(1, len(actual_a_zones)) self.assertEqual(test_a_zone['availability_zone'], actual_a_zones[0].get('availability_zone'))
Example #7
Source File: test_report.py From zun with Apache License 2.0 | 6 votes |
def test_get_provider_aggregates_error(self, log_mock): """Test that when the placement API returns any error when looking up a provider's aggregates, we raise an exception. """ uuid = uuids.compute_node resp_mock = mock.Mock(headers={ 'x-openstack-request-id': uuids.request_id}) self.ks_adap_mock.get.return_value = resp_mock for status_code in (400, 404, 503): resp_mock.status_code = status_code self.assertRaises( exception.ResourceProviderAggregateRetrievalFailed, self.client._get_provider_aggregates, self.context, uuid) expected_url = '/resource_providers/' + uuid + '/aggregates' self.ks_adap_mock.get.assert_called_once_with( expected_url, microversion='1.19', endpoint_filter=mock.ANY, logger=mock.ANY, headers={'X-Openstack-Request-Id': self.context.global_id}) self.assertTrue(log_mock.called) self.assertEqual(uuids.request_id, log_mock.call_args[0][1]['placement_req_id']) self.ks_adap_mock.get.reset_mock() log_mock.reset_mock()
Example #8
Source File: test_capsules.py From zun with Apache License 2.0 | 6 votes |
def test_get_all_capsules_with_exception(self, mock_container_get_by_uuid, mock_capsule_list): test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_container_get_by_uuid.return_value = test_container_obj test_capsule = utils.create_test_container(context=self.context) test_capsule_obj = objects.Capsule(self.context, **test_capsule) mock_capsule_list.return_value = [test_capsule_obj] response = self.app.get('/v1/capsules/') mock_capsule_list.assert_called_once_with(mock.ANY, 1000, None, 'id', 'asc', filters=None) context = mock_capsule_list.call_args[0][0] self.assertIs(False, context.all_projects) self.assertEqual(200, response.status_int) actual_capsules = response.json['capsules'] self.assertEqual(1, len(actual_capsules)) self.assertEqual(test_capsule['uuid'], actual_capsules[0].get('uuid'))
Example #9
Source File: test_report.py From zun with Apache License 2.0 | 6 votes |
def test_get_provider_traits_found(self): uuid = uuids.compute_node resp_mock = mock.Mock(status_code=200) traits = [ 'CUSTOM_GOLD', 'CUSTOM_SILVER', ] resp_mock.json.return_value = {'traits': traits, 'resource_provider_generation': 42} self.ks_adap_mock.get.return_value = resp_mock result, gen = self.client.get_provider_traits(self.context, uuid) expected_url = '/resource_providers/' + uuid + '/traits' self.ks_adap_mock.get.assert_called_once_with( expected_url, endpoint_filter=mock.ANY, logger=mock.ANY, headers={'X-Openstack-Request-Id': self.context.global_id}, **self.trait_api_kwargs) self.assertEqual(set(traits), result) self.assertEqual(42, gen)
Example #10
Source File: test_capsules.py From zun with Apache License 2.0 | 6 votes |
def test_get_all_capsules(self, mock_container_get_by_uuid, mock_capsule_list, mock_container_show): test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_container_get_by_uuid.return_value = test_container_obj test_capsule = utils.create_test_container(context=self.context) test_capsule_obj = objects.Capsule(self.context, **test_capsule) mock_capsule_list.return_value = [test_capsule_obj] mock_container_show.return_value = test_container_obj response = self.app.get('/v1/capsules/') mock_capsule_list.assert_called_once_with(mock.ANY, 1000, None, 'id', 'asc', filters=None) context = mock_capsule_list.call_args[0][0] self.assertIs(False, context.all_projects) self.assertEqual(200, response.status_int) actual_capsules = response.json['capsules'] self.assertEqual(1, len(actual_capsules)) self.assertEqual(test_capsule['uuid'], actual_capsules[0].get('uuid'))
Example #11
Source File: test_report.py From zun with Apache License 2.0 | 6 votes |
def test_ensure_traits_fail_creation(self): get_mock = mock.Mock(status_code=200) get_mock.json.return_value = {'traits': []} self.ks_adap_mock.get.return_value = get_mock self.ks_adap_mock.put.return_value = fake_requests.FakeResponse(400) self.assertRaises(exception.TraitCreationFailed, self.client._ensure_traits, self.context, ['FOO']) self.ks_adap_mock.get.assert_called_once_with( '/traits?name=in:FOO', endpoint_filter=mock.ANY, logger=mock.ANY, headers={'X-Openstack-Request-Id': self.context.global_id}, **self.trait_api_kwargs) self.ks_adap_mock.put.assert_called_once_with( '/traits/FOO', endpoint_filter=mock.ANY, logger=mock.ANY, headers={'X-Openstack-Request-Id': self.context.global_id}, **self.trait_api_kwargs)
Example #12
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_get_all_containers_by_admin(self, mock_container_list, mock_can): mock_can.return_value = True test_container = utils.get_test_container() containers = [objects.Container(self.context, **test_container)] mock_container_list.return_value = containers response = self.get('/v1/containers/') mock_container_list.assert_called_once_with(mock.ANY, 1000, None, 'id', 'asc', filters={}) context = mock_container_list.call_args[0][0] self.assertIs(False, context.all_projects) self.assertEqual(200, response.status_int) actual_containers = response.json['containers'] self.assertEqual(1, len(actual_containers)) self.assertEqual(test_container['uuid'], actual_containers[0].get('uuid')) self.assertIn('host', actual_containers[0])
Example #13
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_list_actions(self, mock_get_by_container_uuid, mock_container_get_by_uuid): test_container = utils.get_test_container() test_action = utils.get_test_action_value( container_uuid=test_container['uuid']) container_object = objects.Container(self.context, **test_container) action_object = objects.ContainerAction(self.context, **test_action) mock_container_get_by_uuid.return_value = container_object mock_get_by_container_uuid.return_value = [action_object] response = self.get('/v1/containers/%s/container_actions' % test_container['uuid']) mock_get_by_container_uuid.assert_called_once_with( mock.ANY, test_container['uuid']) self.assertEqual(200, response.status_int) self.assertEqual( self._format_action(test_action), self._format_action(response.json['containerActions'][0]))
Example #14
Source File: test_report.py From zun with Apache License 2.0 | 6 votes |
def test_create_resource_provider(self): """Test that _create_resource_provider() sends a dict of resource provider information without a parent provider UUID. """ uuid = uuids.compute_node name = 'computehost' resp_mock = mock.Mock(status_code=200) self.ks_adap_mock.post.return_value = resp_mock self.assertEqual( resp_mock.json.return_value, self.client._create_resource_provider(self.context, uuid, name)) expected_payload = { 'uuid': uuid, 'name': name, } expected_url = '/resource_providers' self.ks_adap_mock.post.assert_called_once_with( expected_url, json=expected_payload, microversion='1.20', endpoint_filter=mock.ANY, logger=mock.ANY, headers={'X-Openstack-Request-Id': self.context.global_id})
Example #15
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_get_one_by_uuid(self, mock_container_get_by_uuid, mock_container_show): test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_container_get_by_uuid.return_value = test_container_obj mock_container_show.return_value = test_container_obj response = self.get('/v1/containers/%s/' % test_container['uuid']) mock_container_get_by_uuid.assert_called_once_with( mock.ANY, test_container['uuid']) context = mock_container_get_by_uuid.call_args[0][0] self.assertIs(False, context.all_projects) self.assertEqual(200, response.status_int) self.assertEqual(test_container['uuid'], response.json['uuid']) self.assertNotIn('host', response.json)
Example #16
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_get_all_containers_all_projects(self, mock_container_list, mock_policy): mock_policy.return_value = True test_container = utils.get_test_container() containers = [objects.Container(self.context, **test_container)] mock_container_list.return_value = containers response = self.get('/v1/containers/?all_projects=1') mock_container_list.assert_called_once_with(mock.ANY, 1000, None, 'id', 'asc', filters={}) context = mock_container_list.call_args[0][0] self.assertIs(True, context.all_projects) self.assertEqual(200, response.status_int) actual_containers = response.json['containers'] self.assertEqual(1, len(actual_containers)) self.assertEqual(test_container['uuid'], actual_containers[0].get('uuid'))
Example #17
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def _action_test(self, test_container_obj, action, ident_field, mock_container_action, status_code, query_param=''): ident = test_container_obj.uuid get_by_ident_loc = 'zun.objects.Container.get_by_%s' % ident_field with patch(get_by_ident_loc) as mock_get_by_indent: mock_get_by_indent.return_value = test_container_obj response = self.post('/v1/containers/%s/%s/?%s' % (ident, action, query_param)) self.assertEqual(status_code, response.status_int) # Only PUT should work, others like GET should fail self.assertRaises(AppError, self.get, ('/v1/containers/%s/%s/' % (ident, action))) if query_param: value = query_param.split('=')[1] mock_container_action.assert_called_once_with( mock.ANY, test_container_obj, value) else: mock_container_action.assert_called_once_with( mock.ANY, test_container_obj)
Example #18
Source File: test_report.py From zun with Apache License 2.0 | 6 votes |
def test_get_providers_in_tree_error(self, logging_mock): # Ensure get_providers_in_tree() logs an error and raises if the # placement API call doesn't respond 200 resp_mock = mock.Mock(status_code=503) self.ks_adap_mock.get.return_value = resp_mock self.ks_adap_mock.get.return_value.headers = { 'x-openstack-request-id': 'req-' + uuids.request_id} uuid = uuids.compute_node self.assertRaises(exception.ResourceProviderRetrievalFailed, self.client.get_providers_in_tree, self.context, uuid) expected_url = '/resource_providers?in_tree=' + uuid self.ks_adap_mock.get.assert_called_once_with( expected_url, microversion='1.14', endpoint_filter=mock.ANY, logger=mock.ANY, headers={'X-Openstack-Request-Id': self.context.global_id}) # A 503 Service Unavailable should trigger an error log that includes # the placement request id self.assertTrue(logging_mock.called) self.assertEqual('req-' + uuids.request_id, logging_mock.call_args[0][1]['placement_req_id'])
Example #19
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_remove_security_group_by_uuid(self, mock_get_resource, mock_find_resourceid, mock_remove_security_group): headers = {"OpenStack-API-Version": "container 1.14"} test_container = utils.get_test_container( security_groups=['affb9021-964d-4b1b-80a8-9b9db60497e4']) test_container_obj = objects.Container(self.context, **test_container) mock_get_resource.return_value = test_container_obj mock_find_resourceid.return_value = \ test_container_obj.security_groups[0] container_name = test_container.get('name') security_group_id_to_remove = test_container_obj.security_groups[0] url = '/v1/containers/%s/%s?name=%s' % (container_name, 'remove_security_group', security_group_id_to_remove) response = self.post(url, headers=headers) self.assertEqual(202, response.status_int) self.assertEqual('application/json', response.content_type) mock_find_resourceid.assert_called_once_with( 'security_group', security_group_id_to_remove, mock.ANY) mock_remove_security_group.assert_called_once_with( mock.ANY, test_container_obj, test_container_obj.security_groups[0])
Example #20
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_delete_container_by_uuid_all_projects(self, mock_get_by_uuid, mock_container_delete, mock_validate, mock_policy): mock_policy.return_value = True test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_get_by_uuid.return_value = test_container_obj container_uuid = test_container.get('uuid') response = self.delete('/v1/containers/%s/?all_projects=1' % container_uuid) self.assertEqual(204, response.status_int) mock_container_delete.assert_called_once_with( mock.ANY, test_container_obj, False) context = mock_container_delete.call_args[0][0] self.assertIs(True, context.all_projects)
Example #21
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_kill_container_by_uuid(self, mock_get_by_uuid, mock_container_kill, mock_validate): test_container_obj = objects.Container(self.context, **utils.get_test_container()) mock_container_kill.return_value = test_container_obj test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_get_by_uuid.return_value = test_container_obj container_uuid = test_container.get('uuid') url = '/v1/containers/%s/%s/' % (container_uuid, 'kill') cmd = {'signal': '9'} response = self.post(url, cmd) self.assertEqual(202, response.status_int) mock_container_kill.assert_called_once_with( mock.ANY, test_container_obj, cmd['signal'])
Example #22
Source File: test_report.py From zun with Apache License 2.0 | 6 votes |
def test_get_resource_provider_error(self, logging_mock): # Ensure _get_resource_provider() sets the error flag when trying to # communicate with the placement API and not getting an error we can # deal with resp_mock = mock.Mock(status_code=503) self.ks_adap_mock.get.return_value = resp_mock self.ks_adap_mock.get.return_value.headers = { 'x-openstack-request-id': uuids.request_id} uuid = uuids.compute_node self.assertRaises( exception.ResourceProviderRetrievalFailed, self.client._get_resource_provider, self.context, uuid) expected_url = '/resource_providers/' + uuid self.ks_adap_mock.get.assert_called_once_with( expected_url, microversion='1.14', endpoint_filter=mock.ANY, logger=mock.ANY, headers={'X-Openstack-Request-Id': self.context.global_id}) # A 503 Service Unavailable should trigger an error log that # includes the placement request id and return None # from _get_resource_provider() self.assertTrue(logging_mock.called) self.assertEqual(uuids.request_id, logging_mock.call_args[0][1]['placement_req_id'])
Example #23
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_resize_by_uuid(self, mock_get_by_uuid, mock_container_resize, mock_validate): test_container_obj = objects.Container(self.context, **utils.get_test_container()) mock_container_resize.return_value = test_container_obj test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_get_by_uuid.return_value = test_container_obj container_name = test_container.get('name') url = '/v1/containers/%s/%s/' % (container_name, 'resize') cmd = {'h': '100', 'w': '100'} response = self.post(url, cmd) self.assertEqual(200, response.status_int) mock_container_resize.assert_called_once_with( mock.ANY, test_container_obj, cmd['h'], cmd['w'])
Example #24
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_resize_container(self, mock_get_by_uuid, mock_resize_container, mock_validate): test_container_obj = objects.Container(self.context, **utils.get_test_container()) mock_resize_container.return_value = test_container_obj test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_get_by_uuid.return_value = test_container_obj container_name = test_container.get('name') url = '/v1/containers/%s/resize_container/' % container_name params = {'cpu': 1, 'memory': '512'} response = self.post(url, params) self.assertEqual(202, response.status_int) mock_resize_container.assert_called_once_with( mock.ANY, test_container_obj, params)
Example #25
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_put_archive_by_uuid(self, mock_get_by_uuid, container_put_archive, mock_validate): container_put_archive.return_value = "" test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_get_by_uuid.return_value = test_container_obj container_uuid = test_container.get('uuid') url = '/v1/containers/%s/%s/' % (container_uuid, 'put_archive') cmd = {'path': '/home/', 'data': '/home/1.tar'} response = self.post(url, cmd) self.assertEqual(200, response.status_int) container_put_archive.assert_called_once_with( mock.ANY, test_container_obj, cmd['path'], cmd['data'], mock.ANY)
Example #26
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_commit_by_name(self, mock_get_by_name, mock_container_commit, mock_validate): test_container_obj = objects.Container(self.context, **utils.get_test_container()) test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_get_by_name.return_value = test_container_obj mock_container_commit.return_value = None container_name = test_container.get('name') url = '/v1/containers/%s/%s/' % (container_name, 'commit') cmd = {'repository': 'repo', 'tag': 'tag'} response = self.post(url, cmd) self.assertEqual(202, response.status_int) mock_container_commit.assert_called_once_with( mock.ANY, test_container_obj, cmd['repository'], cmd['tag'])
Example #27
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_commit_by_uuid(self, mock_get_by_uuid, mock_container_commit, mock_validate): test_container_obj = objects.Container(self.context, **utils.get_test_container()) test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_get_by_uuid.return_value = test_container_obj mock_container_commit.return_value = None container_uuid = test_container.get('uuid') url = '/v1/containers/%s/%s/' % (container_uuid, 'commit') cmd = {'repository': 'repo', 'tag': 'tag'} response = self.post(url, cmd) self.assertEqual(202, response.status_int) mock_container_commit.assert_called_once_with( mock.ANY, test_container_obj, cmd['repository'], cmd['tag'])
Example #28
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_execute_resize_container_exec( self, mock_get_resource, mock_exec_resize, mock_validate): test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_get_resource.return_value = test_container_obj mock_exec_resize.return_value = None container_name = test_container.get('name') url = '/v1/containers/%s/%s/' % (container_name, 'execute_resize') fake_exec_id = ('7df36611fa1fc855618c2c643835d41d' 'ac3fe568e7688f0bae66f7bcb3cccc6c') kwargs = {'exec_id': fake_exec_id, 'h': '100', 'w': '100'} response = self.post(url, kwargs) self.assertEqual(200, response.status_int) mock_exec_resize.assert_called_once_with( mock.ANY, test_container_obj, fake_exec_id, kwargs['h'], kwargs['w'])
Example #29
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_add_security_group_by_uuid(self, mock_get_resource, mock_find_resourceid, mock_add_security_group): headers = {"OpenStack-API-Version": "container 1.14"} test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_get_resource.return_value = test_container_obj mock_find_resourceid.return_value = 'fake_security_group_id' container_name = test_container.get('name') security_group_id_to_add = '5f7cf831-9a9c-4e2b-87b2-6081667f852b' url = '/v1/containers/%s/%s?name=%s' % (container_name, 'add_security_group', security_group_id_to_add) response = self.post(url, headers=headers) self.assertEqual(202, response.status_int) self.assertEqual('application/json', response.content_type) mock_find_resourceid.assert_called_once_with( 'security_group', security_group_id_to_add, mock.ANY) mock_add_security_group.assert_called_once_with( mock.ANY, test_container_obj, 'fake_security_group_id')
Example #30
Source File: test_containers.py From zun with Apache License 2.0 | 6 votes |
def test_network_detach_with_port(self, mock_by_uuid, mock_detach, mock_get_port): port_uuid = uuidutils.generate_uuid() network_uuid = uuidutils.generate_uuid() test_container = utils.get_test_container(port=port_uuid, network=network_uuid) test_container_obj = objects.Container(self.context, **test_container) mock_by_uuid.return_value = test_container_obj container_uuid = test_container.get('uuid') mock_get_port.return_value = {'network_id': network_uuid, 'id': port_uuid} mock_detach.return_value = None url = '/v1/containers/%s/%s?port=%s' % (container_uuid, 'network_detach', 'fake-port') response = self.post(url) self.assertEqual(202, response.status_int) mock_detach.assert_called_once_with(mock.ANY, test_container_obj, network_uuid)