Anton Shestakov <av6@dwimlabs.net>, Thu, 17 Nov 2016 00:05:04 +0800
queue: make clear what kind of interval it is
tests/test_viewer.py
Permissions: -rw-r--r--
from datetime import datetime from xml.etree import ElementTree from pytest import raises from tornado.escape import json_encode from tornado.testing import AsyncHTTPTestCase from tornado.web import HTTPError from candolint.handlers import get_project_or_404 from candolint.models import database, Project, Change, Check from viewer import CandolintViewer with database.transaction(): project = Project.create( url='https://example.com/alice/test-viewer', node='92cfceb39d57d914ed8b14d0e37643de0797ae56', date='2016-07-19 22:23 +0800', message='component: do a thing', 'text': '# C&O job started: 2016-08-20T02:38:06+00:00', 'text': '# C&O task: setup', 'text': '$ ../venv2/bin/flake8 --version', 'text': '# C&O task: checks', 'text': 'test.py:20:80: E501 line too long (82 > 79 characters)', 'text': '# C&O job finished: 2016-08-20T02:38:53+00:00', ordinal=Check.get_next_ordinal(project), lines=json_encode(lines), started=datetime(2016, 8, 20, 2, 38, 6), finished=datetime(2016, 8, 20, 2, 38, 53), def test_get_project_or_404(): with raises(HTTPError) as error: get_project_or_404('butt.cloud', 'cyber', 'wizard-attack') assert error.value.status_code == 404 project = get_project_or_404('example.com', 'alice', 'test-viewer') assert project.id is not None assert project.url == 'https://example.com/alice/test-viewer' class ViewerTestCase(AsyncHTTPTestCase): response = self.fetch('/') assert response.code == 200 assert 'online linter' in response.body assert '1 error' in response.body assert '1 warning' in response.body assert '<a href="#">default</a>' in response.body response = self.fetch('/nobodyhere') assert response.code == 404 assert 'online linter' in response.body response = self.fetch('/butt.cloud/cyber/wizard-attack') assert response.code == 404 assert 'online linter' in response.body response = self.fetch('/example.com/alice/test-viewer') assert response.code == 200 assert 'Clone URL' in response.body assert 'status.svg' in response.body assert '.. image:: http' in response.body assert '1 error' in response.body assert '1 warning' in response.body assert '<a href="#">default</a>' in response.body assert ('<link rel="alternate"' ' href="/example.com/alice/test-viewer/atom"' ' type="application/atom+xml"' ' title="test-viewer feed">') in response.body response = self.fetch('/example.com/alice/test-viewer/atom') assert response.code == 200 assert 'atom+xml' in response.headers['Content-Type'] root = ElementTree.fromstring(response.body) ns = {'atom': 'http://www.w3.org/2005/Atom'} title = root.find('./atom:entry/atom:title', ns) assert title.text == 'Check #1: 1 error, 1 warning' updates = [el.text for el in root.findall('.//atom:updated', ns)] assert updates[0] == updates[1] == '2016-08-20T02:38:53Z' response = self.fetch('/butt.cloud/cyber/wizard-attack/latest') assert response.code == 404 assert 'online linter' in response.body response = self.fetch('/example.com/alice/test-viewer/latest') assert response.code == 200 assert '1 error' in response.body assert '1 warning' in response.body assert '<a href="#">default</a>' in response.body assert '<a href="#" class="filelink">test.py:20</a>' in response.body assert ('<time datetime="2016-08-20T02:38:53Z"' ' title="2016-08-20 02:38:53 UTC">' '2016-08-20 02:38:53 UTC</time>') in response.body assert ('<time datetime="2016-07-19T22:23+0800"' ' title="2016-07-19 22:23 +0800">' '2016-07-19 22:23 +0800</time>') in response.body response = self.fetch('/example.com/alice/test-viewer/latest/raw') assert response.code == 200 assert response.headers['Content-Type'] == 'text/plain; charset=utf-8' assert 'test.py' in response.body response = self.fetch('/butt.cloud/cyber/wizard-attack/status.svg') assert response.code == 404 assert 'online linter' in response.body response = self.fetch('/example.com/alice/test-viewer/status.svg') assert response.code == 200 root = ElementTree.fromstring(response.body) ns = {'svg': 'http://www.w3.org/2000/svg'} assert root.tag == '{http://www.w3.org/2000/svg}svg' assert 'height' in root.attrib assert root.attrib['height'] == '20' text = [el.text for el in root.findall('./svg:g/svg:text', ns)] assert text[::2] == ['lint', '1 error', '1 warning']