mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 15:15:38 -05:00
Merge pull request #690 from alphagov/add-key-name-notifications
Add details of API key to notifications
This commit is contained in:
@@ -232,10 +232,11 @@ def sample_email_template_with_placeholders(notify_db, notify_db_session):
|
||||
def sample_api_key(notify_db,
|
||||
notify_db_session,
|
||||
service=None,
|
||||
key_type=KEY_TYPE_NORMAL):
|
||||
key_type=KEY_TYPE_NORMAL,
|
||||
name=None):
|
||||
if service is None:
|
||||
service = sample_service(notify_db, notify_db_session)
|
||||
data = {'service': service, 'name': uuid.uuid4(), 'created_by': service.created_by, 'key_type': key_type}
|
||||
data = {'service': service, 'name': name or uuid.uuid4(), 'created_by': service.created_by, 'key_type': key_type}
|
||||
api_key = ApiKey(**data)
|
||||
save_model_api_key(api_key)
|
||||
return api_key
|
||||
@@ -441,6 +442,17 @@ def sample_notification(notify_db,
|
||||
return notification
|
||||
|
||||
|
||||
@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_id = sample_api_key(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
name='Test key'
|
||||
).id
|
||||
return notification
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def sample_email_notification(notify_db, notify_db_session):
|
||||
created_at = datetime.utcnow()
|
||||
|
||||
@@ -8,3 +8,17 @@ def test_job_schema_doesnt_return_notifications(sample_notification_with_job):
|
||||
|
||||
assert not errors
|
||||
assert 'notifications' not in data
|
||||
|
||||
|
||||
def test_notification_schema_ignores_absent_api_key(sample_notification_with_job):
|
||||
from app.schemas import notification_with_template_schema
|
||||
|
||||
data = notification_with_template_schema.dump(sample_notification_with_job).data
|
||||
assert data['key_name'] is None
|
||||
|
||||
|
||||
def test_notification_schema_adds_api_key_name(sample_notification_with_api_key):
|
||||
from app.schemas import notification_with_template_schema
|
||||
|
||||
data = notification_with_template_schema.dump(sample_notification_with_api_key).data
|
||||
assert data['key_name'] == 'Test key'
|
||||
|
||||
Reference in New Issue
Block a user