예제 #1
0
def test_searches_responses_fielded_response_is_request_from_embed(
        dummy_request):
    from snovault.elasticsearch.searches.responses import FieldedResponse
    from snovault.elasticsearch.searches.parsers import ParamsParser
    fr = FieldedResponse()
    assert not fr._is_request_from_embed()
    fr = FieldedResponse(_meta={'params_parser': ParamsParser(dummy_request)})
    assert not fr._is_request_from_embed()
    dummy_request.__parent__ = 'something'
    fr = FieldedResponse(_meta={'params_parser': ParamsParser(dummy_request)})
    assert fr._is_request_from_embed()
예제 #2
0
def test_searches_parsers_params_parser_get_limit(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'status=released&status!=submitted&type=File&file_format%21=bigWig')
    p = ParamsParser(dummy_request)
    assert p.get_limit() == []
    dummy_request.environ['QUERY_STRING'] = (
        'status=released&status!=submitted&type=File'
        '&file_format%21=bigWig&limit=all')
    p = ParamsParser(dummy_request)
    assert p.get_limit() == [('limit', 'all')]
예제 #3
0
def test_searches_responses_fielded_response_should_stream_response(
        dummy_request):
    from snovault.elasticsearch.searches.responses import FieldedResponse
    from snovault.elasticsearch.searches.parsers import ParamsParser
    fr = FieldedResponse()
    assert not fr._should_stream_response()
    fr = FieldedResponse(_meta={'params_parser': ParamsParser(dummy_request)})
    assert not fr._should_stream_response()
    fr.response = {'a': (x for x in [1, 2, 3])}
    assert fr._should_stream_response()
    dummy_request.__parent__ = 'something'
    fr = FieldedResponse(_meta={'params_parser': ParamsParser(dummy_request)})
    assert not fr._should_stream_response()
    fr.response = {'a': (x for x in [1, 2, 3])}
    assert not fr._should_stream_response()
예제 #4
0
def test_searches_responses_fielded_generator_response_render(dummy_request):
    from snovault.elasticsearch.searches.responses import FieldedGeneratorResponse
    from snovault.elasticsearch.searches.responses import GeneratorResponse
    from snovault.elasticsearch.searches.parsers import ParamsParser
    from types import GeneratorType
    from pyramid.response import Response
    fgr = FieldedGeneratorResponse()
    fgr.response = {'a': 1}
    response = fgr.render()
    assert isinstance(response, dict)
    fgr.response = {'a': (x for x in [1, 2, 3])}
    response = fgr.render()
    assert isinstance(response, dict)
    assert 'a' in response
    assert isinstance(response['a'], GeneratorType)
    assert list(response['a']) == [1, 2, 3]
    dummy_request.__parent__ = 'something'
    fgr = FieldedGeneratorResponse(
        _meta={'params_parser': ParamsParser(dummy_request)})
    fgr.response = {'a': (x for x in [1, 2, 3])}
    response = fgr.render()
    assert isinstance(response, dict)
    assert 'a' in response
    assert isinstance(response['a'], GeneratorType)
    assert list(response['a']) == [1, 2, 3]
예제 #5
0
def search(context, request):
    # Note the order of rendering matters for some fields, e.g. AllResponseField and
    # NotificationResponseField depend on results from BasicSearchWithFacetsResponseField.
    fr = FieldedResponse(
        _meta={
            'params_parser': ParamsParser(request)
        },
        response_fields=[
            TitleResponseField(
                title=SEARCH_TITLE
            ),
            TypeResponseField(
                at_type=[SEARCH_TITLE]
            ),
            IDResponseField(),
            ContextResponseField(),
            BasicSearchWithFacetsResponseField(
                default_item_types=DEFAULT_ITEM_TYPES
            ),
            AllResponseField(),
            NotificationResponseField(),
            FiltersResponseField(),
            ClearFiltersResponseField(),
            ColumnsResponseField(),
            SortResponseField(),
            DebugQueryResponseField()
        ]
    )
    return fr.render()
