Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove habname from exchange query #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -118,12 +118,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 @@ -136,15 +136,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 @@ -179,7 +179,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