[tests] Rename asyncclient into client

This commit is contained in:
missytake 2023-04-01 15:32:10 +02:00
parent f829bf8694
commit c468543fa5
14 changed files with 142 additions and 154 deletions

View file

@ -21,7 +21,7 @@ def anyio_backend():
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def asyncclient(): def client():
Mapping.drop_all() Mapping.drop_all()
Mapping.create_all() Mapping.create_all()
app = FastAPI() app = FastAPI()
@ -54,8 +54,8 @@ def receive_email(monkeymodule):
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
@pytest.mark.anyio @pytest.mark.anyio
async def register_token(asyncclient, receive_email): async def register_token(client, receive_email):
response = await asyncclient.post( response = await client.post(
"/api/admin/register/", json={"email": "user", "password": "password"} "/api/admin/register/", json={"email": "user", "password": "password"}
) )
assert response.status_code == status.HTTP_202_ACCEPTED assert response.status_code == status.HTTP_202_ACCEPTED
@ -64,15 +64,15 @@ async def register_token(asyncclient, receive_email):
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
@pytest.mark.anyio @pytest.mark.anyio
async def register_confirmed(asyncclient, register_token): async def register_confirmed(client, register_token):
response = await asyncclient.post("/api/admin/confirm/{0}".format(register_token)) response = await client.post("/api/admin/confirm/{0}".format(register_token))
assert response.status_code == status.HTTP_200_OK assert response.status_code == status.HTTP_200_OK
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
@pytest.mark.anyio @pytest.mark.anyio
async def access_token(asyncclient, register_confirmed): async def access_token(client, register_confirmed):
response = await asyncclient.post( response = await client.post(
"/api/admin/login/", data={"username": "user", "password": "password"} "/api/admin/login/", data={"username": "user", "password": "password"}
) )
assert response.status_code == status.HTTP_200_OK assert response.status_code == status.HTTP_200_OK
@ -86,20 +86,20 @@ def auth_header(access_token):
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
@pytest.mark.anyio @pytest.mark.anyio
async def hood_id(asyncclient, auth_header): async def hood_id(client, auth_header):
response = await asyncclient.post( response = await client.post(
"/api/hoods/", json={"name": "hood"}, headers=auth_header "/api/hoods/", json={"name": "hood"}, headers=auth_header
) )
assert response.status_code == status.HTTP_201_CREATED assert response.status_code == status.HTTP_201_CREATED
hood_id = int(response.headers["Location"]) hood_id = int(response.headers["Location"])
yield hood_id yield hood_id
await asyncclient.delete("/api/hoods/{0}".format(hood_id), headers=auth_header) await client.delete("/api/hoods/{0}".format(hood_id), headers=auth_header)
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
@pytest.mark.anyio @pytest.mark.anyio
async def trigger_id(asyncclient, hood_id, auth_header): async def trigger_id(client, hood_id, auth_header):
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/triggers/".format(hood_id), "/api/hoods/{0}/triggers/".format(hood_id),
json={"pattern": "test"}, json={"pattern": "test"},
headers=auth_header, headers=auth_header,
@ -107,15 +107,15 @@ async def trigger_id(asyncclient, hood_id, auth_header):
assert response.status_code == status.HTTP_201_CREATED assert response.status_code == status.HTTP_201_CREATED
trigger_id = int(response.headers["Location"]) trigger_id = int(response.headers["Location"])
yield trigger_id yield trigger_id
await asyncclient.delete( await client.delete(
"/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id), headers=auth_header "/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id), headers=auth_header
) )
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
@pytest.mark.anyio @pytest.mark.anyio
async def badword_id(asyncclient, hood_id, auth_header): async def badword_id(client, hood_id, auth_header):
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/badwords/".format(hood_id), "/api/hoods/{0}/badwords/".format(hood_id),
json={"pattern": ""}, json={"pattern": ""},
headers=auth_header, headers=auth_header,
@ -123,20 +123,20 @@ async def badword_id(asyncclient, hood_id, auth_header):
assert response.status_code == status.HTTP_201_CREATED assert response.status_code == status.HTTP_201_CREATED
badword_id = int(response.headers["Location"]) badword_id = int(response.headers["Location"])
yield badword_id yield badword_id
await asyncclient.delete( await client.delete(
"/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id), headers=auth_header "/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id), headers=auth_header
) )
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
@pytest.mark.anyio @pytest.mark.anyio
async def test_id(asyncclient, hood_id, auth_header): async def test_id(client, hood_id, auth_header):
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/test/".format(hood_id), json={}, headers=auth_header "/api/hoods/{0}/test/".format(hood_id), json={}, headers=auth_header
) )
assert response.status_code == status.HTTP_201_CREATED assert response.status_code == status.HTTP_201_CREATED
test_id = int(response.headers["Location"]) test_id = int(response.headers["Location"])
yield test_id yield test_id
await asyncclient.delete( await client.delete(
"/api/hoods/{0}/test/{1}".format(hood_id, test_id), headers=auth_header "/api/hoods/{0}/test/{1}".format(hood_id, test_id), headers=auth_header
) )

