[FEAT] cleanup GET /wallet endpoint, add wallet api routes (#1932)
* [FEAT] cleanup GET /wallet endpoint, add wallet api route this removes the functionalitiy to create accounts and wallets via the GET /wallet endpoint in generic.py it add endpoints inside the api.py for it and the frontend is modified to use the api endpoints this also simplifies for the `feat/login` for the route. * remove stale generic tests and add api tests * bug wrong endpoint create account * vlad nitpick * added checkif deleted is 404 * reload after renaming wallet * another iteration with vlad * create new wallet if it none exist * fix delete refresh * formatting
This commit is contained in:
parent
eb73daffe9
commit
5b16f54857
11 changed files with 158 additions and 164 deletions
|
|
@ -23,11 +23,51 @@ from ...helpers import (
|
|||
WALLET = get_wallet_class()
|
||||
|
||||
|
||||
# check if the client is working
|
||||
# create account POST /api/v1/account
|
||||
@pytest.mark.asyncio
|
||||
async def test_core_views_generic(client):
|
||||
response = await client.get("/")
|
||||
async def test_create_account(client):
|
||||
response = await client.post("/api/v1/account", json={"name": "test"})
|
||||
assert response.status_code == 200
|
||||
result = response.json()
|
||||
assert "name" in result
|
||||
assert result["name"] == "test"
|
||||
assert "balance_msat" in result
|
||||
assert "id" in result
|
||||
assert "user" in result
|
||||
|
||||
|
||||
# check POST and DELETE /api/v1/wallet with adminkey:
|
||||
# create additional wallet and delete it
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_wallet_and_delete(client, adminkey_headers_to):
|
||||
response = await client.post(
|
||||
"/api/v1/wallet", json={"name": "test"}, headers=adminkey_headers_to
|
||||
)
|
||||
assert response.status_code == 200
|
||||
result = response.json()
|
||||
assert "name" in result
|
||||
assert result["name"] == "test"
|
||||
assert "balance_msat" in result
|
||||
assert "id" in result
|
||||
assert "adminkey" in result
|
||||
response = await client.delete(
|
||||
"/api/v1/wallet",
|
||||
headers={
|
||||
"X-Api-Key": result["adminkey"],
|
||||
"Content-type": "application/json",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# get deleted wallet
|
||||
response = await client.get(
|
||||
"/api/v1/wallet",
|
||||
headers={
|
||||
"X-Api-Key": result["adminkey"],
|
||||
"Content-type": "application/json",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
# check GET /api/v1/wallet with inkey: wallet info, no balance
|
||||
|
|
|
|||
|
|
@ -7,35 +7,6 @@ async def test_core_views_generic(client):
|
|||
assert response.status_code == 200, f"{response.url} {response.status_code}"
|
||||
|
||||
|
||||
# check GET /wallet: wallet info
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_wallet(client):
|
||||
response = await client.get("wallet")
|
||||
# redirect not modified
|
||||
assert response.status_code == 307, f"{response.url} {response.status_code}"
|
||||
|
||||
|
||||
# check GET /wallet: do not allow redirects, expect code 307
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_wallet_no_redirect(client):
|
||||
response = await client.get("wallet", follow_redirects=False)
|
||||
assert response.status_code == 307, f"{response.url} {response.status_code}"
|
||||
|
||||
# determine the next redirect location
|
||||
request = client.build_request("GET", "wallet")
|
||||
i = 0
|
||||
while request is not None:
|
||||
response = await client.send(request)
|
||||
request = response.next_request
|
||||
if i == 0:
|
||||
# first redirect
|
||||
assert response.status_code == 307, f"{response.url} {response.status_code}"
|
||||
elif i == 1:
|
||||
# then get the actual page
|
||||
assert response.status_code == 200, f"{response.url} {response.status_code}"
|
||||
i += 1
|
||||
|
||||
|
||||
# check GET /wallet: wrong user, expect 400
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_wallet_with_nonexistent_user(client):
|
||||
|
|
@ -43,27 +14,6 @@ async def test_get_wallet_with_nonexistent_user(client):
|
|||
assert response.status_code == 400, f"{response.url} {response.status_code}"
|
||||
|
||||
|
||||
# check GET /wallet: with user
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_wallet_with_user(client, to_user):
|
||||
response = await client.get("wallet", params={"usr": to_user.id})
|
||||
assert response.status_code == 307, f"{response.url} {response.status_code}"
|
||||
|
||||
# determine the next redirect location
|
||||
request = client.build_request("GET", "wallet", params={"usr": to_user.id})
|
||||
i = 0
|
||||
while request is not None:
|
||||
response = await client.send(request)
|
||||
request = response.next_request
|
||||
if i == 0:
|
||||
# first redirect
|
||||
assert response.status_code == 307, f"{response.url} {response.status_code}"
|
||||
elif i == 1:
|
||||
# then get the actual page
|
||||
assert response.status_code == 200, f"{response.url} {response.status_code}"
|
||||
i += 1
|
||||
|
||||
|
||||
# check GET /wallet: wallet and user
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_wallet_with_user_and_wallet(client, to_user, to_wallet):
|
||||
|
|
@ -89,7 +39,7 @@ async def test_get_extensions(client, to_user):
|
|||
|
||||
# check GET /extensions: extensions list wrong user, expect 400
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_extensions_wrong_user(client, to_user):
|
||||
async def test_get_extensions_wrong_user(client):
|
||||
response = await client.get("extensions", params={"usr": "1"})
|
||||
assert response.status_code == 400, f"{response.url} {response.status_code}"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue