add tests for notification status page

This commit is contained in:
Leo Hemsted
2017-06-16 14:57:48 +01:00
parent 09dc85e5bc
commit 20bb34849d
4 changed files with 119 additions and 5 deletions

View File

@@ -4,6 +4,8 @@ from unittest.mock import Mock
import pytest
from notifications_python_client.errors import HTTPError
from flask import url_for
from bs4 import BeautifulSoup
from app import create_app
from app.notify_client.models import (
@@ -1630,6 +1632,33 @@ def mock_reset_failed_login_count(mocker):
return mocker.patch('app.user_api_client.reset_failed_login_count')
@pytest.fixture
def mock_get_notification(mocker, fake_uuid, notification_status='delivered'):
def _get_notification(
service_id,
notification_id,
):
noti = notification_json(
service_id,
rows=1,
status=notification_status
)['notifications'][0]
noti['id'] = notification_id
noti['created_by'] = {
'id': fake_uuid,
'name': 'Test User',
'email_address': 'test@user.gov.uk'
}
noti['template'] = template_json(service_id, str(generate_uuid()))
return noti
return mocker.patch(
'app.notification_api_client.get_notification',
side_effect=_get_notification
)
@pytest.fixture(scope='function')
def client(app_):
with app_.test_request_context(), app_.test_client() as client:
@@ -1671,3 +1700,28 @@ def os_environ():
os.environ = {}
yield
os.environ = old_env
@pytest.fixture
@pytest.fixture
def client_request(logged_in_client):
class ClientRequest:
@staticmethod
def get(endpoint, endpoint_kwargs=None, expected_status=200, follow_redirects=False):
resp = logged_in_client.get(
url_for(endpoint, **(endpoint_kwargs or {}))
)
assert resp.status_code == expected_status
return BeautifulSoup(resp.data.decode('utf-8'), 'html.parser')
@staticmethod
def post(endpoint, endpoint_kwargs=None, data=None, expected_status=302, follow_redirects=False):
resp = logged_in_client.post(
url_for(endpoint, **(endpoint_kwargs or {})),
data
)
assert resp.status_code == expected_status
return BeautifulSoup(resp.data.decode('utf-8'), 'html.parser')
return ClientRequest