@@ -453,6 +453,62 @@ def test_search_filter_with_percent_in_column_name(self):
453453 result = helpers .call_action ("datastore_search" , ** search_data )
454454 assert result ["total" ] == 1
455455
456+ @pytest .mark .ckan_config ("ckan.plugins" , "datastore" )
457+ @pytest .mark .usefixtures ("clean_datastore" , "with_plugins" )
458+ def test_search_sort_nulls_first_last (self ):
459+ resource = factories .Resource ()
460+ data = {
461+ "resource_id" : resource ["id" ],
462+ "force" : True ,
463+ "records" : [{"a" : 1 , "b" : "Y" }, {"b" : "Z" }],
464+ }
465+ helpers .call_action ("datastore_create" , ** data )
466+
467+ search_data = {
468+ "resource_id" : data ["resource_id" ],
469+ "sort" : [u"a desc nulls last" ],
470+ }
471+ result = helpers .call_action ("datastore_search" , ** search_data )
472+ assert result ["records" ][0 ]['b' ] == 'Y'
473+
474+ search_data = {
475+ "resource_id" : data ["resource_id" ],
476+ "sort" : [u"a desc nulls first" ],
477+ }
478+ result = helpers .call_action ("datastore_search" , ** search_data )
479+ assert result ["records" ][0 ]['b' ] == 'Z'
480+
481+ @pytest .mark .ckan_config ("ckan.plugins" , "datastore" )
482+ @pytest .mark .usefixtures ("clean_datastore" , "with_plugins" )
483+ def test_search_records_text_int_filter (self ):
484+ resource = factories .Resource ()
485+ data = {
486+ "resource_id" : resource ["id" ],
487+ "force" : True ,
488+ "fields" : [
489+ {"id" : "text_field" , "type" : "text" },
490+ ],
491+ "records" : [
492+ {"text_field" : 25 },
493+ {"text_field" : 37 },
494+ ],
495+ }
496+ helpers .call_action ("datastore_create" , ** data )
497+
498+ # can search by int
499+ data = {"resource_id" : resource ["id" ],
500+ "include_total" : True ,
501+ "filters" : {"text_field" : 25 }}
502+ result = helpers .call_action ("datastore_search" , ** data )
503+ assert len (result ["records" ]) == 1
504+
505+ # can search by text
506+ data = {"resource_id" : resource ["id" ],
507+ "include_total" : True ,
508+ "filters" : {"text_field" : "37" }}
509+ result = helpers .call_action ("datastore_search" , ** data )
510+ assert len (result ["records" ]) == 1
511+
456512
457513@pytest .mark .usefixtures ("with_request_context" )
458514class TestDatastoreSearchLegacyTests (object ):
@@ -770,25 +826,6 @@ def test_search_filters_get(self, app):
770826 assert result ["total" ] == 1
771827 assert result ["records" ] == [self .expected_records [0 ]]
772828
773- @pytest .mark .ckan_config ("ckan.plugins" , "datastore" )
774- @pytest .mark .usefixtures ("clean_datastore" , "with_plugins" )
775- def test_search_invalid_filter (self , app ):
776- data = {
777- "resource_id" : self .data ["resource_id" ],
778- # invalid because author is not a numeric field
779- "filters" : {u"author" : 42 },
780- }
781-
782- auth = {"Authorization" : self .sysadmin_token }
783- res = app .post (
784- "/api/action/datastore_search" ,
785- json = data ,
786- extra_environ = auth ,
787- status = 409 ,
788- )
789- res_dict = json .loads (res .data )
790- assert res_dict ["success" ] is False
791-
792829 @pytest .mark .ckan_config ("ckan.plugins" , "datastore" )
793830 @pytest .mark .usefixtures ("clean_datastore" , "with_plugins" )
794831 def test_search_sort (self , app ):
0 commit comments