Files
notifications-admin/tests/app/models/test_event.py
Chris Hill-Scott 59b4d60c91 Munge stuff into a consistent event data type
We store our audit history in two ways:

  1. A list of versions of a service
  2. A list of events to do with API keys

In the future there could be auditing data which we want to display that
is stored in other formats (for example the event table).

This commit adds some objects which wrap around the different types of
auditing data, and expose a consistent interface to them. This
architecture will let us:
- write clean code in the presentation layer to display these events on
  a page
- add more types of events in the future by subclassing the `Event` data
  type, without having to rewrite anything in the presentation layer
2019-10-23 13:02:11 +01:00

90 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pytest
from app.models.event import ServiceEvent
from tests.conftest import sample_uuid
@pytest.mark.parametrize('key, value_from, value_to, expected', (
('restricted', True, False, (
'Made this service live'
)),
('restricted', False, True, (
'Put this service back into trial mode'
)),
('active', False, True, (
'Unsuspended this service'
)),
('active', True, False, (
'Deleted this service'
)),
('contact_link', 'x', 'y', (
'Set the contact details for this service to y'
)),
('email_branding', 'foo', 'bar', (
'Updated this services email branding'
)),
('inbound_api', 'foo', 'bar', (
'Updated the callback for received text messages'
)),
('letter_branding', None, sample_uuid(), (
'Updated the logo on this services letters'
)),
('letter_branding', sample_uuid(), None, (
'Removed the logo from this services letters'
)),
('letter_contact_block', None, sample_uuid(), (
'Updated the default letter contact block for this service'
)),
('message_limit', 1, 2, (
'Increased this services daily message limit from 1 to 2'
)),
('message_limit', 2, 1, (
'Reduced this services daily message limit from 2 to 1'
)),
('name', 'Old', 'New', (
'Renamed this service from Old to New'
)),
('permissions', ['a', 'b', 'c'], ['a', 'b', 'c', 'd'], (
'Added d to this services permissions'
)),
('permissions', ['a', 'b', 'c'], ['a', 'b'], (
'Removed c from this services permissions'
)),
('permissions', ['a', 'b', 'c'], ['c', 'd', 'e'], (
'Removed a and b from this services permissions, added d and e'
)),
('prefix_sms', True, False, (
'Set text messages to not start with the name of this service'
)),
('prefix_sms', False, True, (
'Set text messages to start with the name of this service'
)),
('research_mode', True, False, (
'Took this service out of research mode'
)),
('research_mode', False, True, (
'Put this service into research mode'
)),
('service_callback_api', 'foo', 'bar', (
'Updated the callback for delivery receipts'
)),
))
def test_service_event(
key,
value_from,
value_to,
expected,
):
event = ServiceEvent(
{
'created_at': 'foo',
'updated_at': 'bar',
'created_by_id': sample_uuid(),
},
key,
value_from,
value_to,
)
assert event.relevant is True
assert str(event) == expected