# Path: deckhand/control/views/revision_tag.py
# class ViewBuilder(common.ViewBuilder):
#     def list(self, tags):
#     def show(self, tag):
#     def _show(self, tag):
# 
# Path: deckhand/db/sqlalchemy/api.py
# LOG = logging.getLogger(__name__)
# CONF = cfg.CONF
# _FACADE = None
# _LOCK = threading.Lock()
#                 _FACADE = session.EngineFacade.from_config(
#                     CONF, sqlite_fk=True)
# def _create_facade_lazily():
# def get_engine():
# def get_session(autocommit=True, expire_on_commit=False):
# def drop_db():
# def setup_db(connection_string, create_tables=False):
# def raw_query(query, **kwargs):
# def require_unique_document_schema(schema=None):
#     def decorator(f):
#         def wrapper(bucket_name, documents, *args, **kwargs):
# def documents_create(bucket_name, documents, validations=None,
#                      session=None):
# def _documents_create(bucket_name, documents, session=None):
#     def _document_create(document):
# def _fill_in_metadata_defaults(document):
# def _make_hash(data):
# def document_get(session=None, raw_dict=False, revision_id=None, **filters):
# def document_get_all(session=None, raw_dict=False, revision_id=None,
#                      **filters):
# def bucket_get_or_create(bucket_name, session=None):
# def revision_create(session=None):
# def revision_get(revision_id=None, session=None):
# def revision_get_latest(session=None):
# def require_revision_exists(f):
#     def wrapper(revision_id=None, *args, **kwargs):
# def _update_revision_history(documents):
# def revision_get_all(session=None, **filters):
# def revision_delete_all():
# def _exclude_deleted_documents(documents):
# def _filter_revision_documents(documents, unique_only, **filters):
# def revision_documents_get(revision_id=None, include_history=True,
#                            unique_only=True, session=None, **filters):
# def revision_diff(revision_id, comparison_revision_id):
#     def _compare_buckets(b1, b2):
# def revision_tag_create(revision_id, tag, data=None, session=None):
# def revision_tag_get(revision_id, tag, session=None):
# def revision_tag_get_all(revision_id, session=None):
# def revision_tag_delete(revision_id, tag, session=None):
# def revision_tag_delete_all(revision_id, session=None):
# def revision_rollback(revision_id, latest_revision, session=None):
# def _get_validation_policies_for_revision(revision_id, session=None):
# def validation_create(revision_id, val_name, val_data, session=None):
# def validation_get_all(revision_id, session=None):
# def _check_validation_entries_against_validation_policies(
#         revision_id, entries, val_name=None, session=None):
# def validation_get_all_entries(revision_id, val_name=None, session=None):
# def validation_get_entry(revision_id, val_name, entry_id, session=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/db/base.py
# BASE_EXPECTED_FIELDS = ("created_at", "updated_at", "deleted_at", "deleted")
# DOCUMENT_EXPECTED_FIELDS = BASE_EXPECTED_FIELDS + (
#     "id", "schema", "name", "layer", "metadata", "data", "data_hash",
#     "metadata_hash", "revision_id", "bucket_id")
# REVISION_EXPECTED_FIELDS = ("id", "documents", "tags")
# class DocumentFixture(object):
# class TestDbBase(base.DeckhandWithDBTestCase):
#     def get_minimal_fixture(**kwargs):
#     def get_minimal_multi_fixture(count=2, **kwargs):
#     def create_documents(self, bucket_name, documents,
#                          validation_policies=None):
#     def show_document(self, **fields):
#     def create_revision(self):
#     def show_revision(self, revision_id):
#     def delete_revisions(self):
#     def list_revision_documents(self, revision_id, **filters):
#     def list_revisions(self):
#     def rollback_revision(self, revision_id):
#     def create_validation(self, revision_id, val_name, val_data):
#     def _validate_object(self, obj):
#     def validate_document(self, actual, expected=None, is_deleted=False):
#     def validate_revision(self, revision):


from deckhand.control.views import revision_tag
from deckhand.db.sqlalchemy import api as db_api
from deckhand.tests import test_utils
from deckhand.tests.unit.db import base
# See the License for the specific language governing permissions and
# limitations under the License.



class TestRevisionViews(base.TestDbBase):

    def setUp(self):
        super(TestRevisionViews, self).setUp()
        self.view_builder = revision_tag.ViewBuilder()
        self.revision_id = self.create_revision()

    def test_revision_tag_show_view(self):
        rand_prefix = test_utils.rand_name(self.__class__.__name__)
        tag = rand_prefix + '-Tag'
        data_key = rand_prefix + '-Key'
        data_val = rand_prefix + '-Val'
        expected_view = {tag: {data_key: data_val}}

        created_tag = db_api.revision_tag_create(
            self.revision_id, tag, {data_key: data_val})

        actual_view = self.view_builder.show(created_tag)
        self.assertEqual(expected_view, actual_view)

    def test_revision_tag_list_view(self):
        expected_view = {}

        # Create 2 revision tags for the same revision.
        for _ in range(2):

