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 | |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 18 | from tempest_lib.common.utils import data_utils |
| 19 | |
Victoria Martínez de la Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 20 | from tempest.api.messaging import base |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 21 | from tempest import config |
| 22 | from tempest import test |
| 23 | |
| 24 | |
| 25 | LOG = logging.getLogger(__name__) |
| 26 | CONF = config.CONF |
| 27 | |
| 28 | |
Victoria Martínez de la Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 29 | class TestMessages(base.BaseMessagingTest): |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 30 | |
| 31 | @classmethod |
Andrea Frittoli | 23ee1c6 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 32 | def resource_setup(cls): |
| 33 | super(TestMessages, cls).resource_setup() |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 34 | cls.queue_name = data_utils.rand_name('Queues-Test') |
| 35 | # Create Queue |
| 36 | cls.client.create_queue(cls.queue_name) |
| 37 | |
Victoria Martínez de la Cruz | 1173b6e | 2014-09-22 18:32:13 -0300 | [diff] [blame] | 38 | def _post_messages(self, repeat=CONF.messaging.max_messages_per_page): |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 39 | message_body = self.generate_message_body(repeat=repeat) |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 40 | resp, body = self.post_messages(queue_name=self.queue_name, |
| 41 | rbody=message_body) |
| 42 | return resp, body |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 43 | |
| 44 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 45 | @test.idempotent_id('93867172-a414-4eb3-a639-96e943c516b4') |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 46 | def test_post_messages(self): |
| 47 | # Post Messages |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 48 | resp, _ = self._post_messages() |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 49 | |
| 50 | # Get on the posted messages |
| 51 | message_uri = resp['location'] |
Ken'ichi Ohmichi | 7e3ccd5 | 2015-04-06 23:55:46 +0000 | [diff] [blame] | 52 | resp, _ = self.client.show_multiple_messages(message_uri) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 53 | # The test has an assertion here, because the response cannot be 204 |
| 54 | # in this case (the client allows 200 or 204 for this API call). |
| 55 | self.assertEqual('200', resp['status']) |
| 56 | |
| 57 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 58 | @test.idempotent_id('c967d59a-e919-41cb-994b-1c4300452c80') |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 59 | def test_list_messages(self): |
| 60 | # Post Messages |
| 61 | self._post_messages() |
| 62 | |
| 63 | # List Messages |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 64 | resp, _ = self.list_messages(queue_name=self.queue_name) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 65 | # The test has an assertion here, because the response cannot be 204 |
| 66 | # in this case (the client allows 200 or 204 for this API call). |
| 67 | self.assertEqual('200', resp['status']) |
| 68 | |
| 69 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 70 | @test.idempotent_id('2a68e3de-24df-47c3-9039-ec4156656bf8') |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 71 | def test_get_message(self): |
| 72 | # Post Messages |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 73 | _, body = self._post_messages() |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 74 | message_uri = body['resources'][0] |
| 75 | |
| 76 | # Get posted message |
Ken'ichi Ohmichi | 7e3ccd5 | 2015-04-06 23:55:46 +0000 | [diff] [blame] | 77 | resp, _ = self.client.show_single_message(message_uri) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 78 | # The test has an assertion here, because the response cannot be 204 |
| 79 | # in this case (the client allows 200 or 204 for this API call). |
| 80 | self.assertEqual('200', resp['status']) |
| 81 | |
| 82 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 83 | @test.idempotent_id('c4b0a30b-efda-4b87-a395-0c43140df74d') |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 84 | def test_get_multiple_messages(self): |
| 85 | # Post Messages |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 86 | resp, _ = self._post_messages() |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 87 | message_uri = resp['location'] |
| 88 | |
| 89 | # Get posted messages |
Ken'ichi Ohmichi | 7e3ccd5 | 2015-04-06 23:55:46 +0000 | [diff] [blame] | 90 | resp, _ = self.client.show_multiple_messages(message_uri) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 91 | # The test has an assertion here, because the response cannot be 204 |
| 92 | # in this case (the client allows 200 or 204 for this API call). |
| 93 | self.assertEqual('200', resp['status']) |
| 94 | |
| 95 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 96 | @test.idempotent_id('fc0fca47-dd8b-4ecc-8522-d9c191f9bc9f') |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 97 | def test_delete_single_message(self): |
| 98 | # Post Messages |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 99 | _, body = self._post_messages() |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 100 | message_uri = body['resources'][0] |
| 101 | |
| 102 | # Delete posted message & verify the delete operration |
| 103 | self.client.delete_messages(message_uri) |
| 104 | |
| 105 | message_uri = message_uri.replace('/messages/', '/messages?ids=') |
Ken'ichi Ohmichi | 7e3ccd5 | 2015-04-06 23:55:46 +0000 | [diff] [blame] | 106 | resp, _ = self.client.show_multiple_messages(message_uri) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 107 | # The test has an assertion here, because the response has to be 204 |
| 108 | # in this case (the client allows 200 or 204 for this API call). |
| 109 | self.assertEqual('204', resp['status']) |
| 110 | |
| 111 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 112 | @test.idempotent_id('00cca069-5c8f-4b42-bff1-c577da2a4546') |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 113 | def test_delete_multiple_messages(self): |
| 114 | # Post Messages |
Flavio Percoco | 5ee9f2f | 2015-02-25 08:36:09 +0100 | [diff] [blame] | 115 | resp, _ = self._post_messages() |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 116 | message_uri = resp['location'] |
| 117 | |
| 118 | # Delete multiple messages |
| 119 | self.client.delete_messages(message_uri) |
Ken'ichi Ohmichi | 7e3ccd5 | 2015-04-06 23:55:46 +0000 | [diff] [blame] | 120 | resp, _ = self.client.show_multiple_messages(message_uri) |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 121 | # The test has an assertion here, because the response has to be 204 |
| 122 | # in this case (the client allows 200 or 204 for this API call). |
| 123 | self.assertEqual('204', resp['status']) |
| 124 | |
| 125 | @classmethod |
Andrea Frittoli | 23ee1c6 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 126 | def resource_cleanup(cls): |
Malini Kamalambal | 7458b4b | 2014-05-29 11:47:28 -0400 | [diff] [blame] | 127 | cls.delete_queue(cls.queue_name) |
Andrea Frittoli | 23ee1c6 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 128 | super(TestMessages, cls).resource_cleanup() |