# Path: deckhand/engine/secrets_manager.py
# CONF = cfg.CONF
# LOG = logging.getLogger(__name__)
# class SecretsManager(object):
# class SecretsSubstitution(object):
#     def requires_encryption(document):
#     def is_barbican_ref(cls, secret_ref):
#     def create(cls, secret_doc):
#     def get(cls, secret_ref):
#     def _get_secret_type(cls, schema):
#     def sanitize_potential_secrets(error, document):
#     def get_encrypted_data(src_secret, src_doc, dest_doc):
#     def __init__(self, substitution_sources=None,
#                  fail_on_missing_sub_src=True):
#     def _handle_unknown_substitution_exc(self, exc_message, src_doc, dest_doc):
#     def _get_encrypted_secret(self, src_secret, src_doc, dest_doc):
#     def _check_src_secret_is_not_none(self, src_secret, src_path, src_doc,
#                                       dest_doc):
#     def substitute_all(self, documents):
#     def update_substitution_sources(self, schema, name, data):
# 
# Path: deckhand/factories.py
# LOG = logging.getLogger(__name__)
# DOCUMENT_TEST_SCHEMA = 'example/Kind/v1'
#     DATA_SCHEMA_TEMPLATE = {
#         "data": {
#             "$schema": ""
#         },
#         "metadata": {
#             "schema": "metadata/Control/v1",
#             "name": "",
#             "labels": {},
#             "layeringDefinition": {
#                 "abstract": True,
#                 "layer": "site"
#             }
#         },
#         "schema": "deckhand/DataSchema/v1"
#     }
#     LAYERING_POLICY_TEMPLATE = {
#         "data": {
#             "layerOrder": []
#         },
#         "metadata": {
#             "name": "placeholder",
#             "schema": "metadata/Control/v1",
#             "layeringDefinition": {
#                 "abstract": False,
#                 "layer": "layer"
#             }
#         },
#         "schema": "deckhand/LayeringPolicy/v1"
#     }
#     DOCUMENT_TEMPLATE = {
#         "data": {},
#         "metadata": {
#             "labels": {"": ""},
#             "layeringDefinition": {
#                 "abstract": False,
#                 "layer": "layer"
#             },
#             "name": "",
#             "schema": "metadata/Document/v1"
#         },
#         "schema": DOCUMENT_TEST_SCHEMA
#     }
#     DOCUMENT_SECRET_TEMPLATE = {
#         "data": {
#         },
#         "metadata": {
#             "schema": "metadata/Document/v1",
#             "name": "",
#             "layeringDefinition": {
#                 "abstract": False,
#                 "layer": "site"
#             },
#             "storagePolicy": "",
#         },
#         "schema": "deckhand/%s/v1"
#     }
# class DeckhandFactory(object):
# class DataSchemaFactory(DeckhandFactory):
# class DocumentFactory(DeckhandFactory):
# class DocumentSecretFactory(DeckhandFactory):
#     def gen_test(self, *args, **kwargs):
#     def __init__(self):
#     def gen_test(self, metadata_name, data, **metadata_labels):
#     def __init__(self, num_layers, docs_per_layer):
#     def gen_test(self, mapping, site_abstract=True, region_abstract=True,
#                  global_abstract=True, site_parent_selectors=None):
#     def __init__(self):
#     def gen_test(self, schema, storage_policy, data=None, name=None):
# 
# Path: deckhand/tests/test_utils.py
# def rand_uuid_hex():
# def rand_name(name='', prefix='deckhand'):
# def rand_bool():
# def rand_int(min, max):
# def rand_password(length=15):
# 
# Path: deckhand/tests/unit/control/base.py
# class BaseControllerTest(test_base.DeckhandWithDBTestCase,
#                          falcon_testing.TestCase):
#     def setUp(self):
#     def _read_data(self, file_name):


import yaml
import mock
from oslo_config import cfg
from deckhand.engine import secrets_manager
from deckhand import factories
from deckhand.tests import test_utils
from deckhand.tests.unit.control import base as test_base
        self.assertEqual(200, resp.status_code)
        documents = list(yaml.safe_load_all(resp.text))
        self.assertEqual(3, len(documents))
        self.assertEqual([alt_bucket_name] * 3,
                         [d['status']['bucket'] for d in documents])


class TestBucketsControllerNegative(test_base.BaseControllerTest):
    """Test suite for validating negative scenarios for bucket controller."""

    def test_put_conflicting_layering_policy(self):
        rules = {'deckhand:create_cleartext_documents': '@'}
        self.policy.set_rules(rules)

        payload = factories.DocumentFactory(1, [1]).gen_test({})[0]

        # Create the first layering policy.
        resp = self.app.simulate_put(
            '/api/v1.0/buckets/mop/documents',
            headers={'Content-Type': 'application/x-yaml'},
            body=yaml.safe_dump_all([payload]))
        self.assertEqual(200, resp.status_code)

        # Validate that a layering policy with a different, conflicting name
        # raises the expected exception.
        error_re = (r'.*A singleton document \[%s, %s\] %s already exists in '
                    'the system.' % (payload['schema'],
                                     payload['metadata']['layeringDefinition'][
                                     'layer'],
                                     payload['metadata']['name']))

