Files
notifications-admin/tests/app/main/views/test_jobs.py
Chris Hill-Scott b31c9fbc0d Make job page poll for updates
This is a first go at having the job page update without refreshing.

The approach I’ve taken is to do all the rendering of HTML on the server side,
rather than use a Javascipt templating engine like mustache. This ensures that
we don’t have to maintain two sets of templates.

So the approach is to split the job page into partials. These partials can then:
- be included in the job page to render the whole page
- be rendered indivudually and then returned as a blob of HTML inside a JSON
  response

Then I’ve added a Javascript module which looks for areas of the page that should
be reloaded. For each area of the page it will poll a URL and re-render that
section of the page when it gets new HTML. It implements some throttling so that
API calls will never happen more frequently than 0.67 times/second.
2016-03-03 14:28:36 +00:00

83 lines
2.7 KiB
Python

from flask import url_for
from bs4 import BeautifulSoup
import json
def test_should_return_list_of_all_jobs(app_,
service_one,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_login,
mock_get_jobs):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
response = client.get(url_for('main.view_jobs', service_id=101))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.h1.string == 'Notifications activity'
jobs = page.tbody.find_all('tr')
assert len(jobs) == 5
def test_should_show_page_for_one_job(
app_,
service_one,
api_user_active,
mock_login,
mock_get_user,
mock_get_user_by_email,
mock_get_service,
mock_get_service_template,
job_data,
mock_get_job,
mock_get_notifications
):
service_id = job_data['service']
job_id = job_data['id']
file_name = job_data['original_file_name']
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
response = client.get(url_for('main.view_job', service_id=service_id, job_id=job_id))
assert response.status_code == 200
content = response.get_data(as_text=True)
assert "Test Service: Your vehicle tax is about to expire" in content
assert file_name in content
def test_should_show_updates_for_one_job_as_json(
app_,
service_one,
api_user_active,
mock_login,
mock_get_user,
mock_get_user_by_email,
mock_get_service,
mock_get_service_template,
job_data,
mock_get_job,
mock_get_notifications
):
service_id = job_data['service']
job_id = job_data['id']
file_name = job_data['original_file_name']
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
response = client.get(url_for('main.view_job_updates', service_id=service_id, job_id=job_id))
assert response.status_code == 200
content = json.loads(response.get_data(as_text=True))
assert 'sent' in content['counts']
assert 'queued' in content['counts']
assert 'failed' in content['counts']
assert 'Recipient' in content['notifications']
assert 'Status' in content['notifications']
assert 'Started' in content['status']