[test] webpush_api endpoints (#2534)
* test: webpush_api endpoints * fix: SQL quote for `user`
This commit is contained in:
parent
ae60b4517c
commit
93965bc5b6
3 changed files with 98 additions and 6 deletions
89
tests/api/test_webpush_api.py
Normal file
89
tests/api/test_webpush_api.py
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
from http import HTTPStatus
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create___bad_body(client, adminkey_headers_from):
|
||||
response = await client.post(
|
||||
"/api/v1/webpush",
|
||||
headers=adminkey_headers_from,
|
||||
json={"subscription": "bad_json"},
|
||||
)
|
||||
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create___missing_fields(client, adminkey_headers_from):
|
||||
response = await client.post(
|
||||
"/api/v1/webpush",
|
||||
headers=adminkey_headers_from,
|
||||
json={"subscription": """{"a": "x"}"""},
|
||||
)
|
||||
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create___bad_access_key(client, inkey_headers_from):
|
||||
response = await client.post(
|
||||
"/api/v1/webpush",
|
||||
headers=inkey_headers_from,
|
||||
json={"subscription": """{"a": "x"}"""},
|
||||
)
|
||||
assert response.status_code == HTTPStatus.UNAUTHORIZED
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete__bad_endpoint_format(client, adminkey_headers_from):
|
||||
response = await client.delete(
|
||||
"/api/v1/webpush",
|
||||
params={"endpoint": "https://this.should.be.base64.com"},
|
||||
headers=adminkey_headers_from,
|
||||
)
|
||||
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete__no_endpoint_param(client, adminkey_headers_from):
|
||||
response = await client.delete(
|
||||
"/api/v1/webpush",
|
||||
headers=adminkey_headers_from,
|
||||
)
|
||||
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete__no_endpoint_found(client, adminkey_headers_from):
|
||||
response = await client.delete(
|
||||
"/api/v1/webpush",
|
||||
params={"endpoint": "aHR0cHM6Ly9kZW1vLmxuYml0cy5jb20="},
|
||||
headers=adminkey_headers_from,
|
||||
)
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json()["count"] == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete__bad_access_key(client, inkey_headers_from):
|
||||
response = await client.delete(
|
||||
"/api/v1/webpush",
|
||||
headers=inkey_headers_from,
|
||||
)
|
||||
assert response.status_code == HTTPStatus.UNAUTHORIZED
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_and_delete(client, adminkey_headers_from):
|
||||
response = await client.post(
|
||||
"/api/v1/webpush",
|
||||
headers=adminkey_headers_from,
|
||||
json={"subscription": """{"endpoint": "https://demo.lnbits.com"}"""},
|
||||
)
|
||||
assert response.status_code == HTTPStatus.CREATED
|
||||
response = await client.delete(
|
||||
"/api/v1/webpush",
|
||||
params={"endpoint": "aHR0cHM6Ly9kZW1vLmxuYml0cy5jb20="},
|
||||
headers=adminkey_headers_from,
|
||||
)
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json()["count"] == 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue