From 93bf46354bf43f7412078ad7fa3dbbf43f1ae66a Mon Sep 17 00:00:00 2001 From: Dan Funk Date: Tue, 30 Jun 2020 11:12:28 -0400 Subject: [PATCH] A last minute change to make the API a little clearer and cleaner broke some tests. --- crc/services/lookup_service.py | 22 ++++++++++------------ tests/test_lookup_service.py | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/crc/services/lookup_service.py b/crc/services/lookup_service.py index 97c9824b..e9852315 100644 --- a/crc/services/lookup_service.py +++ b/crc/services/lookup_service.py @@ -20,8 +20,8 @@ class TSRank(GenericFunction): package = 'full_text' name = 'ts_rank' -class LookupService(object): +class LookupService(object): """Provides tools for doing lookups for auto-complete fields. This can currently take two forms: 1) Lookup from spreadsheet data associated with a workflow specification. @@ -51,7 +51,7 @@ class LookupService(object): # if not, we need to rebuild the lookup table. is_current = False if lookup_model: - is_current = db.session.query(WorkflowSpecDependencyFile).\ + is_current = db.session.query(WorkflowSpecDependencyFile). \ filter(WorkflowSpecDependencyFile.file_data_id == lookup_model.file_data_model_id).count() if not is_current: @@ -63,7 +63,7 @@ class LookupService(object): return lookup_model @staticmethod - def lookup(workflow, field_id, query, value, limit): + def lookup(workflow, field_id, query, value=None, limit=10): lookup_model = LookupService.__get_lookup_model(workflow, field_id) @@ -72,8 +72,6 @@ class LookupService(object): else: return LookupService._run_lookup_query(lookup_model, query, value, limit) - - @staticmethod def create_lookup_model(workflow_model, field_id): """ @@ -117,8 +115,8 @@ class LookupService(object): is_ldap=True) else: raise ApiError("unknown_lookup_option", - "Lookup supports using spreadsheet options or ldap options, and neither " - "was provided.") + "Lookup supports using spreadsheet options or ldap options, and neither " + "was provided.") db.session.add(lookup_model) db.session.commit() return lookup_model @@ -199,8 +197,8 @@ class LookupService(object): we return a lookup data model.""" user_list = [] for user in users: - user_list.append( {"value": user['uid'], - "label": user['display_name'] + " (" + user['uid'] + ")", - "data": user - }) - return user_list \ No newline at end of file + user_list.append({"value": user['uid'], + "label": user['display_name'] + " (" + user['uid'] + ")", + "data": user + }) + return user_list diff --git a/tests/test_lookup_service.py b/tests/test_lookup_service.py index 4b7c180d..a27427f4 100644 --- a/tests/test_lookup_service.py +++ b/tests/test_lookup_service.py @@ -66,7 +66,7 @@ class TestLookupService(BaseTest): workflow = self.create_workflow('enum_options_from_file') processor = WorkflowProcessor(workflow) processor.do_engine_steps() - results = LookupService.lookup(workflow, "AllTheNames", "", id=1, limit=10) + results = LookupService.lookup(workflow, "AllTheNames", "", value="1000", limit=10) self.assertEqual(1, len(results), "It is possible to find an item based on the id, rather than as a search") self.assertIsNotNone(results[0].data) self.assertIsInstance(results[0].data, dict)