Skip to content

Commit

Permalink
remove habname from exchange query (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenkan authored Nov 20, 2023
1 parent 2a3f482 commit 843759f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
19 changes: 4 additions & 15 deletions src/keria/peer/exchanging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def loadEnds(app):
app.add_route("/identifiers/{name}/exchanges", exnColEnd)

exnColEnd = ExchangeQueryCollectionEnd()
app.add_route("/identifiers/{name}/exchanges/query", exnColEnd)
app.add_route("/exchanges/query", exnColEnd)

exnResEnd = ExchangeResourceEnd()
app.add_route("/identifiers/{name}/exchanges/{said}", exnResEnd)
app.add_route("/exchanges/{said}", exnResEnd)


class ExchangeCollectionEnd:
Expand Down Expand Up @@ -83,19 +83,15 @@ def on_post(req, rep, name):
class ExchangeQueryCollectionEnd:

@staticmethod
def on_post(req, rep, name):
def on_post(req, rep):
""" POST endpoint for exchange message collection
Args:
req (Request): falcon HTTP request object
rep (Response): falcon HTTP response object
name (str): human readable alias for AID context
"""
agent = req.context.agent
hab = agent.hby.habByName(name)
if hab is None:
raise falcon.HTTPNotFound(description="name is not a valid reference to an identifier")

try:
body = req.get_media()
Expand Down Expand Up @@ -141,23 +137,16 @@ class ExchangeResourceEnd:
""" Exchange message resource endpoint class """

@staticmethod
def on_get(req, rep, name, said):
def on_get(req, rep, said):
"""GET endpoint for exchange message collection
Args:
req (Request): falcon HTTP request object
rep (Response): falcon HTTP response object
name (str): human readable alias for AID context
said (str): qb64 SAID of exchange message to retrieve
"""
agent = req.context.agent

# Get the hab
hab = agent.hby.habByName(name)
if hab is None:
raise falcon.HTTPNotFound(description=f"alias={name} is not a valid reference to an identifier")

serder, pathed = exchanging.cloneMessage(agent.hby, said)

if serder is None:
Expand Down
10 changes: 5 additions & 5 deletions tests/peer/test_exchanging.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ def test_exchange_end(helpers):
agent.exnseeker.index(exn.said)

body = json.dumps({}).encode("utf-8")
res = client.simulate_post(f"/identifiers/aid1/exchanges/query", body=body)
res = client.simulate_post(f"/exchanges/query", body=body)
assert res.status_code == 200
assert len(res.json) == 2

body = json.dumps({'filter': {'-i': pre}, 'sort': ['-dt']}).encode("utf-8")
res = client.simulate_post(f"/identifiers/aid1/exchanges/query", body=body)
res = client.simulate_post(f"/exchanges/query", body=body)
assert res.status_code == 200
assert len(res.json) == 2

Expand All @@ -133,15 +133,15 @@ def test_exchange_end(helpers):
assert serder.said == exn.said

body = json.dumps({'filter': {'-i': pre}, 'sort': ['-dt'], 'skip': 1, "limit": 1}).encode("utf-8")
res = client.simulate_post(f"/identifiers/aid1/exchanges/query", body=body)
res = client.simulate_post(f"/exchanges/query", body=body)
assert res.status_code == 200
assert len(res.json) == 1

ked = res.json[0]['exn']
serder = coring.Serder(ked=ked)
assert serder.said == exn.said

res = client.simulate_get(f"/identifiers/aid1/exchanges/{exn.said}")
res = client.simulate_get(f"/exchanges/{exn.said}")
assert res.status_code == 200
serder = coring.Serder(ked=res.json['exn'])
assert serder.said == exn.said
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_exchange_end(helpers):
agent.exnseeker.index(exn.said)

body = json.dumps({'sort': ['-dt']}).encode("utf-8")
res = client.simulate_post(f"/identifiers/aid1/exchanges/query", body=body)
res = client.simulate_post(f"/exchanges/query", body=body)
assert res.status_code == 200
assert len(res.json) == 3

Expand Down

0 comments on commit 843759f

Please sign in to comment.