ticketfrei3/backend/tests/tests_email/test_api_email_wrong.py

68 lines
2 KiB
Python
Raw Normal View History

# Copyright (C) 2020 by Maike <maike@systemli.org>
# Copyright (C) 2020 by Martin Rey <martin.rey@mailbox.org>
#
# SPDX-License-Identifier: 0BSD
from fastapi import status
from nacl.exceptions import CryptoError
2023-04-01 12:57:41 +00:00
import pytest
2023-04-01 12:57:41 +00:00
@pytest.mark.anyio
2023-04-01 13:32:10 +00:00
async def test_email_subscribe_empty(client, hood_id):
response = await client.post("/api/hoods/{0}/email/subscribe/".format(hood_id))
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
2023-04-01 12:57:41 +00:00
@pytest.mark.anyio
2023-04-01 13:32:10 +00:00
async def test_email_subscribe_confirm_wrong_token(client, hood_id):
try:
2023-04-01 13:32:10 +00:00
response = await client.post(
"/api/hoods/{0}/email/subscribe/confirm/".format(hood_id)
+ "asdfasdfasdfasdfasdfasdfasdfasdf"
)
assert response.status_code is not status.HTTP_201_CREATED
except CryptoError:
pass
2023-04-01 12:57:41 +00:00
@pytest.mark.anyio
2023-04-01 13:32:10 +00:00
async def test_email_subscribe_confirm_wrong_hood(client):
response = await client.delete(
"/api/hoods/99999/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf"
)
assert response.json()["detail"] == "Not Found"
2023-04-01 12:57:41 +00:00
@pytest.mark.anyio
2023-04-01 13:32:10 +00:00
async def test_email_message_wrong(client, hood_id, email_row):
body = {
"text": "",
"author": "test@localhost",
"secret": email_row["secret"],
}
2023-04-01 13:32:10 +00:00
response = await client.post(
2023-04-01 12:57:41 +00:00
"/api/hoods/{0}/email/messages/".format(hood_id), json=body
)
assert response.status_code == status.HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS
2023-04-01 12:57:41 +00:00
@pytest.mark.anyio
2023-04-01 13:32:10 +00:00
async def test_email_unsubscribe_wrong_token(client, hood_id):
try:
2023-04-01 13:32:10 +00:00
await client.delete(
"/api/hoods/{0}/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf".format(
2020-10-12 20:47:06 +00:00
hood_id
)
)
except CryptoError:
pass
2023-04-01 12:57:41 +00:00
@pytest.mark.anyio
2023-04-01 13:32:10 +00:00
async def test_email_unsubscribe_wrong_hood(client):
response = await client.delete(
"/api/hoods/99999/email/unsubscribe/asdfasdfasdfasdfasdfasdfasdfasdf"
)
assert response.json()["detail"] == "Not Found"