Add a ConsumerClient and consumer API tests

This change adds a ConsumerClient for testing the Barbican
consumer API. It adds a consumer test suite and integrates
the ConsumerClient with the plugin testing infrastructure.

Change-Id: I844d1a97ffb82aa67a4ef3b89bd82c90aa221cbb
Depends-On: I930455c6ae1e1127706480f24c0ea46f5cc81e85
Implements: bp tempest-plugin
diff --git a/barbican_tempest_plugin/tests/api/base.py b/barbican_tempest_plugin/tests/api/base.py
index 6b37bc5..c5a7597 100644
--- a/barbican_tempest_plugin/tests/api/base.py
+++ b/barbican_tempest_plugin/tests/api/base.py
@@ -59,10 +59,13 @@
     def setup_clients(cls):
         super(BaseKeyManagerTest, cls).setup_clients()
         os = getattr(cls, 'os_%s' % cls.credentials[0])
-        cls.secret_client = os.secret_v1.SecretClient(service='key-manager')
+        cls.consumer_client = os.secret_v1.ConsumerClient(
+            service='key-manager'
+        )
         cls.container_client = os.secret_v1.ContainerClient(
             service='key-manager'
         )
+        cls.secret_client = os.secret_v1.SecretClient(service='key-manager')
 
     @classmethod
     def resource_setup(cls):
diff --git a/barbican_tempest_plugin/tests/api/test_consumers.py b/barbican_tempest_plugin/tests/api/test_consumers.py
new file mode 100644
index 0000000..bd11cc8
--- /dev/null
+++ b/barbican_tempest_plugin/tests/api/test_consumers.py
@@ -0,0 +1,96 @@
+# Copyright (c) 2016 Johns Hopkins University Applied Physics Laboratory
+#
+# 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 barbican_tempest_plugin.tests.api import base
+
+
+class ConsumersTest(base.BaseKeyManagerTest):
+    """Containers API tests."""
+
+    def test_add_delete_consumers_in_container(self):
+        # Create a container to test against
+        body = self.create_container(
+            type="generic",
+            name="consumer-container"
+        )
+        container_id = base._get_uuid(body.get('container_ref'))
+
+        # Confirm that the container has no consumers
+        body = self.consumer_client.list_consumers_in_container(container_id)
+        self.assertEqual(0, body.get('total'), body)
+        self.assertEmpty(body.get('consumers'), body)
+
+        # Add some consumers to the container
+        body = self.consumer_client.add_consumer_to_container(
+            container_id,
+            name="consumer1",
+            URL="url1"
+        )
+        self.assertEqual(
+            container_id,
+            base._get_uuid(body.get('container_ref')),
+            body
+        )
+        self.assertEqual(1, len(body.get('consumers')), body)
+        body = self.consumer_client.add_consumer_to_container(
+            container_id,
+            name="consumer2",
+            URL="url2"
+        )
+        self.assertEqual(
+            container_id,
+            base._get_uuid(body.get('container_ref')),
+            body
+        )
+        self.assertEqual(2, len(body.get('consumers')), body)
+
+        # Confirm that the consumers are in the container
+        body = self.consumer_client.list_consumers_in_container(container_id)
+        self.assertEqual(2, body.get('total'), body)
+        self.assertEqual(2, len(body.get('consumers')), body)
+        for consumer in body.get('consumers'):
+            self.assertIn(consumer.get('name'), ("consumer1", "consumer2"))
+            self.assertIn(consumer.get('URL'), ("url1", "url2"))
+
+        # Remove the consumers from the container
+        body = self.consumer_client.delete_consumer_from_container(
+            container_id,
+            name="consumer1",
+            URL="url1"
+        )
+        self.assertEqual(
+            container_id,
+            base._get_uuid(body.get('container_ref')),
+            body
+        )
+        self.assertEqual(1, len(body.get('consumers')), body)
+        body = self.consumer_client.delete_consumer_from_container(
+            container_id,
+            name="consumer2",
+            URL="url2"
+        )
+        self.assertEqual(
+            container_id,
+            base._get_uuid(body.get('container_ref')),
+            body
+        )
+        self.assertEqual(0, len(body.get('consumers')), body)
+
+        # Confirm that the container has no consumers
+        body = self.consumer_client.list_consumers_in_container(container_id)
+        self.assertEqual(0, body.get('total'), body)
+        self.assertEqual(0, len(body.get('consumers')), body)
+
+        # Clean up the container
+        self.delete_container(container_id)