forked from ctb/meep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_meeplib.py
71 lines (63 loc) · 1.81 KB
/
test_meeplib.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
import unittest
import meeplib
# note:
#
# functions start within test_ are discovered and run
# between setUp and tearDown;
# setUp and tearDown are run *once* for *each* test_ function.
class TestMeepLib(unittest.TestCase):
#will be run prior to every test
def setUp(self):
u = meeplib.User('foo', 'bar')
print "\n add m"
m = meeplib.Message('the title', 'the content', u, -1, {})
print len(meeplib.get_all_messages())
def test_for_message_existence(self):
print "test for message existence"
messages = meeplib.get_all_messages()
for m in messages:
print m.post
print len(messages)
assert len(messages) == 1
assert messages[0].title == 'the title'
assert messages[0].post == 'the content'
meeplib._reset()
def test_message_ownership(self):
users = meeplib.get_all_users()
for u in users:
print u.username
assert len(users) == 1 #two hardcoded and one added above
u = users[0]
messages = meeplib.get_all_messages()
assert len(messages) == 1
m = messages[0]
assert m.author == u
meeplib._reset()
def test_get_next_user(self):
id = meeplib._get_next_user_id()
assert id != None
meeplib._reset()
def test_tearDown(self):
print "test teardown"
users = meeplib.get_all_users()
for user in users:
meeplib.delete_user(user)
print meeplib._user_ids
messages = meeplib.get_all_messages()
for m in messages:
meeplib.delete_message(m)
print len(meeplib._user_ids)
assert len(meeplib._messages) == 0
assert len(meeplib._users) == 0
assert len(meeplib._user_ids) == 0
meeplib._reset()
def testAddUser_newportt(self):
print "test add user"
meeplib.User("cait","test")
meeplib.User('new', 'test')
for user in meeplib.get_all_users():
print user.username
assert len(meeplib._users) == 3
meeplib._reset()
if __name__ == '__main__':
unittest.main()