blob: 05f9f3e652186781a7ae71fdd13ac37cbc464477 [file] [log] [blame]
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +00001# (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 Pittier00f25962016-03-18 17:10:07 +010018import mock
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000019from oslotest import mockpatch
20
21from tempest.common import negative_rest_client
22from tempest import config
Matthew Treinishffad78a2016-04-16 14:39:52 -040023from tempest.tests import base
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000024from tempest.tests import fake_config
Masayuki Igawa7cf41182016-09-12 14:19:58 +090025from tempest.tests.lib import fake_auth_provider
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000026
27
28class TestNegativeRestClient(base.TestCase):
29
30 url = 'fake_endpoint'
31
32 def setUp(self):
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000033 super(TestNegativeRestClient, self).setUp()
34 self.useFixture(fake_config.ConfigFixture())
Jordan Pittier0021c292016-03-29 21:33:34 +020035 self.patchobject(config, 'TempestConfigPrivate',
36 fake_config.FakePrivate)
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000037 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 Pittier00f25962016-03-18 17:10:07 +010042 @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 Ohmichi316fa462015-01-08 08:55:43 +000045 __, return_dict = self.negative_rest_client.send_request('POST',
46 self.url,
47 [], {})
Jordan Pittier00f25962016-03-18 17:10:07 +010048 mock_post.assert_called_once_with(self.url, {})
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000049
Jordan Pittier00f25962016-03-18 17:10:07 +010050 @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 Ohmichi316fa462015-01-08 08:55:43 +000053 __, return_dict = self.negative_rest_client.send_request('GET',
54 self.url,
55 [])
Jordan Pittier00f25962016-03-18 17:10:07 +010056 mock_get.assert_called_once_with(self.url)
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000057
Jordan Pittier00f25962016-03-18 17:10:07 +010058 @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 Ohmichi316fa462015-01-08 08:55:43 +000061 __, return_dict = self.negative_rest_client.send_request('DELETE',
62 self.url,
63 [])
Jordan Pittier00f25962016-03-18 17:10:07 +010064 mock_delete.assert_called_once_with(self.url)
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000065
Jordan Pittier00f25962016-03-18 17:10:07 +010066 @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 Ohmichi316fa462015-01-08 08:55:43 +000069 __, return_dict = self.negative_rest_client.send_request('PATCH',
70 self.url,
71 [], {})
Jordan Pittier00f25962016-03-18 17:10:07 +010072 mock_patch.assert_called_once_with(self.url, {})
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000073
Jordan Pittier00f25962016-03-18 17:10:07 +010074 @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 Ohmichi316fa462015-01-08 08:55:43 +000077 __, return_dict = self.negative_rest_client.send_request('PUT',
78 self.url,
79 [], {})
Jordan Pittier00f25962016-03-18 17:10:07 +010080 mock_put.assert_called_once_with(self.url, {})
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000081
Jordan Pittier00f25962016-03-18 17:10:07 +010082 @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 Ohmichi316fa462015-01-08 08:55:43 +000085 __, return_dict = self.negative_rest_client.send_request('HEAD',
86 self.url,
87 [])
Jordan Pittier00f25962016-03-18 17:10:07 +010088 mock_head.assert_called_once_with(self.url)
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000089
Jordan Pittier00f25962016-03-18 17:10:07 +010090 @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 Ohmichi316fa462015-01-08 08:55:43 +000093 __, return_dict = self.negative_rest_client.send_request('COPY',
94 self.url,
95 [])
Jordan Pittier00f25962016-03-18 17:10:07 +010096 mock_copy.assert_called_once_with(self.url)
Ken'ichi Ohmichi316fa462015-01-08 08:55:43 +000097
98 def test_other(self):
99 self.assertRaises(AssertionError,
100 self.negative_rest_client.send_request,
101 'OTHER', self.url, [])