blob: efbbf56f7a0ece6fbfb2151ae4f96cb56ff415fe [file] [log] [blame]
Malini Kamalambal7458b4b2014-05-29 11:47:28 -04001# 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
16import logging
17
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030018from tempest.api.messaging import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040020from tempest import config
21from tempest import test
22
23
24LOG = logging.getLogger(__name__)
25CONF = config.CONF
26
27
Victoria Martínez de la Cruz1173b6e2014-09-22 18:32:13 -030028class TestMessages(base.BaseMessagingTest):
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040029
30 @classmethod
Andrea Frittoli23ee1c62014-09-15 13:14:54 +010031 def resource_setup(cls):
32 super(TestMessages, cls).resource_setup()
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040033 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 Cruz1173b6e2014-09-22 18:32:13 -030037 def _post_messages(self, repeat=CONF.messaging.max_messages_per_page):
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040038 message_body = self.generate_message_body(repeat=repeat)
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010039 resp, body = self.post_messages(queue_name=self.queue_name,
40 rbody=message_body)
41 return resp, body
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040042
43 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080044 @test.idempotent_id('93867172-a414-4eb3-a639-96e943c516b4')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040045 def test_post_messages(self):
46 # Post Messages
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010047 resp, _ = self._post_messages()
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040048
49 # Get on the posted messages
50 message_uri = resp['location']
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +000051 resp, _ = self.client.show_multiple_messages(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040052 # 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 Hoge7579c1a2015-02-26 14:12:15 -080057 @test.idempotent_id('c967d59a-e919-41cb-994b-1c4300452c80')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040058 def test_list_messages(self):
59 # Post Messages
60 self._post_messages()
61
62 # List Messages
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010063 resp, _ = self.list_messages(queue_name=self.queue_name)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040064 # 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 Hoge7579c1a2015-02-26 14:12:15 -080069 @test.idempotent_id('2a68e3de-24df-47c3-9039-ec4156656bf8')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040070 def test_get_message(self):
71 # Post Messages
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010072 _, body = self._post_messages()
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040073 message_uri = body['resources'][0]
74
75 # Get posted message
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +000076 resp, _ = self.client.show_single_message(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040077 # 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 Hoge7579c1a2015-02-26 14:12:15 -080082 @test.idempotent_id('c4b0a30b-efda-4b87-a395-0c43140df74d')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040083 def test_get_multiple_messages(self):
84 # Post Messages
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010085 resp, _ = self._post_messages()
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040086 message_uri = resp['location']
87
88 # Get posted messages
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +000089 resp, _ = self.client.show_multiple_messages(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040090 # 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 Hoge7579c1a2015-02-26 14:12:15 -080095 @test.idempotent_id('fc0fca47-dd8b-4ecc-8522-d9c191f9bc9f')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040096 def test_delete_single_message(self):
97 # Post Messages
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +010098 _, body = self._post_messages()
Malini Kamalambal7458b4b2014-05-29 11:47:28 -040099 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 Ohmichi7e3ccd52015-04-06 23:55:46 +0000105 resp, _ = self.client.show_multiple_messages(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400106 # 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 Hoge7579c1a2015-02-26 14:12:15 -0800111 @test.idempotent_id('00cca069-5c8f-4b42-bff1-c577da2a4546')
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400112 def test_delete_multiple_messages(self):
113 # Post Messages
Flavio Percoco5ee9f2f2015-02-25 08:36:09 +0100114 resp, _ = self._post_messages()
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400115 message_uri = resp['location']
116
117 # Delete multiple messages
118 self.client.delete_messages(message_uri)
Ken'ichi Ohmichi7e3ccd52015-04-06 23:55:46 +0000119 resp, _ = self.client.show_multiple_messages(message_uri)
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400120 # 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 Frittoli23ee1c62014-09-15 13:14:54 +0100125 def resource_cleanup(cls):
Malini Kamalambal7458b4b2014-05-29 11:47:28 -0400126 cls.delete_queue(cls.queue_name)
Andrea Frittoli23ee1c62014-09-15 13:14:54 +0100127 super(TestMessages, cls).resource_cleanup()