diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-03-10 15:18:13 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-03-10 15:18:13 +0200 |
commit | ae85e66e58f09af0161005c2d49f9161f9baf6a7 (patch) | |
tree | 3b2e8fecc6aebb52589d13b737ba602222e1203f /effiapi | |
parent | 654f088bab35aff16cd999a5744b8f045e2cc49b (diff) | |
download | effi-reg-ae85e66e58f09af0161005c2d49f9161f9baf6a7.tar.gz |
Add: /search to effiapi
Diffstat (limited to 'effiapi')
-rwxr-xr-x | effiapi | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -114,6 +114,9 @@ class FakeHTTPAPI(HTTPAPI): if url.endswith('/status'): return self._get_status() + if url.endswith('/search'): + return self._get_search(body) + if url.endswith('/res'): return self._get_resource(headers) @@ -124,7 +127,37 @@ class FakeHTTPAPI(HTTPAPI): body = { 'resources': len(self._memb), } - return FakeResponse(200, {}, body=json.dumps(body)) + return FakeResponse(200, {}, json.dumps(body)) + + def _get_search(self, body): + cond = json.loads(body) + logging.debug('_get_search: cond: %r', cond) + matches = [ + rid + for rid in self._memb + if self._matches_cond(rid, cond) + ] + + headers = { + 'Content-Type': 'application/json', + } + result = { + 'resources': matches, + } + return FakeResponse(200, headers, json.dumps(result)) + + def _matches_cond(self, rid, cond): + assert cond == { + 'cond': [ + { + 'where': 'meta', + 'op': '>=', + 'field': 'id', + 'pattern': '', + } + ] + } + return True def _get_resource(self, headers): if headers is None: @@ -340,7 +373,9 @@ class API: return response(404, None, str(e)) def _search(self): + logging.debug('_search callback called') cond = bottle.request.json + logging.debug('_search callback: %r', cond) result = self._muck.search(cond) return response(200, None, result) |