Exemplo n.º 1
0
    def test_adds_an_in_clause_for_multiple_values(self):
        self.model.cat.in_.return_value = 'fake in clause'
        filters = {'cat': ['foo', 'quux']}
        db_filters.exact_filter(self.query, self.model, filters)

        self.query.filter.assert_called_once_with('fake in clause')
        self.model.cat.in_.assert_called_once_with(['foo', 'quux'])
Exemplo n.º 2
0
Arquivo: api.py Projeto: nostmax/heat
def stack_count_all(
    context,
    filters=None,
    tenant_safe=True,
    show_deleted=False,
    show_nested=False,
    show_hidden=False,
    tags=None,
    tags_any=None,
    not_tags=None,
    not_tags_any=None,
):
    query = _query_stack_get_all(
        context,
        tenant_safe=tenant_safe,
        show_deleted=show_deleted,
        show_nested=show_nested,
        show_hidden=show_hidden,
        tags=tags,
        tags_any=tags_any,
        not_tags=not_tags,
        not_tags_any=not_tags_any,
    )
    query = db_filters.exact_filter(query, models.Stack, filters)
    return query.count()
Exemplo n.º 3
0
def stack_count_all(context, filters=None, tenant_safe=True,
                    show_deleted=False, show_nested=False):
    query = _query_stack_get_all(context, tenant_safe=tenant_safe,
                                 show_deleted=show_deleted,
                                 show_nested=show_nested)
    query = db_filters.exact_filter(query, models.Stack, filters)
    return query.count()
Exemplo n.º 4
0
def stack_count_all(context, filters=None, tenant_safe=True,
                    show_deleted=False, show_nested=False):
    query = _query_stack_get_all(context, tenant_safe=tenant_safe,
                                 show_deleted=show_deleted,
                                 show_nested=show_nested)
    query = db_filters.exact_filter(query, models.Stack, filters)
    return query.count()
Exemplo n.º 5
0
def event_get_all_by_tenant(context, limit=None, marker=None,
                            sort_keys=None, sort_dir=None, filters=None):
    query = model_query(context, models.Event)
    query = db_filters.exact_filter(query, models.Event, filters)
    query = query.join(models.Event.stack).\
        filter_by(tenant=context.tenant_id).filter_by(deleted_at=None)
    filters = None
    return _events_filter_and_page_query(context, query, limit, marker,
                                         sort_keys, sort_dir, filters).all()
Exemplo n.º 6
0
def event_get_all_by_tenant(context, limit=None, marker=None,
                            sort_keys=None, sort_dir=None, filters=None):
    query = model_query(context, models.Event)
    query = db_filters.exact_filter(query, models.Event, filters)
    query = query.join(models.Event.stack).\
        filter_by(tenant=context.tenant_id).filter_by(deleted_at=None)
    filters = None
    return _events_filter_and_page_query(context, query, limit, marker,
                                         sort_keys, sort_dir, filters).all()
Exemplo n.º 7
0
def stack_count_all(context, filters=None, tenant_safe=True,
                    show_deleted=False, show_nested=False, show_hidden=False,
                    tags=None, tags_any=None, not_tags=None,
                    not_tags_any=None):
    query = _query_stack_get_all(context, tenant_safe=tenant_safe,
                                 show_deleted=show_deleted,
                                 show_nested=show_nested,
                                 show_hidden=show_hidden, tags=tags,
                                 tags_any=tags_any, not_tags=not_tags,
                                 not_tags_any=not_tags_any)
    query = db_filters.exact_filter(query, models.Stack, filters)
    return query.count()
Exemplo n.º 8
0
Arquivo: api.py Projeto: nostmax/heat
def _events_filter_and_page_query(context, query, limit=None, marker=None, sort_keys=None, sort_dir=None, filters=None):
    if filters is None:
        filters = {}

    sort_key_map = {
        rpc_api.EVENT_TIMESTAMP: models.Event.created_at.key,
        rpc_api.EVENT_RES_TYPE: models.Event.resource_type.key,
    }
    whitelisted_sort_keys = _get_sort_keys(sort_keys, sort_key_map)

    query = db_filters.exact_filter(query, models.Event, filters)

    return _events_paginate_query(context, query, models.Event, limit, whitelisted_sort_keys, marker, sort_dir)
