Files
notifications-api/tests/app/test_schemas.py
Chris Hill-Scott 130f42fed2 Add details of API key to notifications
We want to show developers a log of notifications they’ve sent using the
API in the admin app. In order to indentify a notification it’s probably
helpful to know:

- who the notification was sent to (which we expose)
- when the notification was created (which we expose)
- which key was used to create the notification (which we expose, but
  only as the `id` of the key)

Developers don’t see the `id` of the API key in the app anywhere, so
this isn’t useful information. Much more useful is the `type` and `name`
of the key. So this commit changes the schema to also return these.

This commit does some slightly hacky stuff with conftest because it
breaks a lot of other tests if the sample notification has a real API
key or an API key with a non-unique name.
2016-09-23 14:44:15 +01:00

25 lines
854 B
Python

def test_job_schema_doesnt_return_notifications(sample_notification_with_job):
from app.schemas import job_schema
job = sample_notification_with_job.job
assert job.notifications.count() == 1
data, errors = job_schema.dump(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'