View file

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

View file

@ -8,102 +8,102 @@ from fastapi import status
@pytest.mark.anyio @pytest.mark.anyio
async def test_hood_read_all(asyncclient): async def test_hood_read_all(client):
response = await asyncclient.get("/api/hoods/") response = await client.get("/api/hoods/")
assert response.status_code == status.HTTP_200_OK assert response.status_code == status.HTTP_200_OK
@pytest.mark.anyio @pytest.mark.anyio
async def test_hood_create_unauthorized(asyncclient, hood_id): async def test_hood_create_unauthorized(client, hood_id):
response = await asyncclient.post("/api/hoods/") response = await client.post("/api/hoods/")
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_hood_read(asyncclient, hood_id): async def test_hood_read(client, hood_id):
response = await asyncclient.get("/api/hoods/{0}".format(hood_id)) response = await client.get("/api/hoods/{0}".format(hood_id))
assert response.status_code == status.HTTP_200_OK assert response.status_code == status.HTTP_200_OK
@pytest.mark.anyio @pytest.mark.anyio
async def test_hood_update_unauthorized(asyncclient, hood_id): async def test_hood_update_unauthorized(client, hood_id):
response = await asyncclient.put("/api/hoods/{0}".format(hood_id)) response = await client.put("/api/hoods/{0}".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_hood_delete_unauthorized(asyncclient, hood_id): async def test_hood_delete_unauthorized(client, hood_id):
response = await asyncclient.delete("/api/hoods/{0}".format(hood_id)) response = await client.delete("/api/hoods/{0}".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_trigger_read_all_unauthorized(asyncclient, hood_id): async def test_trigger_read_all_unauthorized(client, hood_id):
response = await asyncclient.get("/api/hoods/{0}/triggers/".format(hood_id)) response = await client.get("/api/hoods/{0}/triggers/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_trigger_create_unauthorized(asyncclient, hood_id): async def test_trigger_create_unauthorized(client, hood_id):
response = await asyncclient.post("/api/hoods/{0}/triggers/".format(hood_id)) response = await client.post("/api/hoods/{0}/triggers/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_trigger_read_unauthorized(asyncclient, hood_id, trigger_id): async def test_trigger_read_unauthorized(client, hood_id, trigger_id):
response = await asyncclient.get( response = await client.get(
"/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id) "/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id)
) )
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_trigger_update_unauthorized(asyncclient, hood_id, trigger_id): async def test_trigger_update_unauthorized(client, hood_id, trigger_id):
response = await asyncclient.put( response = await client.put(
"/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id) "/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id)
) )
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_trigger_delete_unauthorized(asyncclient, hood_id, trigger_id): async def test_trigger_delete_unauthorized(client, hood_id, trigger_id):
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id) "/api/hoods/{0}/triggers/{1}".format(hood_id, trigger_id)
) )
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_badword_read_all_unauthorized(asyncclient, hood_id): async def test_badword_read_all_unauthorized(client, hood_id):
response = await asyncclient.get("/api/hoods/{0}/badwords/".format(hood_id)) response = await client.get("/api/hoods/{0}/badwords/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_badword_create_unauthorized(asyncclient, hood_id): async def test_badword_create_unauthorized(client, hood_id):
response = await asyncclient.post("/api/hoods/{0}/badwords/".format(hood_id)) response = await client.post("/api/hoods/{0}/badwords/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_badword_read_unauthorized(asyncclient, hood_id, badword_id): async def test_badword_read_unauthorized(client, hood_id, badword_id):
response = await asyncclient.get( response = await client.get(
"/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id) "/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id)
) )
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_badword_update_unauthorized(asyncclient, hood_id, badword_id): async def test_badword_update_unauthorized(client, hood_id, badword_id):
response = await asyncclient.put( response = await client.put(
"/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id) "/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id)
) )
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_badword_delete_unauthorized(asyncclient, hood_id, badword_id): async def test_badword_delete_unauthorized(client, hood_id, badword_id):
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id) "/api/hoods/{0}/badwords/{1}".format(hood_id, badword_id)
) )
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED

