Download:
child 130:7a9e1f1ae89f
parent 128:a93fdb7416f0
129:3a25896f01e1
Anton Shestakov <av6@dwimlabs.net>, Fri, 08 Jul 2016 00:16:33 +0800
tests: test BaseModel.manual_upsert()

1 файлов изменено, 41 вставок(+), 1 удалений(-) [+]
tests/test_models.py file | annotate | diff | comparison | revisions
--- 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
@@ -1,6 +1,15 @@
from datetime import datetime, timedelta
-from candolint.models import Project, Check
+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():
@@ -28,3 +37,34 @@
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