From 62735ea125babaaf6b9976448ede17ce1732ab73 Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Fri, 13 Sep 2019 13:26:46 +0100 Subject: [PATCH] Remove sample_notification_with_api_key fixture This was only used once and was not Pytest 4 compatible. --- tests/app/conftest.py | 12 ------------ tests/app/db.py | 7 +++++-- tests/app/test_schemas.py | 8 ++++++-- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/tests/app/conftest.py b/tests/app/conftest.py index 367b577ee..fb395d756 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -628,18 +628,6 @@ def sample_letter_notification(sample_letter_template): return create_notification(sample_letter_template, reference='foo', personalisation=address) -@pytest.fixture(scope='function') -def sample_notification_with_api_key(notify_db, notify_db_session): - notification = sample_notification(notify_db, notify_db_session) - notification.api_key = sample_api_key( - notify_db, - notify_db_session, - name='Test key' - ) - notification.api_key_id = notification.api_key.id - return notification - - @pytest.fixture(scope='function') def sample_email_notification(notify_db, notify_db_session): created_at = datetime.utcnow() diff --git a/tests/app/db.py b/tests/app/db.py index ce58cd08b..b6413b61f 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -511,11 +511,14 @@ def create_letter_rate(start_date=None, end_date=None, crown=True, sheet_count=1 return rate -def create_api_key(service, key_type=KEY_TYPE_NORMAL): +def create_api_key(service, key_type=KEY_TYPE_NORMAL, key_name=None): id_ = uuid.uuid4() + + name = key_name if key_name else '{} api key {}'.format(key_type, id_) + api_key = ApiKey( service=service, - name='{} api key {}'.format(key_type, id_), + name=name, created_by=service.created_by, key_type=key_type, id=id_, diff --git a/tests/app/test_schemas.py b/tests/app/test_schemas.py index 18bbbca37..d64b63edf 100644 --- a/tests/app/test_schemas.py +++ b/tests/app/test_schemas.py @@ -4,6 +4,7 @@ from sqlalchemy import desc from app.dao.provider_details_dao import dao_update_provider_details from app.models import ProviderDetailsHistory +from tests.app.db import create_api_key def test_job_schema_doesnt_return_notifications(sample_notification_with_job): @@ -25,10 +26,13 @@ def test_notification_schema_ignores_absent_api_key(sample_notification_with_job assert data['key_name'] is None -def test_notification_schema_adds_api_key_name(sample_notification_with_api_key): +def test_notification_schema_adds_api_key_name(sample_notification): from app.schemas import notification_with_template_schema - data = notification_with_template_schema.dump(sample_notification_with_api_key).data + api_key = create_api_key(sample_notification.service, key_name='Test key') + sample_notification.api_key = api_key + + data = notification_with_template_schema.dump(sample_notification).data assert data['key_name'] == 'Test key'