-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_models.py
111 lines (81 loc) · 3 KB
/
test_models.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from datetime import datetime
from domain import make_url_item, make_text_item, List, Tree, DATE_FORMAT
from users import User, Realm
def test_news():
import pytest
item = make_url_item('Loogica News', 'http://news.loogica.net')
news = List('main')
news.add(item)
assert 1 == len(news.items)
with pytest.raises(Exception):
news.vote(10)
assert item == news.vote(1, 1)
assert 1 == news.items[0]['votes']
assert item == news.vote(1, -1)
assert 0 == news.items[0]['votes']
new_item = make_url_item('New Video', 'http://loogica.net/videos', owner='tester')
news.add(new_item)
assert 2 == len(news.items)
assert None == news.items[0]['owner']
assert 'tester' == news.items[1]['owner']
assert new_item == news.vote(2, 1)
assert 1 == news.items[1]['votes']
assert new_item == news.vote(2, 1)
assert 2 == news.items[1]['votes']
news.remove(1)
assert 1 == len(news.items)
assert 2 == news.items[0]['votes']
for i in range(20):
new_item = make_url_item('New Video', 'http://loogica.net/videos')
news.add(new_item)
assert 10 == len(news.get_items())
new_item = make_url_item('New Video', 'http://loogica.net/videos', owner='tester')
news.add(new_item)
user_data = news.get_user_items('tester')
assert 2 == len(user_data)
d1 = datetime.strptime(user_data[0]['posted'], DATE_FORMAT)
d2 = datetime.strptime(user_data[1]['posted'], DATE_FORMAT)
assert d1 < d2
root = Tree()
assert news == root.add('main', news)
assert 'main' in root.children
def test_news_comments():
item = make_url_item('Loogica News', 'http://news.loogica.net')
news = List('main')
news.add(item)
assert 1 == len(news.items)
assert 0 == len(news.items[0]['comments'])
news.add_comment(1, 1, 'positive comment')
assert 1 == len(news.items[0]['comments'])
news.del_comment(1, 1)
assert 0 == len(news.items[0]['comments'])
def test_user():
user = User("tester", "testerpass")
assert user
assert 'tester' == user['username']
assert {} == user['profile']
realm = Realm('test')
assert 0 == len(realm.users)
realm.add_user(user)
assert 1 == len(realm.users)
assert True == realm.authenticate('tester', 'testerpass')
def test_tree():
root = Tree('root')
assert 0 == len(root.children)
assert 'root' == root.name
root.add('main')
assert 1 == len(root.children)
root.add('main/specific')
assert 1 == len(root.children)
assert 1 == len(root.children['main'].children)
assert Tree('specific') == root.children['main'].children['specific']
assert Tree('specific') == root.get('main/specific')
root.add('main/specific/sub')
assert isinstance(root.get('main/specific/sub').items, List)
def test_tree_list():
root = Tree('root')
root.add('faq')
root.add('faq/pgto')
item = make_text_item('Title', 'Text')
root.add_item('faq/pgto', item)
assert 'Title' == root.get('faq/pgto').items.items[0]['title']