Add log of notifications to API integration page

Now that we’ve removed simulated notifications from the dashboard and
activity pages they’re not visible anywhere in the app.

While they should’t be visible to non-technical users, developers have
a real need for Notify to confirm that their code is doing what they
expect. This is needed especially when they’re just getting started with
Notify.

There’s no way of seeing this info from the API either, because a key
can only get notifications created with a key of that type.

It doesn’t make sense to make this a ‘mode’ of the dashboard or activity
because the information about notifications that developers need is
also different. So this commit adds up to 50 of the most recent
notifications sent via the API to the page that developers use as their
‘home’ page.

This also lets us explain the 7 days thing to developers via the
empty slate state of this area of the page.
This commit is contained in:
Chris Hill-Scott
2016-09-21 10:13:25 +01:00
parent a04aad8825
commit 48891babc4
9 changed files with 199 additions and 6 deletions

View File

@@ -208,7 +208,7 @@ def notification_json(
if sent_at is None:
sent_at = str(datetime.utcnow().time())
if created_at is None:
created_at = str(datetime.utcnow().time())
created_at = datetime.now(timezone.utc).isoformat()
if updated_at is None:
updated_at = str((datetime.utcnow() + timedelta(minutes=1)).time())
if status is None:

View File

@@ -12,7 +12,8 @@ def test_should_show_api_page(
mock_login,
api_user_active,
mock_get_service,
mock_has_permissions
mock_has_permissions,
mock_get_notifications
):
with app_.test_request_context(), app_.test_client() as client:
client.login(api_user_active)
@@ -21,6 +22,42 @@ def test_should_show_api_page(
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.h1.string.strip() == 'API integration'
assert 'Your service is in trial mode' in page.find('div', {'class': 'banner-warning'}).text
rows = page.find_all('details')
assert len(rows) == 5
for index, row in enumerate(rows):
assert row.find('h3').string.strip() == '07123456789'
def test_should_show_api_page_with_lots_of_notifications(
client,
mock_login,
api_user_active,
mock_get_service,
mock_has_permissions,
mock_get_notifications_with_previous_next
):
client.login(api_user_active)
response = client.get(url_for('main.api_integration', service_id=str(uuid.uuid4())))
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
rows = page.find_all('div', {'class': 'api-notifications-item'})
assert ' '.join(rows[len(rows) - 1].text.split()) == (
'Only showing the first 50 messages. Notify deletes messages after 7 days.'
)
def test_should_show_api_page_with_no_notifications(
client,
mock_login,
api_user_active,
mock_get_service,
mock_has_permissions,
mock_get_notifications_with_no_notifications
):
client.login(api_user_active)
response = client.get(url_for('main.api_integration', service_id=str(uuid.uuid4())))
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
rows = page.find_all('div', {'class': 'api-notifications-item'})
assert 'When you send messages via the API theyll appear here.' in rows[len(rows) - 1].text.strip()
def test_should_show_api_page_for_live_service(

View File

@@ -976,7 +976,9 @@ def mock_get_notifications_with_previous_next(mocker):
page=1,
template_type=None,
status=None,
limit_days=None):
limit_days=None,
include_jobs=None,
include_from_test_key=None):
return notification_json(service_id, with_links=True)
return mocker.patch(
@@ -985,6 +987,24 @@ def mock_get_notifications_with_previous_next(mocker):
)
@pytest.fixture(scope='function')
def mock_get_notifications_with_no_notifications(mocker):
def _get_notifications(service_id,
job_id=None,
page=1,
template_type=None,
status=None,
limit_days=None,
include_jobs=None,
include_from_test_key=None):
return notification_json(service_id, rows=0)
return mocker.patch(
'app.notification_api_client.get_notifications_for_service',
side_effect=_get_notifications
)
@pytest.fixture(scope='function')
def mock_has_permissions(mocker):
def _has_permission(permissions=None, any_=False, admin_override=False):