Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 1 | # Copyright (c) 2014 Rackspace, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 12 | # implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | import logging |
| 17 | |
| 18 | from tempest.api.queuing import base |
| 19 | from tempest.common.utils import data_utils |
| 20 | from tempest import config |
| 21 | from tempest import test |
| 22 | |
| 23 | |
| 24 | LOG = logging.getLogger(__name__) |
| 25 | CONF = config.CONF |
| 26 | |
| 27 | |
| 28 | class TestMessages(base.BaseQueuingTest): |
| 29 | _interface = 'json' |
| 30 | |
| 31 | @classmethod |
| 32 | def setUpClass(cls): |
| 33 | super(TestMessages, cls).setUpClass() |
| 34 | cls.queue_name = data_utils.rand_name('Queues-Test') |
| 35 | # Create Queue |
| 36 | cls.client.create_queue(cls.queue_name) |
| 37 | |
| 38 | def _post_messages(self, repeat=CONF.queuing.max_messages_per_page): |
| 39 | message_body = self.generate_message_body(repeat=repeat) |
| 40 | resp, body = self.post_messages(queue_name=self.queue_name, |
| 41 | rbody=message_body) |
| 42 | return resp, body |
| 43 | |
| 44 | @test.attr(type='smoke') |
| 45 | def test_post_messages(self): |
| 46 | # Post Messages |
| 47 | resp, _ = self._post_messages() |
| 48 | |
| 49 | # Get on the posted messages |
| 50 | message_uri = resp['location'] |
| 51 | resp, _ = self.client.get_multiple_messages(message_uri) |
| 52 | # The test has an assertion here, because the response cannot be 204 |
| 53 | # in this case (the client allows 200 or 204 for this API call). |
| 54 | self.assertEqual('200', resp['status']) |
| 55 | |
| 56 | @test.attr(type='smoke') |
| 57 | def test_list_messages(self): |
| 58 | # Post Messages |
| 59 | self._post_messages() |
| 60 | |
| 61 | # List Messages |
| 62 | resp, _ = self.list_messages(queue_name=self.queue_name) |
| 63 | # The test has an assertion here, because the response cannot be 204 |
| 64 | # in this case (the client allows 200 or 204 for this API call). |
| 65 | self.assertEqual('200', resp['status']) |
| 66 | |
| 67 | @test.attr(type='smoke') |
| 68 | def test_get_message(self): |
| 69 | # Post Messages |
| 70 | _, body = self._post_messages() |
| 71 | message_uri = body['resources'][0] |
| 72 | |
| 73 | # Get posted message |
| 74 | resp, _ = self.client.get_single_message(message_uri) |
| 75 | # The test has an assertion here, because the response cannot be 204 |
| 76 | # in this case (the client allows 200 or 204 for this API call). |
| 77 | self.assertEqual('200', resp['status']) |
| 78 | |
| 79 | @test.attr(type='smoke') |
| 80 | def test_get_multiple_messages(self): |
| 81 | # Post Messages |
| 82 | resp, _ = self._post_messages() |
| 83 | message_uri = resp['location'] |
| 84 | |
| 85 | # Get posted messages |
| 86 | resp, _ = self.client.get_multiple_messages(message_uri) |
| 87 | # The test has an assertion here, because the response cannot be 204 |
| 88 | # in this case (the client allows 200 or 204 for this API call). |
| 89 | self.assertEqual('200', resp['status']) |
| 90 | |
| 91 | @test.attr(type='smoke') |
| 92 | def test_delete_single_message(self): |
| 93 | # Post Messages |
| 94 | _, body = self._post_messages() |
| 95 | message_uri = body['resources'][0] |
| 96 | |
| 97 | # Delete posted message & verify the delete operration |
| 98 | self.client.delete_messages(message_uri) |
| 99 | |
| 100 | message_uri = message_uri.replace('/messages/', '/messages?ids=') |
| 101 | resp, _ = self.client.get_multiple_messages(message_uri) |
| 102 | # The test has an assertion here, because the response has to be 204 |
| 103 | # in this case (the client allows 200 or 204 for this API call). |
| 104 | self.assertEqual('204', resp['status']) |
| 105 | |
| 106 | @test.attr(type='smoke') |
| 107 | def test_delete_multiple_messages(self): |
| 108 | # Post Messages |
| 109 | resp, _ = self._post_messages() |
| 110 | message_uri = resp['location'] |
| 111 | |
| 112 | # Delete multiple messages |
| 113 | self.client.delete_messages(message_uri) |
| 114 | resp, _ = self.client.get_multiple_messages(message_uri) |
| 115 | # The test has an assertion here, because the response has to be 204 |
| 116 | # in this case (the client allows 200 or 204 for this API call). |
| 117 | self.assertEqual('204', resp['status']) |
| 118 | |
| 119 | @classmethod |
| 120 | def tearDownClass(cls): |
| 121 | cls.delete_queue(cls.queue_name) |
| 122 | super(TestMessages, cls).tearDownClass() |