--- a/tests/test_models.py Fri Jul 08 00:15:17 2016 +0800
+++ b/tests/test_models.py Fri Jul 08 00:16:33 2016 +0800
from datetime import datetime, timedelta
-from candolint.models import Project, Check
+from candolint.models import database, Project, Change, Check
+ with database.transaction():
+ url='https://example.com/alice/test-models',
check.finished = now + timedelta(hours=2)
assert check.get_duration() == '120 min'
+def test_manual_upsert():
+ 'node': '92cfceb39d57d914ed8b14d0e37643de0797ae56',
+ 'date': datetime.now(),
+ '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
+ change = Change.get(id=change.id)
+ assert change.rev == 42
+ 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