View file

@ -11,8 +11,8 @@ import pytest
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
@pytest.mark.anyio @pytest.mark.anyio
async def email_row(asyncclient, hood_id, auth_header): async def email_row(client, hood_id, auth_header):
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/email/".format(hood_id), "/api/hoods/{0}/email/".format(hood_id),
json={"name": "kibicara-test"}, json={"name": "kibicara-test"},
headers=auth_header, headers=auth_header,
@ -20,6 +20,6 @@ async def email_row(asyncclient, hood_id, auth_header):
assert response.status_code == status.HTTP_201_CREATED assert response.status_code == status.HTTP_201_CREATED
email_id = int(response.headers["Location"]) email_id = int(response.headers["Location"])
yield response.json() yield response.json()
await asyncclient.delete( await client.delete(
"/api/hoods/{0}/email/{1}".format(hood_id, email_id), headers=auth_header "/api/hoods/{0}/email/{1}".format(hood_id, email_id), headers=auth_header
) )

View file

@ -14,8 +14,8 @@ from kibicara.webapi.admin import to_token
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_subscribe_unsubscribe(asyncclient, hood_id, receive_email): async def test_email_subscribe_unsubscribe(client, hood_id, receive_email):
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/email/subscribe/".format(hood_id), "/api/hoods/{0}/email/subscribe/".format(hood_id),
json={"email": "test@localhost"}, json={"email": "test@localhost"},
) )
@ -28,33 +28,33 @@ async def test_email_subscribe_unsubscribe(asyncclient, hood_id, receive_email):
body, body,
)[0] )[0]
start = len("token=") start = len("token=")
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/email/subscribe/confirm/{1}".format( "/api/hoods/{0}/email/subscribe/confirm/{1}".format(
hood_id, urlparse(confirm_url).query[start:] hood_id, urlparse(confirm_url).query[start:]
) )
) )
assert response.status_code == status.HTTP_201_CREATED assert response.status_code == status.HTTP_201_CREATED
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/email/subscribe/confirm/{1}".format( "/api/hoods/{0}/email/subscribe/confirm/{1}".format(
hood_id, urlparse(confirm_url).query[start:] hood_id, urlparse(confirm_url).query[start:]
) )
) )
assert response.status_code == status.HTTP_409_CONFLICT assert response.status_code == status.HTTP_409_CONFLICT
token = to_token(email=mail["to"], hood=hood_id) token = to_token(email=mail["to"], hood=hood_id)
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/email/unsubscribe/{1}".format(hood_id, token) "/api/hoods/{0}/email/unsubscribe/{1}".format(hood_id, token)
) )
assert response.status_code == status.HTTP_204_NO_CONTENT assert response.status_code == status.HTTP_204_NO_CONTENT
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_message(asyncclient, hood_id, trigger_id, email_row): async def test_email_message(client, hood_id, trigger_id, email_row):
body = { body = {
"text": "test", "text": "test",
"author": "test@localhost", "author": "test@localhost",
"secret": email_row["secret"], "secret": email_row["secret"],
} }
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/email/messages/".format(hood_id), json=body "/api/hoods/{0}/email/messages/".format(hood_id), json=body
) )
assert response.status_code == status.HTTP_201_CREATED assert response.status_code == status.HTTP_201_CREATED