# Path: deckhand/control/views/revision_tag.py
# class ViewBuilder(common.ViewBuilder):
#     def list(self, tags):
#     def show(self, tag):
#     def _show(self, tag):
# 
# Path: deckhand/db/sqlalchemy/api.py
# LOG = logging.getLogger(__name__)
# CONF = cfg.CONF
# _FACADE = None
# _LOCK = threading.Lock()
#                 _FACADE = session.EngineFacade.from_config(
#                     CONF, sqlite_fk=True)
# def _create_facade_lazily():
# def get_engine():
# def get_session(autocommit=True, expire_on_commit=False):
# def drop_db():
# def setup_db(connection_string, create_tables=False):
# def raw_query(query, **kwargs):
# def require_unique_document_schema(schema=None):
#     def decorator(f):
#         def wrapper(bucket_name, documents, *args, **kwargs):
# def documents_create(bucket_name, documents, validations=None,
#                      session=None):
# def _documents_create(bucket_name, documents, session=None):
#     def _document_create(document):
# def _fill_in_metadata_defaults(document):
# def _make_hash(data):
# def document_get(session=None, raw_dict=False, revision_id=None, **filters):
# def document_get_all(session=None, raw_dict=False, revision_id=None,
#                      **filters):
# def bucket_get_or_create(bucket_name, session=None):
# def revision_create(session=None):
# def revision_get(revision_id=None, session=None):
# def revision_get_latest(session=None):
# def require_revision_exists(f):
#     def wrapper(revision_id=None, *args, **kwargs):
# def _update_revision_history(documents):
# def revision_get_all(session=None, **filters):
# def revision_delete_all():
# def _exclude_deleted_documents(documents):
# def _filter_revision_documents(documents, unique_only, **filters):
# def revision_documents_get(revision_id=None, include_history=True,
#                            unique_only=True, session=None, **filters):
# def revision_diff(revision_id, comparison_revision_id):
#     def _compare_buckets(b1, b2):
# def revision_tag_create(revision_id, tag, data=None, session=None):
# def revision_tag_get(revision_id, tag, session=None):
# def revision_tag_get_all(revision_id, session=None):
# def revision_tag_delete(revision_id, tag, session=None):
# def revision_tag_delete_all(revision_id, session=None):
# def revision_rollback(revision_id, latest_revision, session=None):
# def _get_validation_policies_for_revision(revision_id, session=None):
# def validation_create(revision_id, val_name, val_data, session=None):
# def validation_get_all(revision_id, session=None):
# def _check_validation_entries_against_validation_policies(
#         revision_id, entries, val_name=None, session=None):
# def validation_get_all_entries(revision_id, val_name=None, session=None):
# def validation_get_entry(revision_id, val_name, entry_id, session=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/db/base.py
# BASE_EXPECTED_FIELDS = ("created_at", "updated_at", "deleted_at", "deleted")
# DOCUMENT_EXPECTED_FIELDS = BASE_EXPECTED_FIELDS + (
#     "id", "schema", "name", "layer", "metadata", "data", "data_hash",
#     "metadata_hash", "revision_id", "bucket_id")
# REVISION_EXPECTED_FIELDS = ("id", "documents", "tags")
# class DocumentFixture(object):
# class TestDbBase(base.DeckhandWithDBTestCase):
#     def get_minimal_fixture(**kwargs):
#     def get_minimal_multi_fixture(count=2, **kwargs):
#     def create_documents(self, bucket_name, documents,
#                          validation_policies=None):
#     def show_document(self, **fields):
#     def create_revision(self):
#     def show_revision(self, revision_id):
#     def delete_revisions(self):
#     def list_revision_documents(self, revision_id, **filters):
#     def list_revisions(self):
#     def rollback_revision(self, revision_id):
#     def create_validation(self, revision_id, val_name, val_data):
#     def _validate_object(self, obj):
#     def validate_document(self, actual, expected=None, is_deleted=False):
#     def validate_revision(self, revision):


# Path: deckhand/tests/unit/views/test_revision_tag_views.py
from deckhand.control.views import revision_tag
from deckhand.db.sqlalchemy import api as db_api
from deckhand.tests import test_utils
from deckhand.tests.unit.db import base

# See the License for the specific language governing permissions and
# limitations under the License.



class TestRevisionViews(base.TestDbBase):

    def setUp(self):
        super(TestRevisionViews, self).setUp()
        self.view_builder = revision_tag.ViewBuilder()
        self.revision_id = self.create_revision()

    def test_revision_tag_show_view(self):
        rand_prefix = test_utils.rand_name(self.__class__.__name__)
        tag = rand_prefix + '-Tag'
        data_key = rand_prefix + '-Key'
        data_val = rand_prefix + '-Val'
        expected_view = {tag: {data_key: data_val}}

        created_tag = db_api.revision_tag_create(
            self.revision_id, tag, {data_key: data_val})

        actual_view = self.view_builder.show(created_tag)
        self.assertEqual(expected_view, actual_view)

    def test_revision_tag_list_view(self):
        expected_view = {}

        # Create 2 revision tags for the same revision.
        for _ in range(2):

            rand_prefix = test_utils.rand_name(self.__class__.__name__)