Anton Shestakov <av6@dwimlabs.net>, Sun, 24 Sep 2017 12:25:05 +0800
viewer: use subqueries to get data on index page
Before, there were bare columns in the aggregate query, their values were
undefined (but it somehow worked), as SQLite docs say. Good news is that now
this bigger query uses (project_id, ordinal) index and is really fast.
tests/test_models.py
Permissions: -rw-r--r--
from datetime import datetime, timedelta from candolint import adapters from candolint.models import database, Project, Change, Check with database.transaction(): url='https://example.com/alice/test-models', check = Check(started=now) check.finished = now + timedelta(seconds=10) assert check.get_duration() == '10 sec' check.finished = now + timedelta(minutes=5) assert check.get_duration() == '5 min' check.finished = now + timedelta(hours=2) assert check.get_duration() == '120 min' def test_manual_upsert(): 'node': '92cfceb39d57d914ed8b14d0e37643de0797ae56', 'message': 'component: do a thing', 'project': Project.get(name='test-models') with database.transaction(): change, created = Change.manual_upsert(**data) assert change is not None change = Change.get(id=change.id) with database.transaction(): change, created = Change.manual_upsert(**data) assert change is not None change = Change.get(id=change.id) assert change.rev is None assert change.id == old_id project = Project(domain='bitbucket.org', name='obviously-from-bitbucket') assert isinstance(project.get_adapter(), adapters.BitbucketAdapter) project = Project(domain='github.com', name='obviously-from-github') assert isinstance(project.get_adapter(), adapters.GithubAdapter) project = Project(domain='example.com', name='fallback') assert isinstance(project.get_adapter(), adapters.HostingAdapter)