View file

@ -9,23 +9,23 @@ import pytest
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_create_unauthorized(asyncclient, hood_id): async def test_email_create_unauthorized(client, hood_id):
response = await asyncclient.post("/api/hoods/{0}/email/".format(hood_id)) response = await client.post("/api/hoods/{0}/email/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_delete_unauthorized(asyncclient, hood_id, email_row): async def test_email_delete_unauthorized(client, hood_id, email_row):
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/email/{1}".format(hood_id, email_row["id"]) "/api/hoods/{0}/email/{1}".format(hood_id, email_row["id"])
) )
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_message_unauthorized(asyncclient, hood_id, email_row): async def test_email_message_unauthorized(client, hood_id, email_row):
body = {"text": "test", "author": "author", "secret": "wrong"} body = {"text": "test", "author": "author", "secret": "wrong"}
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/email/messages/".format(hood_id), json=body "/api/hoods/{0}/email/messages/".format(hood_id), json=body
) )
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED

View file

@ -9,15 +9,15 @@ import pytest
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_subscribe_empty(asyncclient, hood_id): async def test_email_subscribe_empty(client, hood_id):
response = await asyncclient.post("/api/hoods/{0}/email/subscribe/".format(hood_id)) response = await client.post("/api/hoods/{0}/email/subscribe/".format(hood_id))
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_subscribe_confirm_wrong_token(asyncclient, hood_id): async def test_email_subscribe_confirm_wrong_token(client, hood_id):
try: try:
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/email/subscribe/confirm/".format(hood_id) "/api/hoods/{0}/email/subscribe/confirm/".format(hood_id)
+ "asdfasdfasdfasdfasdfasdfasdfasdf" + "asdfasdfasdfasdfasdfasdfasdfasdf"
) )
@ -27,30 +27,30 @@ async def test_email_subscribe_confirm_wrong_token(asyncclient, hood_id):
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_subscribe_confirm_wrong_hood(asyncclient): async def test_email_subscribe_confirm_wrong_hood(client):
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/99999/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf" "/api/hoods/99999/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf"
) )
assert response.json()["detail"] == "Not Found" assert response.json()["detail"] == "Not Found"
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_message_wrong(asyncclient, hood_id, email_row): async def test_email_message_wrong(client, hood_id, email_row):
body = { body = {
"text": "", "text": "",
"author": "test@localhost", "author": "test@localhost",
"secret": email_row["secret"], "secret": email_row["secret"],
} }
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/email/messages/".format(hood_id), json=body "/api/hoods/{0}/email/messages/".format(hood_id), json=body
) )
assert response.status_code == status.HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS assert response.status_code == status.HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_unsubscribe_wrong_token(asyncclient, hood_id): async def test_email_unsubscribe_wrong_token(client, hood_id):
try: try:
await asyncclient.delete( await client.delete(
"/api/hoods/{0}/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf".format( "/api/hoods/{0}/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf".format(
hood_id hood_id
) )
@ -60,8 +60,8 @@ async def test_email_unsubscribe_wrong_token(asyncclient, hood_id):
@pytest.mark.anyio @pytest.mark.anyio
async def test_email_unsubscribe_wrong_hood(asyncclient): async def test_email_unsubscribe_wrong_hood(client):
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/99999/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf" "/api/hoods/99999/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf"
) )
assert response.json()["detail"] == "Not Found" assert response.json()["detail"] == "Not Found"

