-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tests] Make HTTP endpoints testable
It is now possible to write API tests with the test client of aiohttp. Added an example test that checks that the /version endpoint returns the expected version. Refactored the declaration of endpoints in the initialization of the app. We now have a `register_routes` function centralized in a single module. All references to the global app object inside the implementation of endpoints were replaced by accesses to `request.app`. This allows to import the app object, configured properly, without importing other files.
- Loading branch information
1 parent
f2193ec
commit 2a39689
Showing
15 changed files
with
89 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,62 @@ | ||
from aiohttp import web | ||
import pkg_resources | ||
|
||
from aleph.web.controllers import ( | ||
main, | ||
aggregates, | ||
channels, | ||
info, | ||
ipfs, | ||
storage, | ||
p2p, | ||
main, | ||
messages, | ||
aggregates, | ||
p2p, | ||
posts, | ||
stats, | ||
channels, | ||
listener, | ||
info, | ||
storage, | ||
version, | ||
) | ||
|
||
|
||
def register_routes(app: web.Application): | ||
app.router.add_static( | ||
"/static/", | ||
path=pkg_resources.resource_filename("aleph.web", "static/"), | ||
name="static", | ||
) | ||
app.router.add_get("/", main.index) | ||
app.router.add_get("/api/ws0/status", main.status_ws) | ||
app.router.add_get("/metrics", main.metrics) | ||
app.router.add_get("/metrics.json", main.metrics_json) | ||
|
||
app.router.add_get( | ||
"/api/v0/aggregates/{address}.json", aggregates.address_aggregate | ||
) | ||
|
||
app.router.add_get("/api/v0/channels/list.json", channels.used_channels) | ||
|
||
app.router.add_get("/api/v0/info/public.json", info.public_multiaddress) | ||
|
||
app.router.add_post("/api/v0/ipfs/add_file", ipfs.ipfs_add_file) | ||
|
||
app.router.add_get("/api/v0/messages.json", messages.view_messages_list) | ||
app.router.add_get("/api/v0/messages/page/{page}.json", messages.view_messages_list) | ||
app.router.add_get("/api/ws0/messages", messages.messages_ws) | ||
|
||
app.router.add_post("/api/v0/ipfs/pubsub/pub", p2p.pub_json) | ||
app.router.add_post("/api/v0/p2p/pubsub/pub", p2p.pub_json) | ||
|
||
app.router.add_get("/api/v0/posts.json", posts.view_posts_list) | ||
app.router.add_get("/api/v0/posts/page/{page}.json", posts.view_posts_list) | ||
|
||
app.router.add_get("/api/v0/addresses/stats.json", stats.addresses_stats_view) | ||
|
||
app.router.add_post("/api/v0/ipfs/add_json", storage.add_ipfs_json_controller) | ||
app.router.add_post("/api/v0/storage/add_json", storage.add_storage_json_controller) | ||
app.router.add_post("/api/v0/storage/add_file", storage.storage_add_file) | ||
app.router.add_get("/api/v0/storage/{hash}", storage.get_hash) | ||
app.router.add_get("/api/v0/storage/raw/{hash}", storage.get_raw_hash) | ||
app.router.add_get( | ||
"/api/v0/storage/count/{hash}", storage.get_file_references_count | ||
) | ||
|
||
app.router.add_get("/version", version.version) | ||
app.router.add_get("/api/v0/version", version.version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
from aiohttp import web | ||
from aleph.web import app | ||
|
||
|
||
async def public_multriaddres(request): | ||
"""Broadcast public node adresses | ||
async def public_multiaddress(request): | ||
"""Broadcast public node addresses | ||
According to multriaddr spec https://multiformats.io/multiaddr/ | ||
According to multiaddr spec https://multiformats.io/multiaddr/ | ||
""" | ||
|
||
output = { | ||
"node_multi_addresses": request.config_dict["extra_config"]["public_adresses"], | ||
} | ||
return web.json_response(output) | ||
|
||
|
||
app.router.add_get("/api/v0/info/public.json", public_multriaddres) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from aiohttp import web | ||
from aleph import __version__ | ||
|
||
|
||
async def version(request): | ||
"""Version endpoint.""" | ||
|
||
response = web.json_response({"version": __version__}) | ||
return response |
Oops, something went wrong.