diff --git a/python/nistoar/midas/dbio/wsgi/project.py b/python/nistoar/midas/dbio/wsgi/project.py index edf90a5..aca9bce 100644 --- a/python/nistoar/midas/dbio/wsgi/project.py +++ b/python/nistoar/midas/dbio/wsgi/project.py @@ -49,6 +49,7 @@ from ... import dbio from ...dbio import ProjectRecord, ProjectService, ProjectServiceFactory from .base import DBIOHandler +from .search_sorter import SortByPerm __all__ = ["MIDASProjectHandler", "ProjectDataHandler"] @@ -455,7 +456,7 @@ def do_GET(self, path, ashead=False): # sort the results by the best permission type permitted sortd = SortByPerm() - for rec in self._selected_records(perms): + for rec in self._select_records(perms): sortd.add_record(rec) out = [rec.to_dict() for rec in sortd.sorted()] @@ -489,16 +490,12 @@ def adv_select_records(self, input: Mapping): perms = [ dbio.ACLs.OWN ] # sort the results by the best permission type permitted - #sortd = SortByPerm() - result=[] + sortd = SortByPerm() for rec in self._adv_select_records(filter, perms): - #sortd.add_record(rec) - result.append(rec.to_dict()) + sortd.add_record(rec) - #out = [rec.to_dict() for rec in sortd.sorted()] - #return rec - return result - #return self.send_json(result, ashead=ashead) + out = [rec.to_dict() for rec in sortd.sorted()] + return self.send_json(out, ashead=ashead) def _adv_select_records(self, filter, perms) -> Iterator[ProjectRecord]: """ diff --git a/python/tests/nistoar/midas/dbio/wsgi/test_project_midas.py b/python/tests/nistoar/midas/dbio/wsgi/test_project_midas.py index cc670a5..811d36a 100644 --- a/python/tests/nistoar/midas/dbio/wsgi/test_project_midas.py +++ b/python/tests/nistoar/midas/dbio/wsgi/test_project_midas.py @@ -50,27 +50,36 @@ def tostr(self, resplist): def setUp(self): self.cfg = { - "broker": { - "clients": { - "midas": { - "default_shoulder": "mdm1" - }, - "default": { - "default_shoulder": "mdm0" - } + "clients": { + "midas": { + "default_shoulder": "mdm1" + }, + "default": { + "default_shoulder": "mdm0" } }, "dbio": { "superusers": [ "rlp" ], "allowed_project_shoulders": ["mdm1", "spc1"], "default_shoulder": "mdm0" + }, + "include_headers": { + "Access-Control-Allow-Origin": "*" } } self.dbfact = mongo.MongoDBClientFactory({}, os.environ['MONGO_TESTDB_URL']) - self.app = prj.MIDASProjectApp(base.DMP_PROJECTS, rootlog.getChild("dmpapi"), self.dbfact, self.cfg) + self.svcfact = prj.ProjectServiceFactory(base.DMP_PROJECTS, self.dbfact, self.cfg, + rootlog.getChild("midas.prj")) + self.app = prj.MIDASProjectApp(self.svcfact, rootlog.getChild("dmpapi"), self.cfg) self.resp = [] self.rootpath = "/midas/dmp/" + def tearDown(self): + cli = self.dbfact.create_client(base.DMP_PROJECTS) + cli.native.drop_collection("dmp") + cli.native.drop_collection("nextnum") + cli.native.drop_collection("prov_action_log") + def create_record(self, name="goob", meta=None): cli = self.dbfact.create_client(base.DMP_PROJECTS, self.cfg["dbio"], nistr.actor) out = cli.create_record(name, "mdm1")