# Path: deckhand/engine/secrets_manager.py
# CONF = cfg.CONF
# LOG = logging.getLogger(__name__)
# class SecretsManager(object):
# class SecretsSubstitution(object):
#     def requires_encryption(document):
#     def is_barbican_ref(cls, secret_ref):
#     def create(cls, secret_doc):
#     def get(cls, secret_ref):
#     def _get_secret_type(cls, schema):
#     def sanitize_potential_secrets(error, document):
#     def get_encrypted_data(src_secret, src_doc, dest_doc):
#     def __init__(self, substitution_sources=None,
#                  fail_on_missing_sub_src=True):
#     def _handle_unknown_substitution_exc(self, exc_message, src_doc, dest_doc):
#     def _get_encrypted_secret(self, src_secret, src_doc, dest_doc):
#     def _check_src_secret_is_not_none(self, src_secret, src_path, src_doc,
#                                       dest_doc):
#     def substitute_all(self, documents):
#     def update_substitution_sources(self, schema, name, data):
# 
# Path: deckhand/factories.py
# LOG = logging.getLogger(__name__)
# DOCUMENT_TEST_SCHEMA = 'example/Kind/v1'
#     DATA_SCHEMA_TEMPLATE = {
#         "data": {
#             "$schema": ""
#         },
#         "metadata": {
#             "schema": "metadata/Control/v1",
#             "name": "",
#             "labels": {},
#             "layeringDefinition": {
#                 "abstract": True,
#                 "layer": "site"
#             }
#         },
#         "schema": "deckhand/DataSchema/v1"
#     }
#     LAYERING_POLICY_TEMPLATE = {
#         "data": {
#             "layerOrder": []
#         },
#         "metadata": {
#             "name": "placeholder",
#             "schema": "metadata/Control/v1",
#             "layeringDefinition": {
#                 "abstract": False,
#                 "layer": "layer"
#             }
#         },
#         "schema": "deckhand/LayeringPolicy/v1"
#     }
#     DOCUMENT_TEMPLATE = {
#         "data": {},
#         "metadata": {
#             "labels": {"": ""},
#             "layeringDefinition": {
#                 "abstract": False,
#                 "layer": "layer"
#             },
#             "name": "",
#             "schema": "metadata/Document/v1"
#         },
#         "schema": DOCUMENT_TEST_SCHEMA
#     }
#     DOCUMENT_SECRET_TEMPLATE = {
#         "data": {
#         },
#         "metadata": {
#             "schema": "metadata/Document/v1",
#             "name": "",
#             "layeringDefinition": {
#                 "abstract": False,
#                 "layer": "site"
#             },
#             "storagePolicy": "",
#         },
#         "schema": "deckhand/%s/v1"
#     }
# class DeckhandFactory(object):
# class DataSchemaFactory(DeckhandFactory):
# class DocumentFactory(DeckhandFactory):
# class DocumentSecretFactory(DeckhandFactory):
#     def gen_test(self, *args, **kwargs):
#     def __init__(self):
#     def gen_test(self, metadata_name, data, **metadata_labels):
#     def __init__(self, num_layers, docs_per_layer):
#     def gen_test(self, mapping, site_abstract=True, region_abstract=True,
#                  global_abstract=True, site_parent_selectors=None):
#     def __init__(self):
#     def gen_test(self, schema, storage_policy, data=None, name=None):
# 
# Path: deckhand/tests/test_utils.py
# def rand_uuid_hex():
# def rand_name(name='', prefix='deckhand'):
# def rand_bool():
# def rand_int(min, max):
# def rand_password(length=15):
# 
# Path: deckhand/tests/unit/control/base.py
# class BaseControllerTest(test_base.DeckhandWithDBTestCase,
#                          falcon_testing.TestCase):
#     def setUp(self):
#     def _read_data(self, file_name):


# Path: deckhand/tests/unit/control/test_buckets_controller.py
import yaml
import mock
from oslo_config import cfg
from deckhand.engine import secrets_manager
from deckhand import factories
from deckhand.tests import test_utils
from deckhand.tests.unit.control import base as test_base

        self.assertEqual(200, resp.status_code)
        documents = list(yaml.safe_load_all(resp.text))
        self.assertEqual(3, len(documents))
        self.assertEqual([alt_bucket_name] * 3,
                         [d['status']['bucket'] for d in documents])


class TestBucketsControllerNegative(test_base.BaseControllerTest):
    """Test suite for validating negative scenarios for bucket controller."""

    def test_put_conflicting_layering_policy(self):
        rules = {'deckhand:create_cleartext_documents': '@'}
        self.policy.set_rules(rules)

        payload = factories.DocumentFactory(1, [1]).gen_test({})[0]

        # Create the first layering policy.
        resp = self.app.simulate_put(
            '/api/v1.0/buckets/mop/documents',
            headers={'Content-Type': 'application/x-yaml'},
            body=yaml.safe_dump_all([payload]))
        self.assertEqual(200, resp.status_code)

        # Validate that a layering policy with a different, conflicting name
        # raises the expected exception.
        error_re = (r'.*A singleton document \[%s, %s\] %s already exists in '
                    'the system.' % (payload['schema'],
                                     payload['metadata']['layeringDefinition'][
                                     'layer'],
                                     payload['metadata']['name']))

        payload['metadata']['name'] = test_utils.rand_name('layering-policy')