From 0dbade63acd6a115d3f1bb217bc68dd38120e18e Mon Sep 17 00:00:00 2001 From: maike Date: Sun, 12 Jul 2020 19:52:59 +0200 Subject: [PATCH] [email] Fix and reduce tests --- tests/conftest.py | 4 +++- tests/test_api_email_happy_path.py | 26 +++++--------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c3d80a0..4e38292 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -124,6 +124,8 @@ def email_row(client, hood_id, auth_header): assert response.status_code == status.HTTP_201_CREATED assert response.json()["hood"]["id"] == hood_id 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 # 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) diff --git a/tests/test_api_email_happy_path.py b/tests/test_api_email_happy_path.py index 798b1a9..afbabb2 100644 --- a/tests/test_api_email_happy_path.py +++ b/tests/test_api_email_happy_path.py @@ -5,6 +5,7 @@ from fastapi import status from logging import getLogger, INFO, WARNING, Handler from kibicara.webapi.admin import to_token +import os class CaptureHandler(Handler): @@ -16,15 +17,7 @@ class CaptureHandler(Handler): self.records.append(record) -def test_email_create(client, hood_id, auth_header): - 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): +def test_email_subscribe(client, hood_id, email_row): logger = getLogger() capture = CaptureHandler() 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 -def test_email_unsubscribe(client, hood_id): - test_email_subscribe(client, hood_id) +def test_email_unsubscribe(client, hood_id, email_row): + test_email_subscribe(client, hood_id, email_row) token = to_token(email="user@localhost", hood=hood_id) response = client.get('/api/hoods/%d/email/unsubscribe/%s' % (hood_id, token)) - assert response.status_code == status.HTTP_200_OK - - -# 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 + assert response.status_code == status.HTTP_204_NO_CONTENT