Skip to content

Commit

Permalink
dbio.wsgi.project: fix sorting problem; fix mongo project test
Browse files Browse the repository at this point in the history
  • Loading branch information
RayPlante committed Apr 2, 2024
1 parent 88e1977 commit 01b3e93
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
15 changes: 6 additions & 9 deletions python/nistoar/midas/dbio/wsgi/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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()]

Expand Down Expand Up @@ -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]:
"""
Expand Down
27 changes: 18 additions & 9 deletions python/tests/nistoar/midas/dbio/wsgi/test_project_midas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 01b3e93

Please sign in to comment.