
Moved consumers tests from functional to smoke tests. Added test to handle get consumers. Also added consumer behaviors and the consumer model. Change-Id: I3466fbf6c0f13ba9ea483a8251f19b00104968a3
80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
"""
|
|
Copyright 2014 Rackspace
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
"""
|
|
from functionaltests.api.v1.behaviors import base_behaviors
|
|
from functionaltests.api.v1.models import consumer_model
|
|
|
|
|
|
class ConsumerBehaviors(base_behaviors.BaseBehaviors):
|
|
|
|
def create_consumer(self, model, container_ref):
|
|
"""Register a consumer to a container.
|
|
|
|
:param model: The metadata for the consumer
|
|
:param container_ref: Full reference to a container
|
|
|
|
:return: A tuple containing the response from the create
|
|
and the href to the newly registered consumer
|
|
"""
|
|
|
|
url = '{0}/consumers'.format(container_ref)
|
|
|
|
resp = self.client.post(url, request_model=model)
|
|
|
|
returned_data = resp.json()
|
|
consumer_data = returned_data['consumers']
|
|
|
|
return resp, consumer_data
|
|
|
|
def get_consumers(self, container_ref, limit=10, offset=0):
|
|
"""Gets a list of consumers on a container.
|
|
|
|
:param container_ref: Full reference to a container
|
|
:param limit: limits number of returned consumers
|
|
:param offset: represents how many records to skip before retrieving
|
|
the list
|
|
|
|
:return: The response from the get and refs to the next/previous list
|
|
of consumers
|
|
"""
|
|
|
|
url = '{0}/consumers'.format(container_ref)
|
|
|
|
params = {'limit': limit, 'offset': offset}
|
|
resp = self.client.get(url, params=params)
|
|
|
|
consumer_list = resp.json()
|
|
|
|
consumers, next_ref, prev_ref = self.client.get_list_of_models(
|
|
consumer_list, consumer_model.ConsumerModel)
|
|
|
|
return resp, consumers, next_ref, prev_ref
|
|
|
|
def delete_consumer(self, model, container_ref):
|
|
"""Deletes a consumer from a container.
|
|
|
|
:param model: The metadata for the consumer
|
|
:param container_ref: Full reference to a container
|
|
|
|
:return: The response from the delete
|
|
"""
|
|
url = '{0}/consumers'.format(container_ref)
|
|
|
|
resp = self.client.delete(url, request_model=model)
|
|
returned_data = resp.json()
|
|
consumer_data = returned_data['consumers']
|
|
|
|
return resp, consumer_data
|