[tests] Ported other hood webAPI tests to async

This commit is contained in:
missytake 2023-04-01 14:41:13 +02:00
parent c1b8ad2984
commit 6b6a2777bb
2 changed files with 61 additions and 33 deletions

View file

@ -12,6 +12,7 @@ async def test_hoods_unauthorized(asyncclient):
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_hoods_success(client, auth_header):
response = client.get("/api/admin/hoods/", headers=auth_header)
@pytest.mark.anyio
async def test_hoods_success(asyncclient, auth_header):
response = await asyncclient.get("/api/admin/hoods/", headers=auth_header)
assert response.status_code == status.HTTP_200_OK

View file

@ -3,80 +3,107 @@
# Copyright (C) 2020 by Martin Rey <martin.rey@mailbox.org>
#
# SPDX-License-Identifier: 0BSD
import pytest
from fastapi import status
def test_hood_read_all(client):
response = client.get("/api/hoods/")
@pytest.mark.anyio
async def test_hood_read_all(asyncclient):
response = await asyncclient.get("/api/hoods/")
assert response.status_code == status.HTTP_200_OK
def test_hood_create_unauthorized(client, hood_id):
response = client.post("/api/hoods/")
@pytest.mark.anyio
async def test_hood_create_unauthorized(asyncclient, hood_id):
response = await asyncclient.post("/api/hoods/")
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_hood_read(client, hood_id):
response = client.get("/api/hoods/{0}".format(hood_id))
@pytest.mark.anyio
async def test_hood_read(asyncclient, hood_id):
response = await asyncclient.get("/api/hoods/{0}".format(hood_id))
assert response.status_code == status.HTTP_200_OK
def test_hood_update_unauthorized(client, hood_id):
response = client.put("/api/hoods/{0}".format(hood_id))
@pytest.mark.anyio
async def test_hood_update_unauthorized(asyncclient, hood_id):
response = await asyncclient.put("/api/hoods/{0}".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_hood_delete_unauthorized(client, hood_id):
response = client.delete("/api/hoods/{0}".format(hood_id))
@pytest.mark.anyio
async def test_hood_delete_unauthorized(asyncclient, hood_id):
response = await asyncclient.delete("/api/hoods/{0}".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_trigger_read_all_unauthorized(client, hood_id):
response = client.get("/api/hoods/{0}/triggers/".format(hood_id))
@pytest.mark.anyio
async def test_trigger_read_all_unauthorized(asyncclient, hood_id):
response = await asyncclient.get("/api/hoods/{0}/triggers/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_trigger_create_unauthorized(client, hood_id):
response = client.post("/api/hoods/{0}/triggers/".format(hood_id))
@pytest.mark.anyio
async def test_trigger_create_unauthorized(asyncclient, hood_id):
response = await asyncclient.post("/api/hoods/{0}/triggers/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_trigger_read_unauthorized(client, hood_id, trigger_id):
response = client.get("/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id))
@pytest.mark.anyio
async def test_trigger_read_unauthorized(asyncclient, hood_id, trigger_id):
response = await asyncclient.get(
"/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id)
)
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_trigger_update_unauthorized(client, hood_id, trigger_id):
response = client.put("/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id))
@pytest.mark.anyio
async def test_trigger_update_unauthorized(asyncclient, hood_id, trigger_id):
response = await asyncclient.put(
"/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id)
)
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_trigger_delete_unauthorized(client, hood_id, trigger_id):
response = client.delete("/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id))
@pytest.mark.anyio
async def test_trigger_delete_unauthorized(asyncclient, hood_id, trigger_id):
response = await asyncclient.delete(
"/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id)
)
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_badword_read_all_unauthorized(client, hood_id):
response = client.get("/api/hoods/{0}/badwords/".format(hood_id))
@pytest.mark.anyio
async def test_badword_read_all_unauthorized(asyncclient, hood_id):
response = await asyncclient.get("/api/hoods/{0}/badwords/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_badword_create_unauthorized(client, hood_id):
response = client.post("/api/hoods/{0}/badwords/".format(hood_id))
@pytest.mark.anyio
async def test_badword_create_unauthorized(asyncclient, hood_id):
response = await asyncclient.post("/api/hoods/{0}/badwords/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_badword_read_unauthorized(client, hood_id, badword_id):
response = client.get("/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id))
@pytest.mark.anyio
async def test_badword_read_unauthorized(asyncclient, hood_id, badword_id):
response = await asyncclient.get(
"/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id)
)
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_badword_update_unauthorized(client, hood_id, badword_id):
response = client.put("/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id))
@pytest.mark.anyio
async def test_badword_update_unauthorized(asyncclient, hood_id, badword_id):
response = await asyncclient.put(
"/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id)
)
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_badword_delete_unauthorized(client, hood_id, badword_id):
response = client.delete("/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id))
@pytest.mark.anyio
async def test_badword_delete_unauthorized(asyncclient, hood_id, badword_id):
response = await asyncclient.delete(
"/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id)
)
assert response.status_code == status.HTTP_401_UNAUTHORIZED