예제 #6
0
def cart_search(context, request):
    '''
    Like search but takes cart params.
    '''
    # Note the order of rendering matters for some fields, e.g. AllResponseField and
    # NotificationResponseField depend on results from CartSearchWithFacetsResponseField.
    fr = FieldedResponse(_meta={'params_parser': ParamsParser(request)},
                         response_fields=[
                             TitleResponseField(title='Cart search'),
                             TypeResponseField(at_type=[SEARCH_TITLE]),
                             IDResponseField(),
                             ContextResponseField(),
                             CartSearchWithFacetsResponseField(
                                 default_item_types=DEFAULT_ITEM_TYPES,
                                 cart=CartWithElements(request),
                             ),
                             AllResponseField(),
                             NotificationResponseField(),
                             CartFiltersResponseField(),
                             ClearFiltersResponseFieldWithCarts(),
                             ColumnsResponseField(),
                             SortResponseField(),
                             DebugQueryResponseField()
                         ])
    return fr.render()
예제 #7
0
def audit(context, request):
    fr = FieldedResponse(
        _meta={
            'params_parser': ParamsParser(request)
        },
        response_fields=[
            TitleResponseField(
                title=AUDIT_TITLE
            ),
            TypeResponseField(
                at_type=[AUDIT_TITLE]
            ),
            IDResponseField(),
            SearchBaseResponseField(),
            ContextResponseField(),
            AuditMatrixWithFacetsResponseField(
                default_item_types=DEFAULT_ITEM_TYPES
            ),
            NotificationResponseField(),
            FiltersResponseField(),
            TypeOnlyClearFiltersResponseField(),
            DebugQueryResponseField()
        ]
    )
    return fr.render()
예제 #8
0
def summary(context, request):
    fr = FieldedResponse(
        _meta={
            'params_parser': ParamsParser(request)
        },
        response_fields=[
            TitleResponseField(
                title=SUMMARY_TITLE
            ),
            TypeResponseField(
                at_type=[SUMMARY_TITLE]
            ),
            IDResponseField(),
            SearchBaseResponseField(),
            ContextResponseField(),
            BasicMatrixWithFacetsResponseField(
                default_item_types=DEFAULT_ITEM_TYPES,
                matrix_definition_name=SUMMARY_MATRIX
            ),
            NotificationResponseField(),
            FiltersResponseField(),
            TypeOnlyClearFiltersResponseField(),
            DebugQueryResponseField()
        ]
    )
    return fr.render()
예제 #9
0
def mouse_development(context, request):
    fr = FieldedResponse(
        _meta={
            'params_parser': ParamsParser(request)
        },
        response_fields=[
            TitleResponseField(
                title='Mouse Development Matrix'
            ),
            TypeResponseField(
                at_type=['MouseDevelopmentMatrix']
            ),
            IDResponseField(),
            SearchBaseResponseField(),
            ContextResponseField(),
            BasicMatrixWithFacetsResponseField(
                default_item_types=DEFAULT_ITEM_TYPES,
                matrix_definition_name='mouse_development'
            ),
            NotificationResponseField(),
            FiltersResponseField(),
            TypeOnlyClearFiltersResponseField(),
            DebugQueryResponseField()
        ]
    )
    return fr.render()
예제 #10
0
def test_searches_parsers_params_parser_get_advanced_query_filters_empty(
        dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'type=Experiment&type=File&field=status&type!=Item')
    p = ParamsParser(dummy_request)
    assert p.get_advanced_query_filters() == []
예제 #11
0
def test_searches_parsers_params_parser_get_must_filters(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'type=Experiment&type=File&files.file_type!=fastq&field=status&type=*')
    p = ParamsParser(dummy_request)
    assert p.get_must_filters() == [('type', 'Experiment'), ('type', 'File'),
                                    ('field', 'status')]
예제 #12
0
def searchv2_quick(context, request):
    fr = FieldedResponse(
        _meta={'params_parser': ParamsParser(request)},
        response_fields=[
            BasicSearchResponseField(default_item_types=DEFAULT_ITEM_TYPES)
        ])
    return fr.render()
예제 #13
0
def test_searches_parsers_params_parser_get_debug(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'frame=embedded&status!=submitted&type=File&sort=date_created&debug=true'
    )
    p = ParamsParser(dummy_request)
    assert p.get_debug() == [('debug', 'true')]
예제 #14
0
def test_searches_parsers_params_parser_get_field_filters(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'type=Experiment&type=File&field=status&type!=Item'
        '&searchTerm=my+favorite+experiment&searchTerm=my+other+experiment')
    p = ParamsParser(dummy_request)
    assert p.get_field_filters() == [('field', 'status')]
예제 #15
0
def test_searches_parsers_params_parser_get_wildcard_filters(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'status=released&type=*&file_format%21=*'
        '&file_type%21=bigBed+tss_peak&file_format_type=bed3%2B')
    p = ParamsParser(dummy_request)
    assert p.get_wildcard_filters() == [('type', '*'), ('file_format!', '*')]
예제 #16
0
def test_searches_parsers_params_parser_keys_filters_not_flag(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'status=released&status!=submitted&type=File&file_format%21=bigWig')
    p = ParamsParser(dummy_request)
    assert p.get_not_keys_filters() == [('status', 'released'),
                                        ('status!', 'submitted'),
                                        ('type', 'File'),
                                        ('file_format!', 'bigWig')]
    assert p.get_not_keys_filters(not_keys=['status']) == [('type', 'File'),
                                                           ('file_format!',
                                                            'bigWig')]
    assert p.get_not_keys_filters(not_keys=['status', 'file_format']) == [
        ('type', 'File')
    ]
    assert p.get_not_keys_filters(
        not_keys=['status', 'file_format', 'type']) == []
    assert p.get_keys_filters(keys=['status']) == [('status', 'released'),
                                                   ('status!', 'submitted')]
    assert p.get_keys_filters(keys=['status', 'file_format']) == [
        ('status', 'released'), ('status!', 'submitted'),
        ('file_format!', 'bigWig')
    ]
    assert p.get_must_not_match_filters(params=p.get_keys_filters(
        keys=['status', 'file_format'])) == [('status!', 'submitted'),
                                             ('file_format!', 'bigWig')]
    assert p.get_must_match_filters(params=p.get_keys_filters(
        keys=['status', 'file_format'])) == [('status', 'released')]
    assert p.get_query_string(params=p.get_must_match_filters(
        params=p.get_keys_filters(
            keys=['status', 'file_format']))) == 'status=released'
예제 #17
0
def test_searches_parsers_params_parser_get_not_exists_filters(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'type=Experiment&type=File&files.file_type!=fastq'
        '&field=status&type=*&file_size!=*')
    p = ParamsParser(dummy_request)
    assert p.get_not_exists_filters() == [('file_size!', '*')]
예제 #18
0
def test_searches_parsers_params_parser_get_query_string(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'type=File&file_format%21=bigWig&file_type%21=bigBed+tss_peak'
        '&file_format_type=bed3%2B')
    p = ParamsParser(dummy_request)
    assert dummy_request.environ['QUERY_STRING'] == p.get_query_string()
예제 #19
0
def matrixv2_raw(context, request):
    fr = FieldedResponse(_meta={'params_parser': ParamsParser(request)},
                         response_fields=[
                             RawMatrixWithAggsResponseField(
                                 default_item_types=DEFAULT_ITEM_TYPES)
                         ])
    return fr.render()
예제 #20
0
def entex_matrix(context, request):
    fr = FieldedResponse(
        _meta={
            'params_parser': ParamsParser(request)
        },
        response_fields=[
            TitleResponseField(
                title='Epigenomes from four individuals (ENTEx)'
            ),
            TypeResponseField(
                at_type=['EntexMatrix']
            ),
            IDResponseField(),
            SearchBaseResponseField(),
            ContextResponseField(),
            MissingMatrixWithFacetsResponseField(
                default_item_types=DEFAULT_ITEM_TYPES,
                matrix_definition_name='entex'
            ),
            NotificationResponseField(),
            FiltersResponseField(),
            TypeOnlyClearFiltersResponseField(),
            DebugQueryResponseField()
        ]
    )
    return fr.render()
예제 #21
0
def report(context, request):
    fr = FieldedResponse(
        _meta={
            'params_parser': ParamsParser(request)
        },
        response_fields=[
            TitleResponseField(
                title=REPORT_TITLE
            ),
            TypeResponseField(
                at_type=[REPORT_TITLE]
            ),
            IDResponseField(),
            ContextResponseField(),
            BasicReportWithFacetsResponseField(),
            AllResponseField(),
            NotificationResponseField(),
            FiltersResponseField(),
            TypeOnlyClearFiltersResponseField(),
            ColumnsResponseField(),
            NonSortableResponseField(),
            SortResponseField(),
            DebugQueryResponseField()
        ]
    )
    return fr.render()
