mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
change(fastapi): rework /rpc (get)
This reworks the base implementation of the RPC to use a class called RPC for handling of requests. Took a bit of a different approach than PHP in terms of exposed methods, but it does end up achieving the same goal, with one additional error: "Request type '{type}' is not yet implemented." For FastAPI development, we'll stick with: - If the supplied 'type' argument has an alias mapping in RPC.ALIASES, we convert the type argument over to its alias before doing anything. Example: 'info' is aliased to 'multiinfo', so when a user requests type=info, it is converted to type=multiinfo. - If the type does not exist in RPC.EXPOSED_TYPES, the following error is produced: "No request type/data specified." - If the type **does** exist in RPC.EXPOSED_TYPES, but does not have an implemented `RPC._handle_{type}_type` function, the following error is produced: "Request type '{type}' is not yet implemented." Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
30ab45f459
commit
7c4fb539d8
3 changed files with 227 additions and 255 deletions
|
@ -3,6 +3,7 @@ import pytest
|
|||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from aurweb import db, scripts
|
||||
from aurweb.asgi import app
|
||||
from aurweb.db import begin, create, query
|
||||
from aurweb.models.account_type import AccountType
|
||||
|
@ -173,6 +174,9 @@ def setup():
|
|||
PackageBase=pkgbase1,
|
||||
VoteTS=5000)
|
||||
|
||||
conn = db.ConnectionExecutor(db.get_engine().raw_connection())
|
||||
scripts.popupdate.run_single(conn, pkgbase1)
|
||||
|
||||
|
||||
def test_rpc_singular_info():
|
||||
# Define expected response.
|
||||
|
@ -284,7 +288,7 @@ def test_rpc_no_dependencies():
|
|||
'Description': 'Wubby wubby on wobba wuubu',
|
||||
'URL': 'https://example.com/',
|
||||
'PackageBase': 'chungy-chungus',
|
||||
'NumVotes': 3,
|
||||
'NumVotes': 0,
|
||||
'Popularity': 0.0,
|
||||
'OutOfDate': None,
|
||||
'Maintainer': 'user1',
|
||||
|
@ -428,3 +432,12 @@ def test_rpc_suggest_pkgbase():
|
|||
response = make_request("/rpc?v=5&type=suggest-pkgbase&arg=chungy")
|
||||
data = response.json()
|
||||
assert data == ["chungy-chungus"]
|
||||
|
||||
|
||||
def test_rpc_unimplemented_types():
|
||||
unimplemented = ["search", "msearch", "suggest"]
|
||||
for type in unimplemented:
|
||||
response = make_request(f"/rpc?v=5&type={type}&arg=big")
|
||||
data = response.json()
|
||||
expected = f"Request type '{type}' is not yet implemented."
|
||||
assert data.get("error") == expected
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue