[email] Fix and reduce tests

This commit is contained in:
maike 2020-07-12 19:52:59 +02:00 committed by dl6tom
parent df5e17814c
commit 0dbade63ac
2 changed files with 8 additions and 22 deletions

View file

@ -124,6 +124,8 @@ def email_row(client, hood_id, auth_header):
assert response.status_code == status.HTTP_201_CREATED assert response.status_code == status.HTTP_201_CREATED
assert response.json()["hood"]["id"] == hood_id assert response.json()["hood"]["id"] == hood_id
email_row = response.json() email_row = response.json()
response = client.post('/api/hoods/%d/email/' % hood_id, headers=auth_header)
assert response.status_code == status.HTTP_409_CONFLICT
yield email_row yield email_row
# not sure if necessary; it raises problems at least # not sure if necessary; it raises problems at least
# client.delete('/api/hoods/%d/email/' % hood_id, headers=auth_header) client.delete('/api/hoods/%d/email/%d' % (hood_id, email_row['id']), headers=auth_header)

View file

@ -5,6 +5,7 @@
from fastapi import status from fastapi import status
from logging import getLogger, INFO, WARNING, Handler from logging import getLogger, INFO, WARNING, Handler
from kibicara.webapi.admin import to_token from kibicara.webapi.admin import to_token
import os
class CaptureHandler(Handler): class CaptureHandler(Handler):
@ -16,15 +17,7 @@ class CaptureHandler(Handler):
self.records.append(record) self.records.append(record)
def test_email_create(client, hood_id, auth_header): def test_email_subscribe(client, hood_id, email_row):
response = client.post('/api/hoods/%d/email/' % hood_id, headers=auth_header)
assert response.status_code == status.HTTP_201_CREATED
assert response.json()["hood"]["id"] == hood_id
# response = client.post('/api/hoods/%d/email/' % hood_id, headers=auth_header)
# assert response.status_code == status.HTTP_409_CONFLICT
def test_email_subscribe(client, hood_id):
logger = getLogger() logger = getLogger()
capture = CaptureHandler() capture = CaptureHandler()
logger.setLevel(INFO) logger.setLevel(INFO)
@ -54,17 +47,8 @@ def test_email_message(client, hood_id, trigger_id, email_row):
assert response.status_code == status.HTTP_201_CREATED assert response.status_code == status.HTTP_201_CREATED
def test_email_unsubscribe(client, hood_id): def test_email_unsubscribe(client, hood_id, email_row):
test_email_subscribe(client, hood_id) test_email_subscribe(client, hood_id, email_row)
token = to_token(email="user@localhost", hood=hood_id) token = to_token(email="user@localhost", hood=hood_id)
response = client.get('/api/hoods/%d/email/unsubscribe/%s' % (hood_id, token)) response = client.get('/api/hoods/%d/email/unsubscribe/%s' % (hood_id, token))
assert response.status_code == status.HTTP_200_OK assert response.status_code == status.HTTP_204_NO_CONTENT
# def test_email_send_mda -> call kibicara_mda.py like an MDA would
def test_email_delete(client, hood_id, auth_header):
test_email_create(client, hood_id, auth_header)
response = client.delete(
'/api/hoods/%d/email/%d' % (hood_id, hood_id), headers=auth_header
)
assert response.status_code == status.HTTP_200_OK