Exemplo n.º 9
0
def _filter_and_page_query(context, query, limit=None, sort_keys=None,
                           marker=None, sort_dir=None, filters=None):
    if filters is None:
        filters = {}

    sort_key_map = {rpc_api.STACK_NAME: models.Stack.name.key,
                    rpc_api.STACK_STATUS: models.Stack.status.key,
                    rpc_api.STACK_CREATION_TIME: models.Stack.created_at.key,
                    rpc_api.STACK_UPDATED_TIME: models.Stack.updated_at.key}
    whitelisted_sort_keys = _get_sort_keys(sort_keys, sort_key_map)

    query = db_filters.exact_filter(query, models.Stack, filters)
    return _paginate_query(context, query, models.Stack, limit,
                           whitelisted_sort_keys, marker, sort_dir)
Exemplo n.º 10
0
Arquivo: api.py Projeto: karcaw/heat
def _filter_and_page_query(context, query, limit=None, sort_keys=None,
                           marker=None, sort_dir=None, filters=None):
    if filters is None:
        filters = {}

    allowed_sort_keys = [models.Stack.name.key,
                         models.Stack.status.key,
                         models.Stack.created_at.key,
                         models.Stack.updated_at.key]
    whitelisted_sort_keys = _filter_sort_keys(sort_keys, allowed_sort_keys)

    query = db_filters.exact_filter(query, models.Stack, filters)
    return _paginate_query(context, query, models.Stack, limit,
                           whitelisted_sort_keys, marker, sort_dir)
Exemplo n.º 11
0
Arquivo: api.py Projeto: B-Rich/heat
def _filter_and_page_query(context, query, limit=None, sort_keys=None,
                           marker=None, sort_dir=None, filters=None):
    if filters is None:
        filters = {}

    allowed_sort_keys = [models.Stack.name.key,
                         models.Stack.status.key,
                         models.Stack.created_at.key,
                         models.Stack.updated_at.key]
    whitelisted_sort_keys = _filter_sort_keys(sort_keys, allowed_sort_keys)

    query = db_filters.exact_filter(query, models.Stack, filters)
    return _paginate_query(context, query, models.Stack, limit,
                           whitelisted_sort_keys, marker, sort_dir)
Exemplo n.º 12
0
def _filter_and_page_query(context, query, limit=None, sort_keys=None,
                           marker=None, sort_dir=None, filters=None):
    if filters is None:
        filters = {}

    sort_key_map = {rpc_api.STACK_NAME: models.Stack.name.key,
                    rpc_api.STACK_STATUS: models.Stack.status.key,
                    rpc_api.STACK_CREATION_TIME: models.Stack.created_at.key,
                    rpc_api.STACK_UPDATED_TIME: models.Stack.updated_at.key}
    whitelisted_sort_keys = _get_sort_keys(sort_keys, sort_key_map)

    query = db_filters.exact_filter(query, models.Stack, filters)
    return _paginate_query(context, query, models.Stack, limit,
                           whitelisted_sort_keys, marker, sort_dir)
Exemplo n.º 13
0
Arquivo: api.py Projeto: jazeltq/heat
def stack_get_all_by_tenant(context, limit=None, sort_keys=None, marker=None,
                            sort_dir=None, filters=None):
    if filters is None:
        filters = {}

    allowed_sort_keys = [models.Stack.name.key,
                         models.Stack.status.key,
                         models.Stack.created_at.key,
                         models.Stack.updated_at.key]
    filtered_keys = _filter_sort_keys(sort_keys, allowed_sort_keys)

    query = _query_stack_get_all_by_tenant(context)
    query = db_filters.exact_filter(query, models.Stack, filters)
    return _paginate_query(context, query, models.Stack, limit, filtered_keys,
                           marker, sort_dir).all()
Exemplo n.º 14
0
def _events_filter_and_page_query(context, query,
                                  limit=None, marker=None,
                                  sort_keys=None, sort_dir=None,
                                  filters=None):
    if filters is None:
        filters = {}

    sort_key_map = {rpc_api.EVENT_TIMESTAMP: models.Event.created_at.key,
                    rpc_api.EVENT_RES_TYPE: models.Event.resource_type.key}
    whitelisted_sort_keys = _get_sort_keys(sort_keys, sort_key_map)

    query = db_filters.exact_filter(query, models.Event, filters)

    return _events_paginate_query(context, query, models.Event, limit,
                                  whitelisted_sort_keys, marker, sort_dir)
