179:572fc0f25c6b
Anton Shestakov <av6@dwimlabs.net>, Sun, 24 Jul 2016 09:24:14 +0800
checker: support running linters with custom environment

next change 241:f5efb98791b5
previous change 171:dd72c5809c96

tests/test_models.py

Permissions: -rw-r--r--

Other formats: Feeds:
from datetime import datetime, timedelta
from candolint import adapters
from candolint.models import database, Project, Change, Check
def setup_module():
with database.transaction():
Project.create(
url='https://example.com/alice/test-models',
domain='example.com',
user='alice',
name='test-models')
def test_get_title():
project = Project()
project.domain = 'example.com'
project.user = 'alice'
project.name = 'hello-world'
assert project.get_title() == 'alice/hello-world'
project.domain = 'hello-world.com'
project.user = None
project.name = 'central'
assert project.get_title() == 'hello-world.com/central'
def test_duration():
now = datetime.now()
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():
data = {
'rev': 42,
'node': '92cfceb39d57d914ed8b14d0e37643de0797ae56',
'branch': 'default',
'date': datetime.now(),
'author': 'alice',
'message': 'project: add a thing',
'project': Project.get(name='test-models')
}
with database.transaction():
change, created = Change.manual_upsert(**data)
assert change is not None
assert created
change = Change.get(id=change.id)
assert change.rev == 42
old_id = change.id
data['rev'] = None
with database.transaction():
change, created = Change.manual_upsert(**data)
assert change is not None
assert not created
change = Change.get(id=change.id)
assert change.rev is None
assert change.id == old_id
def test_get_adapter():
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)