View file

@ -32,7 +32,7 @@ def disable_spawner(monkeypatch):
) )
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_create_bot( async def test_mastodon_create_bot(
asyncclient, client,
disable_spawner, disable_spawner,
hood_id, hood_id,
auth_header, auth_header,
@ -44,7 +44,7 @@ async def test_mastodon_create_bot(
monkeypatch.setattr(Mastodon, "log_in", log_in_mock) monkeypatch.setattr(Mastodon, "log_in", log_in_mock)
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/mastodon/".format(hood_id), "/api/hoods/{0}/mastodon/".format(hood_id),
json=body, json=body,
headers=auth_header, headers=auth_header,
@ -77,14 +77,14 @@ async def test_mastodon_create_bot(
) )
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_invalid_input( async def test_mastodon_invalid_input(
asyncclient, client,
disable_spawner, disable_spawner,
hood_id, hood_id,
auth_header, auth_header,
monkeypatch, monkeypatch,
body, body,
): ):
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/mastodon/".format(hood_id), "/api/hoods/{0}/mastodon/".format(hood_id),
json=body, json=body,
headers=auth_header, headers=auth_header,
@ -93,14 +93,14 @@ async def test_mastodon_invalid_input(
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_create_mastodon_invalid_id(asyncclient, auth_header): async def test_mastodon_create_mastodon_invalid_id(client, auth_header):
response = await asyncclient.post("/api/hoods/1337/mastodon/", headers=auth_header) response = await client.post("/api/hoods/1337/mastodon/", headers=auth_header)
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.post("/api/hoods/wrong/mastodon/", headers=auth_header) response = await client.post("/api/hoods/wrong/mastodon/", headers=auth_header)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_create_unauthorized(asyncclient, hood_id): async def test_mastodon_create_unauthorized(client, hood_id):
response = await asyncclient.post("/api/hoods/{hood_id}/mastodon/") response = await client.post("/api/hoods/{hood_id}/mastodon/")
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED

View file

@ -11,8 +11,8 @@ from kibicara.platforms.mastodon.model import MastodonAccount
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_delete_bot(asyncclient, mastodon_account, auth_header): async def test_mastodon_delete_bot(client, mastodon_account, auth_header):
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/mastodon/{1}".format( "/api/hoods/{0}/mastodon/{1}".format(
mastodon_account.hood.id, mastodon_account.id mastodon_account.hood.id, mastodon_account.id
), ),
@ -24,28 +24,24 @@ async def test_mastodon_delete_bot(asyncclient, mastodon_account, auth_header):
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_delete_bot_invalid_id(asyncclient, auth_header, hood_id): async def test_mastodon_delete_bot_invalid_id(client, auth_header, hood_id):
response = await asyncclient.delete( response = await client.delete("/api/hoods/1337/mastodon/123", headers=auth_header)
"/api/hoods/1337/mastodon/123", headers=auth_header
)
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.delete( response = await client.delete("/api/hoods/wrong/mastodon/123", headers=auth_header)
"/api/hoods/wrong/mastodon/123", headers=auth_header
)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/mastodon/7331".format(hood_id), headers=auth_header "/api/hoods/{0}/mastodon/7331".format(hood_id), headers=auth_header
) )
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/mastodon/wrong".format(hood_id), headers=auth_header "/api/hoods/{0}/mastodon/wrong".format(hood_id), headers=auth_header
) )
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_delete_bot_unauthorized(asyncclient, mastodon_account): async def test_mastodon_delete_bot_unauthorized(client, mastodon_account):
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/mastodon/{1}".format( "/api/hoods/{0}/mastodon/{1}".format(
mastodon_account.hood.id, mastodon_account.id mastodon_account.hood.id, mastodon_account.id
) )

View file