Exemplo n.º 15
0
Arquivo: api.py Projeto: ColinCui/heat
def _events_filter_and_page_query(context, query,
                                  limit=None, marker=None,
                                  sort_keys=None, sort_dir=None,
                                  filters=None):
    if filters is None:
        filters = {}

    allowed_sort_keys = [models.Event.created_at.key,
                         models.Event.resource_type.key]
    whitelisted_sort_keys = _filter_sort_keys(sort_keys, allowed_sort_keys)

    query = db_filters.exact_filter(query, models.Event, filters)

    return _events_paginate_query(context, query, models.Event, limit,
                                  whitelisted_sort_keys, marker, sort_dir)
Exemplo n.º 16
0
def resource_get_all_by_stack(context, stack_id, key_id=False, filters=None):
    query = model_query(
        context, models.Resource
    ).filter_by(
        stack_id=stack_id
    ).options(orm.joinedload("data"))

    query = db_filters.exact_filter(query, models.Resource, filters)
    results = query.all()

    if not results:
        raise exception.NotFound(_("no resources for stack_id %s were found")
                                 % stack_id)
    if key_id:
        return dict((res.id, res) for res in results)
    else:
        return dict((res.name, res) for res in results)
Exemplo n.º 17
0
def stack_get_all_by_tenant(context,
                            limit=None,
                            sort_keys=None,
                            marker=None,
                            sort_dir=None,
                            filters=None):
    if filters is None:
        filters = {}

    allowed_sort_keys = [
        models.Stack.name.key, models.Stack.status.key,
        models.Stack.created_at.key, models.Stack.updated_at.key
    ]
    filtered_keys = _filter_sort_keys(sort_keys, allowed_sort_keys)

    query = _query_stack_get_all_by_tenant(context)
    query = db_filters.exact_filter(query, models.Stack, filters)
    return _paginate_query(context, query, models.Stack, limit, filtered_keys,
                           marker, sort_dir).all()
Exemplo n.º 18
0
def _events_filter_and_page_query(context,
                                  query,
                                  limit=None,
                                  marker=None,
                                  sort_keys=None,
                                  sort_dir=None,
                                  filters=None):
    if filters is None:
        filters = {}

    allowed_sort_keys = [
        models.Event.created_at.key, models.Event.resource_type.key
    ]
    whitelisted_sort_keys = _filter_sort_keys(sort_keys, allowed_sort_keys)

    query = db_filters.exact_filter(query, models.Event, filters)

    return _events_paginate_query(context, query, models.Event, limit,
                                  whitelisted_sort_keys, marker, sort_dir)
Exemplo n.º 19
0
 def test_returns_same_query_for_empty_filters(self):
     filters = {}
     db_filters.exact_filter(self.query, self.model, filters)
     self.assertEqual(0, self.query.call_count)
Exemplo n.º 20
0
    def test_add_exact_match_clause_for_single_values(self):
        filters = {'cat': 'foo'}
        db_filters.exact_filter(self.query, self.model, filters)

        self.query.filter_by.assert_called_once_with(cat='foo')
Exemplo n.º 21
0
Arquivo: api.py Projeto: stavxyz/heat
def stack_count_all(context, filters=None, tenant_safe=True):
    query = _query_stack_get_all(context, tenant_safe=tenant_safe)
    query = db_filters.exact_filter(query, models.Stack, filters)
    return query.count()
Exemplo n.º 22
0
def stack_count_all_by_tenant(context, filters=None):
    query = _query_stack_get_all_by_tenant(context)
    query = db_filters.exact_filter(query, models.Stack, filters)
    return query.count()
Exemplo n.º 23
0
Arquivo: api.py Projeto: B-Rich/heat
def stack_count_all(context, filters=None, tenant_safe=True):
    query = _query_stack_get_all(context, tenant_safe=tenant_safe)
    query = db_filters.exact_filter(query, models.Stack, filters)
    return query.count()
Exemplo n.º 24
0
Arquivo: api.py Projeto: jazeltq/heat
def stack_count_all_by_tenant(context, filters=None):
    query = _query_stack_get_all_by_tenant(context)
    query = db_filters.exact_filter(query, models.Stack, filters)
    return query.count()