-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sync0.py
59 lines (47 loc) · 1.76 KB
/
test_sync0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pytest
import sync0
from sqlalchemy import create_engine
@pytest.fixture(scope='module', autouse=True)
def init():
sync0.engine = create_engine("sqlite://")
sync0.metadata.create_all(sync0.engine)
@pytest.fixture(scope='function', autouse=True)
def cleanup():
sync0.r.delete('seq_no')
sync0.engine.execute(sync0.tasks.delete())
def test_sync():
# I'm adding a task...
task_id, seq_no = sync0.add_task(1, 'foo')
# I've just added a task, and I know the last sequence number, is there anything new for me?
assert sync0.sync_tasks(1, seq_no) == []
def test_sync_add():
# I'm adding a task...
task_id, seq_no = sync0.add_task(1, 'foo')
# Someone else is adding a task independently from me
sync0.add_task(1, 'bar')
# Let's see what new do we have. I only know my sequence number
tasks = sync0.sync_tasks(1, seq_no)
assert len(tasks) == 1
assert tasks[0]['content'] == 'bar'
def test_sync_edit():
# I'm adding a task...
task_id, seq_no = sync0.add_task(1, 'foo')
# Someone else changes my task
sync0.edit_task(1, task_id, 'bar')
# Let's see what new do we have. I only know my sequence number
tasks = sync0.sync_tasks(1, seq_no)
assert len(tasks) == 1
assert tasks[0]['id'] == task_id
assert tasks[0]['content'] == 'bar'
def test_sync_delete():
# I'm adding a task...
task_id, seq_no = sync0.add_task(1, 'foo')
# Someone else deletes it!
sync0.delete_task(1, task_id)
# Let's see what new do we have. I only know my sequence number
tasks = sync0.sync_tasks(1, seq_no)
assert len(tasks) == 1
assert tasks[0]['id'] == task_id
assert tasks[0]['deleted']
# let's ensure we don't get deleted tasks on initial sync
assert sync0.all_tasks(1) == []