def test_get_version_list_302(self): req = webob.Request.blank('/v2') req.accept = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 302) redirect_req = webob.Request.blank('/v2/') self.assertEqual(res.location, redirect_req.url)
def test_create_root_volume_bdm_v2(self): body = dict(server=dict( name='test_server', imageRef=IMAGE_UUID, flavorRef=2, min_count=1, max_count=1, block_device_mapping_v2=[dict( source_type='volume', uuid='1', device_name='/dev/vda', boot_index=0, delete_on_termination=False, )] )) req = fakes.HTTPRequest.blank('/v2/fake/os-volumes_boot') req.method = 'POST' req.body = jsonutils.dump_as_bytes(body) req.headers['content-type'] = 'application/json' res = req.get_response(fakes.wsgi_app( init_only=('os-volumes_boot', 'servers'))) self.assertEqual(202, res.status_int) server = jsonutils.loads(res.body)['server'] self.assertEqual(FAKE_UUID, server['id']) self.assertEqual(CONF.password_length, len(server['adminPass'])) self.assertEqual(1, len(self._block_device_mapping_seen)) self.assertFalse(self._legacy_bdm_seen) self.assertEqual('1', self._block_device_mapping_seen[0]['volume_id']) self.assertEqual(0, self._block_device_mapping_seen[0]['boot_index']) self.assertEqual('/dev/vda', self._block_device_mapping_seen[0]['device_name'])
def test_get_version_list(self): req = webob.Request.blank('/') req.accept = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/json") versions = jsonutils.loads(res.body)["versions"] expected = [ { "id": "v2.0", "status": "CURRENT", "updated": "2011-01-21T11:33:21Z", "links": [ { "rel": "self", "href": "http://localhost/v2/", }], }, { "id": "v2.1", "status": "EXPERIMENTAL", "updated": "2013-07-23T11:33:21Z", "links": [ { "rel": "self", "href": "http://localhost/v2/", }], }, ] self.assertEqual(versions, expected)
def test_create_root_volume(self): body = dict(server=dict( name='test_server', imageRef=IMAGE_UUID, flavorRef=2, min_count=1, max_count=1, block_device_mapping=[dict( volume_id='1', device_name='/dev/vda', virtual='root', delete_on_termination=False, )] )) req = webob.Request.blank('/v2/fake/os-volumes_boot') req.method = 'POST' req.body = jsonutils.dumps(body) req.headers['content-type'] = 'application/json' res = req.get_response(fakes.wsgi_app( init_only=('os-volumes_boot', 'servers'))) self.assertEqual(res.status_int, 202) server = jsonutils.loads(res.body)['server'] self.assertEqual(FAKE_UUID, server['id']) self.assertEqual(CONF.password_length, len(server['adminPass'])) self.assertEqual(len(self._block_device_mapping_seen), 1) self.assertTrue(self._legacy_bdm_seen) self.assertEqual(self._block_device_mapping_seen[0]['volume_id'], '1') self.assertEqual(self._block_device_mapping_seen[0]['device_name'], '/dev/vda')
def _get_wsgi_app(self, context): self.flags(osapi_compute_extension=[ 'nova.api.openstack.compute.contrib.select_extensions' ], osapi_compute_ext_list=['Simple_tenant_usage']) return fakes.wsgi_app(fake_auth_context=context, init_only=('os-simple-tenant-usage', ))
def _make_request(self, url, method='GET'): req = webob.Request.blank(url) req.headers['Accept'] = self.content_type req.method = method res = req.get_response( fakes.wsgi_app(init_only=('servers', 'os-server-password'))) return res
def test_get_version_list(self): req = webob.Request.blank('/') req.accept = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/json") versions = jsonutils.loads(res.body)["versions"] expected = [ { "id": "v2.0", "status": "SUPPORTED", "version": "", "min_version": "", "updated": "2011-01-21T11:33:21Z", "links": [{ "rel": "self", "href": "http://localhost/v2/", }], }, { "id": "v2.1", "status": "CURRENT", "version": "2.3", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z", "links": [{ "rel": "self", "href": "http://localhost/v2.1/", }], }, ] self.assertEqual(versions, expected)
def test_multi_choice_image(self): req = webob.Request.blank('/images/1') req.accept = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 300) self.assertEqual(res.content_type, "application/json") expected = { "choices": [ { "id": "v2.0", "status": "CURRENT", "links": [ { "href": "http://localhost/v2/images/1", "rel": "self", }, ], "media-types": [ { "base": "application/xml", "type": "application/vnd.openstack.compute+xml" ";version=2" }, { "base": "application/json", "type": "application/vnd.openstack.compute+json" ";version=2" }, ], }, { "id": "v2.1", "status": "EXPERIMENTAL", "links": [ { "href": "http://localhost/v2/images/1", "rel": "self", }, ], "media-types": [{ "base": "application/json", "type": "application/vnd.openstack.compute+json;version=2.1", }], }, ], } self.assertThat(jsonutils.loads(res.body), matchers.DictMatches(expected))
def test_get_version_2_detail_atom(self): req = webob.Request.blank('/v2/') req.accept = "application/atom+xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) self.assertEqual("application/atom+xml", res.content_type) xmlutil.validate_schema(etree.XML(res.body), 'atom') f = feedparser.parse(res.body) self.assertEqual(f.feed.title, 'About This Version') self.assertEqual(f.feed.updated, '2011-01-21T11:33:21Z') self.assertEqual(f.feed.id, 'http://localhost/v2/') self.assertEqual(f.feed.author, 'Rackspace') self.assertEqual(f.feed.author_detail.href, 'http://www.rackspace.com/') self.assertEqual(f.feed.links[0]['href'], 'http://localhost/v2/') self.assertEqual(f.feed.links[0]['rel'], 'self') self.assertEqual(len(f.entries), 1) entry = f.entries[0] self.assertEqual(entry.id, 'http://localhost/v2/') self.assertEqual(entry.title, 'Version v2.0') self.assertEqual(entry.updated, '2011-01-21T11:33:21Z') self.assertEqual(len(entry.content), 1) self.assertEqual(entry.content[0].value, 'Version v2.0 CURRENT (2011-01-21T11:33:21Z)') self.assertEqual(len(entry.links), 2) self.assertEqual(entry.links[0]['href'], 'http://localhost/v2/') self.assertEqual(entry.links[0]['rel'], 'self') self.assertEqual(entry.links[1], { 'href': EXP_LINKS['v2.0']['html'], 'type': 'text/html', 'rel': 'describedby'})
def test_get_version_list_xml(self): req = webob.Request.blank('/') req.accept = "application/xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/xml") root = etree.XML(res.body) xmlutil.validate_schema(root, 'versions') self.assertTrue(root.xpath('/ns:versions', namespaces=NS)) versions = root.xpath('ns:version', namespaces=NS) self.assertEqual(len(versions), 2) for i, v in enumerate(['v2.0', 'v2.1']): version = versions[i] expected = EXP_VERSIONS[v] for key in ['id', 'status', 'updated']: self.assertEqual(version.get(key), expected[key]) (link, ) = version.xpath('atom:link', namespaces=NS) self.assertTrue( common.compare_links(link, [{ 'rel': 'self', 'href': 'http://localhost/%s/' % v }]))
def test_create_root_volume_bdm_v2(self): body = dict( server=dict( name="test_server", imageRef=IMAGE_UUID, flavorRef=2, min_count=1, max_count=1, block_device_mapping_v2=[ dict( source_type="volume", uuid="1", device_name="/dev/vda", boot_index=0, delete_on_termination=False, ) ], ) ) req = fakes.HTTPRequest.blank("/v2/fake/os-volumes_boot") req.method = "POST" req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app(init_only=("os-volumes_boot", "servers"))) self.assertEqual(res.status_int, 202) server = jsonutils.loads(res.body)["server"] self.assertEqual(FAKE_UUID, server["id"]) self.assertEqual(CONF.password_length, len(server["adminPass"])) self.assertEqual(len(self._block_device_mapping_seen), 1) self.assertFalse(self._legacy_bdm_seen) self.assertEqual(self._block_device_mapping_seen[0]["volume_id"], "1") self.assertEqual(self._block_device_mapping_seen[0]["boot_index"], 0) self.assertEqual(self._block_device_mapping_seen[0]["device_name"], "/dev/vda")
def _make_request(self, url): req = webob.Request.blank(url) req.headers['Accept'] = self.content_type res = req.get_response( fakes.wsgi_app(init_only=('os-virtual-interfaces', 'OS-EXT-VIF-NET'))) return res
def _get_wsgi_app(self, context): self.flags( osapi_compute_extension=[ 'nova.api.openstack.compute.contrib.select_extensions'], osapi_compute_ext_list=['Simple_tenant_usage']) return fakes.wsgi_app(fake_auth_context=context, init_only=('os-simple-tenant-usage', ))
def test_create_root_volume_bdm_v2(self): body = dict(server=dict(name='test_server', imageRef=IMAGE_UUID, flavorRef=2, min_count=1, max_count=1, block_device_mapping_v2=[ dict( source_type='volume', uuid='1', device_name='/dev/vda', boot_index=0, delete_on_termination=False, ) ])) req = fakes.HTTPRequest.blank('/v2/fake/os-volumes_boot') req.method = 'POST' req.body = jsonutils.dumps(body) req.headers['content-type'] = 'application/json' res = req.get_response( fakes.wsgi_app(init_only=('os-volumes_boot', 'servers'))) self.assertEqual(res.status_int, 202) server = jsonutils.loads(res.body)['server'] self.assertEqual(FAKE_UUID, server['id']) self.assertEqual(CONF.password_length, len(server['adminPass'])) self.assertEqual(len(self._block_device_mapping_seen), 1) self.assertFalse(self._legacy_bdm_seen) self.assertEqual(self._block_device_mapping_seen[0]['volume_id'], '1') self.assertEqual(self._block_device_mapping_seen[0]['boot_index'], 0) self.assertEqual(self._block_device_mapping_seen[0]['device_name'], '/dev/vda')
def test_versions_without_headers(self): req = wsgi.Request.blank('/') req.accept = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) href = _get_self_href(res) self.assertTrue(href.startswith('http://'))
def _test_get_version_2_detail(self, url, accept=None): if accept is None: accept = "application/json" req = webob.Request.blank(url) req.accept = accept res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/json") version = jsonutils.loads(res.body) expected = { "version": { "id": "v2.0", "status": "CURRENT", "updated": "2011-01-21T11:33:21Z", "links": [ { "rel": "self", "href": "http://localhost/v2/", }, { "rel": "describedby", "type": "text/html", "href": EXP_LINKS['v2.0']['html'], }, ], "media-types": [ { "base": "application/json", "type": "application/" "vnd.openstack.compute+json;version=2", }, ], }, } self.assertEqual(expected, version)
def test_malformed_xml(self): req = webob.Request.blank('/') req.method = 'POST' req.body = '<hi im not xml>' req.headers["content-type"] = "application/xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400)
def test_versions_with_header(self): req = wsgi.Request.blank("/") req.accept = "application/json" req.headers["X-Forwarded-Proto"] = "https" res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) href = _get_self_href(res) self.assertTrue(href.startswith("https://"))
def test_create_instance_with_network_no_id(self): body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]]) del body_dict['server']['networks'][0]['uuid'] request = self._get_create_request_json(body_dict) response = request.get_response(fakes.wsgi_app( init_only=('servers', 'os-create-server-ext'))) self.assertEqual(response.status_int, 400) self.assertIsNone(self.networks)
def test_malformed_json(self): req = webob.Request.blank("/") req.method = "POST" req.body = "{" req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400)
def _set_up_wsgi_app(self): self.flags(osapi_compute_extension=[ 'nova.api.openstack.compute.contrib.select_extensions' ], osapi_compute_ext_list=['Console_auth_tokens']) self.app = fakes.wsgi_app(init_only=('os-console-auth-tokens', ), fake_auth_context=self._get_admin_context())
def test_create_instance_with_network_no_id(self): body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]]) del body_dict['server']['networks'][0]['uuid'] request = self._get_create_request_json(body_dict) response = request.get_response( fakes.wsgi_app(init_only=('servers', 'os-create-server-ext'))) self.assertEqual(response.status_int, 400) self.assertIsNone(self.networks)
def _set_up_wsgi_app(self): self.flags( osapi_compute_extension=[ 'nova.api.openstack.compute.contrib.select_extensions'], osapi_compute_ext_list=['Console_auth_tokens']) self.app = fakes.wsgi_app(init_only=('os-console-auth-tokens',), fake_auth_context=self._get_admin_context())
def test_create_instance_with_network_no_fixed_ip(self): body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]]) del body_dict['server']['networks'][0]['fixed_ip'] request = self._get_create_request_json(body_dict) response = request.get_response(fakes.wsgi_app( init_only=('servers', 'os-create-server-ext'))) self.assertEqual(response.status_int, 202) self.assertEqual([('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', None)], self.networks.as_tuples())
def test_create_instance_with_network_no_id_xml(self): body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]]) request = self._get_create_request_xml(body_dict) uuid = ' uuid="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"' request.body = request.body.replace(uuid, '') response = request.get_response( fakes.wsgi_app(init_only=('servers', 'os-create-server-ext'))) self.assertEqual(response.status_int, 400) self.assertIsNone(self.networks)
def test_get_version_list_with_body(self): req = webob.Request.blank('/') req.accept = "application/json" req.method = 'POST' req.content_type = "application/json" req.body = "{\"foo\": \"bar\"}" res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) self.assertEqual("application/json", res.content_type)
def test_authorize_user(self): req = webob.Request.blank('/v2') req.headers['X-Auth-User'] = '******' req.headers['X-Auth-Key'] = 'user1_key' req.headers['X-Auth-Project-Id'] = 'user1_project' result = req.get_response(fakes.wsgi_app(use_no_auth=True)) self.assertEqual(result.status, '204 No Content') self.assertEqual(result.headers['X-Server-Management-Url'], "http://localhost/v2/user1_project")
def test_path_version_v2(self): # Test URL path specifying v2 returns v2 content. req = webob.Request.blank('/v2/') req.accept = "application/json" res = req.get_response(fakes.wsgi_app(init_only=('versions',))) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/json") body = jsonutils.loads(res.body) self.assertEqual(body['version']['id'], 'v2.0')
def test_create_instance_with_network_no_id_xml(self): body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]]) request = self._get_create_request_xml(body_dict) uuid = ' uuid="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"' request.body = request.body.replace(uuid, '') response = request.get_response(fakes.wsgi_app( init_only=('servers', 'os-create-server-ext'))) self.assertEqual(response.status_int, 400) self.assertIsNone(self.networks)
def test_auth_token_no_empty_headers(self): req = webob.Request.blank('/v2') req.headers['X-Auth-User'] = '******' req.headers['X-Auth-Key'] = 'user1_key' req.headers['X-Auth-Project-Id'] = 'user1_project' result = req.get_response(fakes.wsgi_app(use_no_auth=True)) self.assertEqual(result.status, '204 No Content') self.assertNotIn('X-CDN-Management-Url', result.headers) self.assertNotIn('X-Storage-Url', result.headers)
def test_create_instance_with_network_no_fixed_ip_xml(self): body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]]) request = self._get_create_request_xml(body_dict) request.body = request.body.replace(' fixed_ip="10.0.1.12"', '') response = request.get_response(fakes.wsgi_app( init_only=('servers', 'os-create-server-ext'))) self.assertEqual(response.status_int, 202) self.assertEqual([('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', None)], self.networks.as_tuples())
def test_path_version_v2(self): # Test URL path specifying v2 returns v2 content. req = webob.Request.blank('/v2/') req.accept = "application/json" res = req.get_response(fakes.wsgi_app(init_only=('versions', ))) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/json") body = jsonutils.loads(res.body) self.assertEqual(body['version']['id'], 'v2.0')
def test_create_instance_with_network_no_fixed_ip_xml(self): body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]]) request = self._get_create_request_xml(body_dict) request.body = request.body.replace(' fixed_ip="10.0.1.12"', '') response = request.get_response( fakes.wsgi_app(init_only=('servers', 'os-create-server-ext'))) self.assertEqual(response.status_int, 202) self.assertEqual([('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', None)], self.networks.as_tuples())
def test_create_instance_with_network_no_fixed_ip(self): body_dict = self._create_networks_request_dict([FAKE_NETWORKS[0]]) del body_dict['server']['networks'][0]['fixed_ip'] request = self._get_create_request_json(body_dict) response = request.get_response( fakes.wsgi_app(init_only=('servers', 'os-create-server-ext'))) self.assertEqual(response.status_int, 202) self.assertEqual([('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', None)], self.networks.as_tuples())
def test_multi_choice_server_atom(self): """Make sure multi choice responses do not have content-type application/atom+xml (should use default of json) """ req = webob.Request.blank('/servers') req.accept = "application/atom+xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 300) self.assertEqual(res.content_type, "application/json")
def test_accept_version_v2(self): # Test Accept header specifying v2 returns v2 content. req = webob.Request.blank('/') req.accept = "application/json;version=2" res = req.get_response(fakes.wsgi_app(init_only=('versions', ))) self.assertEqual(200, res.status_int) self.assertEqual("application/json", res.content_type) body = jsonutils.loads(res.body) self.assertEqual('v2.0', body['version']['id'])
def _make_request(self, url, body=None): req = webob.Request.blank(url) if body: req.method = "POST" req.body = self._encode_body(body) req.content_type = self.content_type req.headers["Accept"] = self.content_type res = req.get_response(fakes.wsgi_app(init_only=("servers",))) return res
def _make_request(self, url, body=None): req = webob.Request.blank(url) if body: req.method = 'POST' req.body = self._encode_body(body) req.content_type = self.content_type req.headers['Accept'] = self.content_type res = req.get_response(fakes.wsgi_app(init_only=('servers', ))) return res
def _make_request(self, url, body=None): req = webob.Request.blank(url) if body: req.method = 'POST' req.body = encodeutils.safe_encode(self._encode_body(body)) req.content_type = self.content_type req.headers['Accept'] = self.content_type res = req.get_response(fakes.wsgi_app(init_only=('servers',))) return res
def test_accept_version_v2(self): # Test Accept header specifying v2 returns v2 content. req = webob.Request.blank('/') req.accept = "application/json;version=2" res = req.get_response(fakes.wsgi_app(init_only=('versions',))) self.assertEqual(200, res.status_int) self.assertEqual("application/json", res.content_type) body = jsonutils.loads(res.body) self.assertEqual('v2.0', body['version']['id'])
def test_authorize_user_trailing_slash(self): # make sure it works with trailing slash on the request req = webob.Request.blank('/v2/') req.headers['X-Auth-User'] = '******' req.headers['X-Auth-Key'] = 'user1_key' req.headers['X-Auth-Project-Id'] = 'user1_project' result = req.get_response(fakes.wsgi_app(use_no_auth=True)) self.assertEqual('204 No Content', result.status) self.assertEqual("http://localhost/v2/user1_project", result.headers['X-Server-Management-Url'])
def test_get_resources_with_mgr(self): app = fakes.wsgi_app(init_only=('flavors',)) request = webob.Request.blank("/v2/fake/flavors/1?chewing=newblue") request.environ['api.version'] = '2' response = request.get_response(app) self.assertEqual(200, response.status_int) response_data = jsonutils.loads(response.body) self.assertEqual('newblue', response_data['flavor']['googoose']) self.assertEqual("Pig Bands!", response_data['big_bands'])
def test_get_resources_with_mgr(self): app = fakes.wsgi_app(init_only=("flavors",)) request = webob.Request.blank("/v2/fake/flavors/1?chewing=newblue") request.environ["api.version"] = "2" response = request.get_response(app) self.assertEqual(200, response.status_int) response_data = jsonutils.loads(response.body) self.assertEqual("newblue", response_data["flavor"]["googoose"]) self.assertEqual("Pig Bands!", response_data["big_bands"])
def test_vendor_content_type_xml(self): ctype = 'application/vnd.openstack.compute+xml' req = webob.Request.blank('/') req.headers['Accept'] = ctype res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, ctype) etree.XML(res.body)
def test_path_content_type(self): # Test URL path specifying JSON returns JSON content. url = '/v2/fake/images/cedef40a-ed67-4d10-800e-17455edce175.json' req = webob.Request.blank(url) req.accept = "application/xml" res = req.get_response(fakes.wsgi_app(init_only=('images', ))) self.assertEqual(res.status_int, 200) self.assertEqual(res.content_type, "application/json") body = jsonutils.loads(res.body) self.assertEqual(body['image']['id'], 'cedef40a-ed67-4d10-800e-17455edce175')
def test_multi_choice_server(self): uuid = str(stdlib_uuid.uuid4()) req = webob.Request.blank('/servers/' + uuid) req.accept = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 300) self.assertEqual(res.content_type, "application/json") expected = { "choices": [ { "id": "v2.0", "status": "SUPPORTED", "links": [ { "href": "http://localhost/v2/servers/" + uuid, "rel": "self", }, ], "media-types": [ { "base": "application/json", "type": "application/vnd.openstack.compute+json" ";version=2" }, ], }, { "id": "v2.1", "status": "CURRENT", "links": [ { "href": "http://localhost/v2.1/servers/" + uuid, "rel": "self", }, ], "media-types": [{ "base": "application/json", "type": "application/vnd.openstack.compute+json;version=2.1", }], }, ], } self.assertThat(jsonutils.loads(res.body), matchers.DictMatches(expected))
def test_accept_content_type(self): # Test Accept header specifying JSON returns JSON content. url = '/v2/fake/images/cedef40a-ed67-4d10-800e-17455edce175' req = webob.Request.blank(url) req.accept = "application/xml;q=0.8, application/json" res = req.get_response(fakes.wsgi_app(init_only=('images', ))) self.assertEqual(200, res.status_int) self.assertEqual("application/json", res.content_type) body = jsonutils.loads(res.body) self.assertEqual('cedef40a-ed67-4d10-800e-17455edce175', body['image']['id'])
def test_get_server_by_id_verify_security_groups_json(self): self.stubs.Set(db, 'instance_get', fakes.fake_instance_get()) self.stubs.Set(db, 'instance_get_by_uuid', fakes.fake_instance_get()) req = webob.Request.blank('/v2/fake/os-create-server-ext/1') req.headers['Content-Type'] = 'application/json' response = req.get_response( fakes.wsgi_app(init_only=('os-create-server-ext', 'servers'))) self.assertEqual(response.status_int, 200) res_dict = jsonutils.loads(response.body) expected_security_group = [{"name": "test"}] self.assertEqual(res_dict['server'].get('security_groups'), expected_security_group)
def test_create_instance_with_security_group_json(self): security_groups = ['test', 'test1'] self.stub_out('nova.db.security_group_get_by_name', return_security_group_get_by_name) self.stub_out('nova.db.instance_add_security_group', return_instance_add_security_group) body_dict = self._create_security_group_request_dict(security_groups) request = self._get_create_request_json(body_dict) response = request.get_response( fakes.wsgi_app(init_only=('servers', 'os-create-server-ext'))) self.assertEqual(response.status_int, 202) self.assertJsonEqual(self.security_group, security_groups)