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 | |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 18 | import mock |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 19 | from oslotest import mockpatch |
| 20 | |
| 21 | from tempest.common import negative_rest_client |
| 22 | from tempest import config |
Matthew Treinish | ffad78a | 2016-04-16 14:39:52 -0400 | [diff] [blame] | 23 | from tempest.tests import base |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 24 | from tempest.tests import fake_config |
Masayuki Igawa | 7cf4118 | 2016-09-12 14:19:58 +0900 | [diff] [blame] | 25 | from tempest.tests.lib import fake_auth_provider |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 26 | |
| 27 | |
| 28 | class TestNegativeRestClient(base.TestCase): |
| 29 | |
| 30 | url = 'fake_endpoint' |
| 31 | |
| 32 | def setUp(self): |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 33 | super(TestNegativeRestClient, self).setUp() |
| 34 | self.useFixture(fake_config.ConfigFixture()) |
Jordan Pittier | 0021c29 | 2016-03-29 21:33:34 +0200 | [diff] [blame] | 35 | self.patchobject(config, 'TempestConfigPrivate', |
| 36 | fake_config.FakePrivate) |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 37 | self.negative_rest_client = negative_rest_client.NegativeRestClient( |
| 38 | fake_auth_provider.FakeAuthProvider(), None) |
| 39 | self.useFixture(mockpatch.PatchObject(self.negative_rest_client, |
| 40 | '_log_request')) |
| 41 | |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 42 | @mock.patch('tempest.lib.common.rest_client.RestClient.post', |
| 43 | return_value=(mock.Mock(), mock.Mock())) |
| 44 | def test_post(self, mock_post): |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 45 | __, return_dict = self.negative_rest_client.send_request('POST', |
| 46 | self.url, |
| 47 | [], {}) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 48 | mock_post.assert_called_once_with(self.url, {}) |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 49 | |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 50 | @mock.patch('tempest.lib.common.rest_client.RestClient.get', |
| 51 | return_value=(mock.Mock(), mock.Mock())) |
| 52 | def test_get(self, mock_get): |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 53 | __, return_dict = self.negative_rest_client.send_request('GET', |
| 54 | self.url, |
| 55 | []) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 56 | mock_get.assert_called_once_with(self.url) |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 57 | |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 58 | @mock.patch('tempest.lib.common.rest_client.RestClient.delete', |
| 59 | return_value=(mock.Mock(), mock.Mock())) |
| 60 | def test_delete(self, mock_delete): |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 61 | __, return_dict = self.negative_rest_client.send_request('DELETE', |
| 62 | self.url, |
| 63 | []) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 64 | mock_delete.assert_called_once_with(self.url) |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 65 | |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 66 | @mock.patch('tempest.lib.common.rest_client.RestClient.patch', |
| 67 | return_value=(mock.Mock(), mock.Mock())) |
| 68 | def test_patch(self, mock_patch): |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 69 | __, return_dict = self.negative_rest_client.send_request('PATCH', |
| 70 | self.url, |
| 71 | [], {}) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 72 | mock_patch.assert_called_once_with(self.url, {}) |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 73 | |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 74 | @mock.patch('tempest.lib.common.rest_client.RestClient.put', |
| 75 | return_value=(mock.Mock(), mock.Mock())) |
| 76 | def test_put(self, mock_put): |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 77 | __, return_dict = self.negative_rest_client.send_request('PUT', |
| 78 | self.url, |
| 79 | [], {}) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 80 | mock_put.assert_called_once_with(self.url, {}) |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 81 | |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 82 | @mock.patch('tempest.lib.common.rest_client.RestClient.head', |
| 83 | return_value=(mock.Mock(), mock.Mock())) |
| 84 | def test_head(self, mock_head): |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 85 | __, return_dict = self.negative_rest_client.send_request('HEAD', |
| 86 | self.url, |
| 87 | []) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 88 | mock_head.assert_called_once_with(self.url) |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 89 | |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 90 | @mock.patch('tempest.lib.common.rest_client.RestClient.copy', |
| 91 | return_value=(mock.Mock(), mock.Mock())) |
| 92 | def test_copy(self, mock_copy): |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 93 | __, return_dict = self.negative_rest_client.send_request('COPY', |
| 94 | self.url, |
| 95 | []) |
Jordan Pittier | 00f2596 | 2016-03-18 17:10:07 +0100 | [diff] [blame] | 96 | mock_copy.assert_called_once_with(self.url) |
Ken'ichi Ohmichi | 316fa46 | 2015-01-08 08:55:43 +0000 | [diff] [blame] | 97 | |
| 98 | def test_other(self): |
| 99 | self.assertRaises(AssertionError, |
| 100 | self.negative_rest_client.send_request, |
| 101 | 'OTHER', self.url, []) |