예제 #22
0
def test_searches_parsers_params_parser_get_mode(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'frame=embedded&status!=submitted&mode=picker&type=File&sort=date_created'
    )
    p = ParamsParser(dummy_request)
    assert p.get_mode() == [('mode', 'picker')]
    assert p.param_values_to_list(params=p.get_mode())[0] == 'picker'
예제 #23
0
def test_searches_parsers_params_parser_is_param(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'type=Experiment&type=File&files.file_type=fastq&field=status')
    p = ParamsParser(dummy_request)
    assert p.is_param(key='type', value='File')
    assert p.is_param(key='files.file_type', value='fastq')
    assert not p.is_param(key='files.file_type', value='bam')
예제 #24
0
def test_searches_parsers_params_parser_param_remove_not_flag(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'frame=embedded&status!=submitted&type=File&sort=date_created')
    p = ParamsParser(dummy_request)
    assert p.remove_not_flag() == [('frame', 'embedded'),
                                   ('status', 'submitted'), ('type', 'File'),
                                   ('sort', 'date_created')]
예제 #25
0
def test_searches_responses_fielded_response_response_factory(dummy_request):
    from snovault.elasticsearch.searches.responses import FieldedResponse
    from snovault.elasticsearch.searches.responses import InMemoryResponse
    from snovault.elasticsearch.searches.responses import StreamedResponse
    from snovault.elasticsearch.searches.parsers import ParamsParser
    fr = FieldedResponse()
    fr.response = {'a': 1}
    assert isinstance(fr._response_factory(), InMemoryResponse)
    fr = FieldedResponse(_meta={'params_parser': ParamsParser(dummy_request)})
    assert isinstance(fr._response_factory(), InMemoryResponse)
    fr.response = {'a': (x for x in [1, 2, 3])}
    assert isinstance(fr._response_factory(), StreamedResponse)
    dummy_request.__parent__ = 'something'
    fr = FieldedResponse(_meta={'params_parser': ParamsParser(dummy_request)})
    assert isinstance(fr._response_factory(), InMemoryResponse)
    fr.response = {'a': (x for x in [1, 2, 3])}
    assert isinstance(fr._response_factory(), InMemoryResponse)
예제 #26
0
def test_searches_parsers_params_parser_get_key_filters(dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'type=Experiment&type=File&status=archived&type!=Item&status!=released'
    )
    p = ParamsParser(dummy_request)
    assert p.get_key_filters(key='status') == [('status', 'archived'),
                                               ('status!', 'released')]
예제 #27
0
def test_searches_parsers_params_parser_get_must_not_match_advanced_query_filters(
        dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'type=Experiment&type=File&field=status&type!=Item'
        '&advancedQuery!=whatever')
    p = ParamsParser(dummy_request)
    assert p.get_must_not_match_advanced_query_filters() == [('advancedQuery!',
                                                              'whatever')]
예제 #28
0
def test_searches_parsers_params_parser_get_filters_by_condition_none(
        dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ[
        'QUERY_STRING'] = 'type=Experiment&type=File&field=status'
    p = ParamsParser(dummy_request)
    assert p.get_filters_by_condition() == [('type', 'Experiment'),
                                            ('type', 'File'),
                                            ('field', 'status')]
예제 #29
0
def test_searches_parsers_params_parser_params_coerce_value_to_int_or_return_none(
        dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ['QUERY_STRING'] = (
        'frame=embedded&status!=submitted&type=File&sort=date_created')
    p = ParamsParser(dummy_request)
    assert p.coerce_value_to_int_or_return_none('12') == 12
    assert p.coerce_value_to_int_or_return_none(12) == 12
    assert p.coerce_value_to_int_or_return_none('all') is None
예제 #30
0
def test_searches_parsers_params_parser_get_filters_by_condition_value_status(
        dummy_request):
    from snovault.elasticsearch.searches.parsers import ParamsParser
    dummy_request.environ[
        'QUERY_STRING'] = 'type=Experiment&type=File&field=status'
    p = ParamsParser(dummy_request)
    assert p.get_filters_by_condition(
        key_and_value_condition=lambda _, v: v == 'status') == [('field',
                                                                 'status')]