Andrew Kerr | fcb0b68 | 2016-04-01 16:01:34 -0400 | [diff] [blame] | 1 | # Copyright 2016 Andrew Kerr |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | from oslo_serialization import jsonutils as json |
| 17 | |
| 18 | from tempest.lib.common import rest_client |
| 19 | from tempest.lib import exceptions as lib_exc |
| 20 | from tempest.services.volume.base import base_v3_client |
| 21 | |
| 22 | |
| 23 | class MessagesClient(base_v3_client.BaseV3Client): |
| 24 | """Client class to send user messages API requests.""" |
| 25 | |
| 26 | def show_message(self, message_id): |
| 27 | """Show details for a single message.""" |
| 28 | url = 'messages/%s' % str(message_id) |
| 29 | resp, body = self.get(url) |
| 30 | body = json.loads(body) |
| 31 | self.expected_success(200, resp.status) |
| 32 | return rest_client.ResponseBody(resp, body) |
| 33 | |
| 34 | def list_messages(self): |
| 35 | """List all messages.""" |
| 36 | url = 'messages' |
| 37 | resp, body = self.get(url) |
| 38 | body = json.loads(body) |
| 39 | self.expected_success(200, resp.status) |
| 40 | return rest_client.ResponseBody(resp, body) |
| 41 | |
| 42 | def delete_message(self, message_id): |
| 43 | """Delete a single message.""" |
| 44 | url = 'messages/%s' % str(message_id) |
| 45 | resp, body = self.delete(url) |
| 46 | self.expected_success(204, resp.status) |
| 47 | return rest_client.ResponseBody(resp, body) |
| 48 | |
| 49 | def is_resource_deleted(self, id): |
| 50 | try: |
| 51 | self.show_message(id) |
| 52 | except lib_exc.NotFound: |
| 53 | return True |
| 54 | return False |
| 55 | |
| 56 | @property |
| 57 | def resource_type(self): |
| 58 | """Returns the primary type of resource this client works with.""" |
| 59 | return 'message' |