Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 1 | # (c) 2015 Deutsche Telekom AG |
| 2 | # Copyright 2015 Red Hat, Inc. |
| 3 | # Copyright 2015 NEC Corporation |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | import httplib2 |
| 19 | from oslotest import mockpatch |
| 20 | |
| 21 | from tempest.common import negative_rest_client |
| 22 | from tempest import config |
| 23 | from tempest.tests import base |
| 24 | from tempest.tests import fake_auth_provider |
| 25 | from tempest.tests import fake_config |
| 26 | from tempest.tests import fake_http |
| 27 | |
| 28 | |
| 29 | class TestNegativeRestClient(base.TestCase): |
| 30 | |
| 31 | url = 'fake_endpoint' |
| 32 | |
| 33 | def setUp(self): |
| 34 | self.fake_http = fake_http.fake_httplib2() |
| 35 | super(TestNegativeRestClient, self).setUp() |
| 36 | self.useFixture(fake_config.ConfigFixture()) |
| 37 | self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate) |
| 38 | self.stubs.Set(httplib2.Http, 'request', self.fake_http.request) |
| 39 | self.negative_rest_client = negative_rest_client.NegativeRestClient( |
| 40 | fake_auth_provider.FakeAuthProvider(), None) |
| 41 | self.useFixture(mockpatch.PatchObject(self.negative_rest_client, |
| 42 | '_log_request')) |
| 43 | |
| 44 | def test_post(self): |
| 45 | __, return_dict = self.negative_rest_client.send_request('POST', |
| 46 | self.url, |
| 47 | [], {}) |
| 48 | self.assertEqual('POST', return_dict['method']) |
| 49 | |
| 50 | def test_get(self): |
| 51 | __, return_dict = self.negative_rest_client.send_request('GET', |
| 52 | self.url, |
| 53 | []) |
| 54 | self.assertEqual('GET', return_dict['method']) |
| 55 | |
| 56 | def test_delete(self): |
| 57 | __, return_dict = self.negative_rest_client.send_request('DELETE', |
| 58 | self.url, |
| 59 | []) |
| 60 | self.assertEqual('DELETE', return_dict['method']) |
| 61 | |
| 62 | def test_patch(self): |
| 63 | __, return_dict = self.negative_rest_client.send_request('PATCH', |
| 64 | self.url, |
| 65 | [], {}) |
| 66 | self.assertEqual('PATCH', return_dict['method']) |
| 67 | |
| 68 | def test_put(self): |
| 69 | __, return_dict = self.negative_rest_client.send_request('PUT', |
| 70 | self.url, |
| 71 | [], {}) |
| 72 | self.assertEqual('PUT', return_dict['method']) |
| 73 | |
| 74 | def test_head(self): |
| 75 | self.useFixture(mockpatch.PatchObject(self.negative_rest_client, |
| 76 | 'response_checker')) |
| 77 | __, return_dict = self.negative_rest_client.send_request('HEAD', |
| 78 | self.url, |
| 79 | []) |
| 80 | self.assertEqual('HEAD', return_dict['method']) |
| 81 | |
| 82 | def test_copy(self): |
| 83 | __, return_dict = self.negative_rest_client.send_request('COPY', |
| 84 | self.url, |
| 85 | []) |
| 86 | self.assertEqual('COPY', return_dict['method']) |
| 87 | |
| 88 | def test_other(self): |
| 89 | self.assertRaises(AssertionError, |
| 90 | self.negative_rest_client.send_request, |
| 91 | 'OTHER', self.url, []) |