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