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