/
usr
/
lib
/
python2.6
/
site-packages
/
neutronclient
/
tests
/
unit
/
/usr/lib/python2.6/site-packages/neutronclient/tests/unit
mkdir
upload
Name
Size
Mode
Actions
fw/
-
0755
rm
lb/
-
0755
rm
qos/
-
0755
rm
vpn/
-
0755
rm
test_auth.py
15714
0644
edit
dl
rm
test_auth.pyc
14626
0644
edit
dl
rm
test_casual_args.py
4993
0644
edit
dl
rm
test_casual_args.pyc
6781
0644
edit
dl
rm
test_cli20.py
31706
0644
edit
dl
rm
test_cli20.pyc
29553
0644
edit
dl
rm
test_cli20_address_scope.py
6024
0644
edit
dl
rm
test_cli20_address_scope.pyc
6576
0644
edit
dl
rm
test_cli20_agents.py
3052
0644
edit
dl
rm
test_cli20_agents.pyc
3543
0644
edit
dl
rm
test_cli20_agentschedulers.py
8631
0644
edit
dl
rm
test_cli20_agentschedulers.pyc
10044
0644
edit
dl
rm
test_cli20_credential.py
3301
0644
edit
dl
rm
test_cli20_credential.pyc
3684
0644
edit
dl
rm
test_cli20_extensions.py
1945
0644
edit
dl
rm
test_cli20_extensions.pyc
1834
0644
edit
dl
rm
test_cli20_floatingips.py
6258
0755
edit
dl
rm
test_cli20_floatingips.pyc
6875
0644
edit
dl
rm
test_cli20_metering.py
3974
0644
edit
dl
rm
test_cli20_metering.pyc
4670
0644
edit
dl
rm
test_cli20_network.py
26443
0644
edit
dl
rm
test_cli20_network.pyc
27226
0644
edit
dl
rm
test_cli20_networkprofile.py
6186
0644
edit
dl
rm
test_cli20_networkprofile.pyc
6011
0644
edit
dl
rm
test_cli20_nsx_networkgateway.py
11974
0644
edit
dl
rm
test_cli20_nsx_networkgateway.pyc
12566
0644
edit
dl
rm
test_cli20_nsx_queue.py
3124
0755
edit
dl
rm
test_cli20_nsx_queue.pyc
3714
0644
edit
dl
rm
test_cli20_nuage_netpartition.py
2252
0644
edit
dl
rm
test_cli20_nuage_netpartition.pyc
2732
0644
edit
dl
rm
test_cli20_policyprofile.py
3299
0644
edit
dl
rm
test_cli20_policyprofile.pyc
3305
0644
edit
dl
rm
test_cli20_port.py
26748
0644
edit
dl
rm
test_cli20_port.pyc
25239
0644
edit
dl
rm
test_cli20_rbac.py
5239
0644
edit
dl
rm
test_cli20_rbac.pyc
5633
0644
edit
dl
rm
test_cli20_router.py
14364
0644
edit
dl
rm
test_cli20_router.pyc
15580
0644
edit
dl
rm
test_cli20_securitygroup.py
27847
0755
edit
dl
rm
test_cli20_securitygroup.pyc
27420
0644
edit
dl
rm
test_cli20_servicetype.py
2268
0644
edit
dl
rm
test_cli20_servicetype.pyc
2768
0644
edit
dl
rm
test_cli20_subnet.py
30402
0644
edit
dl
rm
test_cli20_subnet.pyc
28179
0644
edit
dl
rm
test_cli20_subnetpool.py
7603
0644
edit
dl
rm
test_cli20_subnetpool.pyc
8094
0644
edit
dl
rm
test_client_extension.py
9253
0644
edit
dl
rm
test_client_extension.pyc
12179
0644
edit
dl
rm
test_command_meta.py
1496
0644
edit
dl
rm
test_command_meta.pyc
1848
0644
edit
dl
rm
test_http.py
4261
0644
edit
dl
rm
test_http.pyc
6393
0644
edit
dl
rm
test_name_or_id.py
8241
0644
edit
dl
rm
test_name_or_id.pyc
7399
0644
edit
dl
rm
test_quota.py
1680
0755
edit
dl
rm
test_quota.pyc
1951
0644
edit
dl
rm
test_shell.py
20714
0644
edit
dl
rm
test_shell.pyc
18083
0644
edit
dl
rm
test_ssl.py
6303
0644
edit
dl
rm
test_ssl.pyc
5229
0644
edit
dl
rm
test_utils.py
4368
0644
edit
dl
rm
test_utils.pyc
7650
0644
edit
dl
rm
test_validators.py
4101
0644
edit
dl
rm
test_validators.pyc
4238
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
__init__.pyc
166
0644
edit
dl
rm
Edit:
/usr/lib/python2.6/site-packages/neutronclient/tests/unit/test_http.py
(4261B)
# Copyright (C) 2013 OpenStack Foundation. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import abc from requests_mock.contrib import fixture as mock_fixture import six import testtools from neutronclient import client from neutronclient.common import exceptions from neutronclient.tests.unit import test_auth AUTH_TOKEN = 'test_token' END_URL = 'test_url' METHOD = 'GET' URL = 'http://test.test:1234/v2.0/test' BODY = 'IAMFAKE' @six.add_metaclass(abc.ABCMeta) class TestHTTPClientMixin(object): def setUp(self): super(TestHTTPClientMixin, self).setUp() self.requests = self.useFixture(mock_fixture.Fixture()) self.clazz, self.http = self.initialize() @abc.abstractmethod def initialize(self): """Return client class, instance.""" def _test_headers(self, expected_headers, **kwargs): """Test headers.""" self.requests.register_uri(METHOD, URL, request_headers=expected_headers) self.http.request(URL, METHOD, **kwargs) self.assertEqual(kwargs.get('body'), self.requests.last_request.body) def test_headers_without_body(self): self._test_headers({'Accept': 'application/json'}) def test_headers_with_body(self): headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} self._test_headers(headers, body=BODY) def test_headers_without_body_with_content_type(self): headers = {'Accept': 'application/xml'} self._test_headers(headers, content_type='application/xml') def test_headers_with_body_with_content_type(self): headers = {'Accept': 'application/xml', 'Content-Type': 'application/xml'} self._test_headers(headers, body=BODY, content_type='application/xml') def test_headers_defined_in_headers(self): headers = {'Accept': 'application/xml', 'Content-Type': 'application/xml'} self._test_headers(headers, body=BODY, headers=headers) class TestSessionClient(TestHTTPClientMixin, testtools.TestCase): def initialize(self): session, auth = test_auth.setup_keystone_v2(self.requests) return [client.SessionClient, client.SessionClient(session=session, auth=auth)] class TestHTTPClient(TestHTTPClientMixin, testtools.TestCase): def initialize(self): return [client.HTTPClient, client.HTTPClient(token=AUTH_TOKEN, endpoint_url=END_URL)] def test_request_error(self): def cb(*args, **kwargs): raise Exception('error msg') self.requests.get(URL, body=cb) self.assertRaises( exceptions.ConnectionFailed, self.http._cs_request, URL, METHOD ) def test_request_success(self): text = 'test content' self.requests.register_uri(METHOD, URL, text=text) resp, resp_text = self.http._cs_request(URL, METHOD) self.assertEqual(200, resp.status_code) self.assertEqual(text, resp_text) def test_request_unauthorized(self): text = 'unauthorized message' self.requests.register_uri(METHOD, URL, status_code=401, text=text) e = self.assertRaises(exceptions.Unauthorized, self.http._cs_request, URL, METHOD) self.assertEqual(text, e.message) def test_request_forbidden_is_returned_to_caller(self): text = 'forbidden message' self.requests.register_uri(METHOD, URL, status_code=403, text=text) resp, resp_text = self.http._cs_request(URL, METHOD) self.assertEqual(403, resp.status_code) self.assertEqual(text, resp_text)
Save
cmd:
run