-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_message_model.py
83 lines (55 loc) · 1.86 KB
/
test_message_model.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
import os
from unittest import TestCase
from sqlalchemy.exc import IntegrityError
from models import db, User, Message, Follow, Like, DEFAULT_IMAGE_URL
os.environ['DATABASE_URL'] = "postgresql:///warbler_test"
from app import app
db.drop_all()
db.create_all()
Msg1 = dict(text='testing1', user_id=1)
Msg2 = dict(text='testing2', user_id=2)
class MessageModelTestCase(TestCase):
''' Tests message model '''
def setUp(self):
Message.query.delete()
User.query.delete()
db.session.commit()
m1 = Message(**Msg1)
m2 = Message(**Msg2)
u1 = User.signup("u1", "[email protected]", "password", None)
u2 = User.signup("u2", "[email protected]", "password", None)
# must append here, the rest, including the db relationships,
# is abstracted away
u1.messages.append(m1)
u2.messages.append(m2)
db.session.commit()
self.u1_id = u1.id
self.u2_id = u2.id
self.m1_id = m1.id
self.m2_id = m2.id
def tearDown(self):
db.session.rollback()
def test_message_model(self):
'''Tests message model'''
m1 = Message.query.get(self.m1_id)
self.assertEqual(m1.text, 'testing1')
self.assertIsInstance(m1, Message)
def test_users_messages(self):
'''Tests message model'''
u1 = User.query.get(self.u1_id)
m1 = Message.query.get(self.m1_id)
self.assertEqual(len(u1.messages), 1)
self.assertIs(u1.messages[0], m1)
def test_add_message(self):
u1 = User.query.get(self.u1_id)
u1.messages.append(Message(**Msg1))
db.session.commit()
self.assertEqual(len(u1.messages), 2)
def test_like_message(self):
pass
def test_unlike_message(self):
pass
def test_delete_message(self):
pass
def test_empty_message(self):
pass