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()
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')]
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()
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]
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()
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()
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()
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()
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()
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() == []
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')]
def searchv2_quick(context, request): fr = FieldedResponse( _meta={'params_parser': ParamsParser(request)}, response_fields=[ BasicSearchResponseField(default_item_types=DEFAULT_ITEM_TYPES) ]) return fr.render()
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')]
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')]
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!', '*')]
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'
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!', '*')]
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()
def matrixv2_raw(context, request): fr = FieldedResponse(_meta={'params_parser': ParamsParser(request)}, response_fields=[ RawMatrixWithAggsResponseField( default_item_types=DEFAULT_ITEM_TYPES) ]) return fr.render()
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()
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()
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'
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')
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')]
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)
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')]
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')]
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')]
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
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')]