@ -11,7 +11,7 @@ from kibicara.platforms.mastodon.model import MastodonAccount
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_get_bots( async def test_mastodon_get_bots(
asyncclient, auth_header, hood_id, mastodon_account, mastodon_instance client, auth_header, hood_id, mastodon_account, mastodon_instance
): ):
mastodon2 = await MastodonAccount.objects.create( mastodon2 = await MastodonAccount.objects.create(
hood=mastodon_account.hood, hood=mastodon_account.hood,
@ -20,7 +20,7 @@ async def test_mastodon_get_bots(
enabled=True, enabled=True,
username="us4r", username="us4r",
) )
response = await asyncclient.get( response = await client.get(
"/api/hoods/{0}/mastodon/".format(mastodon_account.hood.id), headers=auth_header "/api/hoods/{0}/mastodon/".format(mastodon_account.hood.id), headers=auth_header
) )
print(response.headers) print(response.headers)
@ -32,22 +32,22 @@ async def test_mastodon_get_bots(
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_get_bots_invalid_id(asyncclient, auth_header, hood_id): async def test_mastodon_get_bots_invalid_id(client, auth_header, hood_id):
response = await asyncclient.get("/api/hoods/1337/mastodon/", headers=auth_header) response = await client.get("/api/hoods/1337/mastodon/", headers=auth_header)
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.get("/api/hoods/wrong/mastodon/", headers=auth_header) response = await client.get("/api/hoods/wrong/mastodon/", headers=auth_header)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_get_bots_unauthorized(asyncclient, hood_id): async def test_mastodon_get_bots_unauthorized(client, hood_id):
response = await asyncclient.get("/api/hoods/{0}/mastodon/".format(hood_id)) response = await client.get("/api/hoods/{0}/mastodon/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.anyio @pytest.mark.anyio
async def test_mastodon_public(asyncclient, mastodon_account, mastodon_instance): async def test_mastodon_public(client, mastodon_account, mastodon_instance):
response = await asyncclient.get( response = await client.get(
"/api/hoods/{0}/mastodon/public".format(mastodon_account.hood.id) "/api/hoods/{0}/mastodon/public".format(mastodon_account.hood.id)
) )
assert response.json()[0]["username"] == mastodon_account.username assert response.json()[0]["username"] == mastodon_account.username

View file

@ -22,7 +22,7 @@ def disable_spawner(monkeypatch):
@pytest.mark.parametrize("body", [{"api_token": "string", "welcome_message": "string"}]) @pytest.mark.parametrize("body", [{"api_token": "string", "welcome_message": "string"}])
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_create_bot( async def test_telegram_create_bot(
asyncclient, client,
disable_spawner, disable_spawner,
hood_id, hood_id,
auth_header, auth_header,
@ -34,7 +34,7 @@ async def test_telegram_create_bot(
monkeypatch.setattr(telegram.webapi, "check_token", check_token_mock) monkeypatch.setattr(telegram.webapi, "check_token", check_token_mock)
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/telegram/".format(hood_id), "/api/hoods/{0}/telegram/".format(hood_id),
json=body, json=body,
headers=auth_header, headers=auth_header,
@ -55,14 +55,14 @@ async def test_telegram_create_bot(
@pytest.mark.parametrize("body", [{"api_token": "string", "welcome_message": "string"}]) @pytest.mark.parametrize("body", [{"api_token": "string", "welcome_message": "string"}])
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_invalid_api_token( async def test_telegram_invalid_api_token(
asyncclient, client,
disable_spawner, disable_spawner,
hood_id, hood_id,
auth_header, auth_header,
monkeypatch, monkeypatch,
body, body,
): ):
response = await asyncclient.post( response = await client.post(
"/api/hoods/{0}/telegram/".format(hood_id), "/api/hoods/{0}/telegram/".format(hood_id),
json=body, json=body,
headers=auth_header, headers=auth_header,
@ -71,14 +71,14 @@ async def test_telegram_invalid_api_token(
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_create_telegram_invalid_id(asyncclient, auth_header): async def test_telegram_create_telegram_invalid_id(client, auth_header):
response = await asyncclient.post("/api/hoods/1337/telegram/", headers=auth_header) response = await client.post("/api/hoods/1337/telegram/", headers=auth_header)
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.post("/api/hoods/wrong/telegram/", headers=auth_header) response = await client.post("/api/hoods/wrong/telegram/", headers=auth_header)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_create_unauthorized(asyncclient, hood_id): async def test_telegram_create_unauthorized(client, hood_id):
response = await asyncclient.post("/api/hoods/{hood_id}/telegram/") response = await client.post("/api/hoods/{hood_id}/telegram/")
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED

View file

@ -14,10 +14,10 @@ from kibicara.platforms.telegram.model import Telegram, TelegramUser
"bot", [{"api_token": "apitoken123", "welcome_message": "msg"}] "bot", [{"api_token": "apitoken123", "welcome_message": "msg"}]
) )
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_delete_bot(asyncclient, bot, telegram, auth_header): async def test_telegram_delete_bot(client, bot, telegram, auth_header):
await TelegramUser.objects.create(user_id=1234, bot=telegram.id) await TelegramUser.objects.create(user_id=1234, bot=telegram.id)
await TelegramUser.objects.create(user_id=5678, bot=telegram.id) await TelegramUser.objects.create(user_id=5678, bot=telegram.id)
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/telegram/{1}".format(telegram.hood.id, telegram.id), "/api/hoods/{0}/telegram/{1}".format(telegram.hood.id, telegram.id),
headers=auth_header, headers=auth_header,
) )
@ -29,20 +29,16 @@ async def test_telegram_delete_bot(asyncclient, bot, telegram, auth_header):
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_delete_bot_invalid_id(asyncclient, auth_header, hood_id): async def test_telegram_delete_bot_invalid_id(client, auth_header, hood_id):
response = await asyncclient.delete( response = await client.delete("/api/hoods/1337/telegram/123", headers=auth_header)
"/api/hoods/1337/telegram/123", headers=auth_header
)
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.delete( response = await client.delete("/api/hoods/wrong/telegram/123", headers=auth_header)
"/api/hoods/wrong/telegram/123", headers=auth_header
)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/telegram/7331".format(hood_id), headers=auth_header "/api/hoods/{0}/telegram/7331".format(hood_id), headers=auth_header
) )
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/telegram/wrong".format(hood_id), headers=auth_header "/api/hoods/{0}/telegram/wrong".format(hood_id), headers=auth_header
) )
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
@ -52,8 +48,8 @@ async def test_telegram_delete_bot_invalid_id(asyncclient, auth_header, hood_id)
"bot", [{"api_token": "apitoken123", "welcome_message": "msg"}] "bot", [{"api_token": "apitoken123", "welcome_message": "msg"}]
) )
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_delete_bot_unauthorized(asyncclient, bot, telegram): async def test_telegram_delete_bot_unauthorized(client, bot, telegram):
response = await asyncclient.delete( response = await client.delete(
"/api/hoods/{0}/telegram/{1}".format(telegram.hood.id, telegram.id) "/api/hoods/{0}/telegram/{1}".format(telegram.hood.id, telegram.id)
) )
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED

View file

@ -11,8 +11,8 @@ import pytest
"bot", [{"api_token": "apitoken123", "welcome_message": "msg"}] "bot", [{"api_token": "apitoken123", "welcome_message": "msg"}]
) )
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_get_bot(asyncclient, auth_header, bot, telegram): async def test_telegram_get_bot(client, auth_header, bot, telegram):
response = await asyncclient.get( response = await client.get(
"/api/hoods/{0}/telegram/{1}".format(telegram.hood.id, telegram.id), "/api/hoods/{0}/telegram/{1}".format(telegram.hood.id, telegram.id),
headers=auth_header, headers=auth_header,
) )
@ -23,20 +23,16 @@ async def test_telegram_get_bot(asyncclient, auth_header, bot, telegram):
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_get_bot_invalid_id(asyncclient, auth_header, hood_id): async def test_telegram_get_bot_invalid_id(client, auth_header, hood_id):
response = await asyncclient.get( response = await client.get("/api/hoods/1337/telegram/123", headers=auth_header)
"/api/hoods/1337/telegram/123", headers=auth_header
)
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.get( response = await client.get("/api/hoods/wrong/telegram/123", headers=auth_header)
"/api/hoods/wrong/telegram/123", headers=auth_header
)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
response = await asyncclient.get( response = await client.get(
"/api/hoods/{0}/telegram/7331".format(hood_id), headers=auth_header "/api/hoods/{0}/telegram/7331".format(hood_id), headers=auth_header
) )
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.get( response = await client.get(
"/api/hoods/{0}/telegram/wrong".format(hood_id), headers=auth_header "/api/hoods/{0}/telegram/wrong".format(hood_id), headers=auth_header
) )
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
@ -46,8 +42,8 @@ async def test_telegram_get_bot_invalid_id(asyncclient, auth_header, hood_id):
"bot", [{"api_token": "apitoken456", "welcome_message": "msg"}] "bot", [{"api_token": "apitoken456", "welcome_message": "msg"}]
) )
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_get_bot_unauthorized(asyncclient, bot, telegram): async def test_telegram_get_bot_unauthorized(client, bot, telegram):
response = await asyncclient.get( response = await client.get(
"/api/hoods/{0}/telegram/{1}".format(telegram.hood.id, telegram.id) "/api/hoods/{0}/telegram/{1}".format(telegram.hood.id, telegram.id)
) )
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED

View file

@ -11,7 +11,7 @@ from kibicara.platforms.telegram.model import Telegram
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_get_bots(asyncclient, auth_header, hood_id): async def test_telegram_get_bots(client, auth_header, hood_id):
hood = await Hood.objects.get(id=hood_id) hood = await Hood.objects.get(id=hood_id)
telegram0 = await Telegram.objects.create( telegram0 = await Telegram.objects.create(
hood=hood, hood=hood,
@ -23,7 +23,7 @@ async def test_telegram_get_bots(asyncclient, auth_header, hood_id):
api_token="api_token456", api_token="api_token456",
welcome_message="welcome_message123", welcome_message="welcome_message123",
) )
response = await asyncclient.get( response = await client.get(
"/api/hoods/{0}/telegram/".format(telegram0.hood.id), headers=auth_header "/api/hoods/{0}/telegram/".format(telegram0.hood.id), headers=auth_header
) )
assert response.status_code == status.HTTP_200_OK assert response.status_code == status.HTTP_200_OK
@ -34,14 +34,14 @@ async def test_telegram_get_bots(asyncclient, auth_header, hood_id):
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_get_bots_invalid_id(asyncclient, auth_header, hood_id): async def test_telegram_get_bots_invalid_id(client, auth_header, hood_id):
response = await asyncclient.get("/api/hoods/1337/telegram/", headers=auth_header) response = await client.get("/api/hoods/1337/telegram/", headers=auth_header)
assert response.status_code == status.HTTP_404_NOT_FOUND assert response.status_code == status.HTTP_404_NOT_FOUND
response = await asyncclient.get("/api/hoods/wrong/telegram/", headers=auth_header) response = await client.get("/api/hoods/wrong/telegram/", headers=auth_header)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
@pytest.mark.anyio @pytest.mark.anyio
async def test_telegram_get_bots_unauthorized(asyncclient, hood_id): async def test_telegram_get_bots_unauthorized(client, hood_id):
response = await asyncclient.get("/api/hoods/{0}/telegram/".format(hood_id)) response = await client.get("/api/hoods/{0}/telegram/".format(hood_id))
assert response.status_code == status.HTTP_401_UNAUTHORIZED assert response.status_code == status.HTTP_401_UNAUTHORIZED