-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_message_model.py
65 lines (43 loc) · 1.47 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
"""Message model tests."""
from app import app
import os
from unittest import TestCase
from sqlalchemy.exc import IntegrityError
from datetime import datetime
from models import db, User, Message, Follows
os.environ['DATABASE_URL'] = "postgresql:///warbler_test"
db.drop_all()
db.create_all()
class MessageModelTestCase(TestCase):
def setUp(self):
Message.query.delete()
User.query.delete()
u1 = User.signup("u1", "[email protected]", "password", None)
u2 = User.signup("u2", "[email protected]", "password", None)
m1 = Message(
text="User 1 sample message",
)
m2 = Message(
text="User 2 sample message",
)
# Builds the relationship for User -> Message
u1.messages.append(m1)
u2.messages.append(m2)
db.session.add(m1, m2)
db.session.commit()
self.u1_id = u1.id
self.u2_id = u2.id
self.m1_id = m1.id
self.m2_id = m2.id
self.client = app.test_client()
def tearDown(self):
db.session.rollback()
def test_create_new_message_success(self):
m1 = Message.query.get(self.m1_id)
self.assertIsInstance(m1, Message)
def test_message_timestamp_success(self):
m1 = Message.query.get(self.m1_id)
self.assertIsInstance(m1.timestamp, datetime)
def test_return_user_object_success(self):
m2 = Message.query.get(self.m2_id)
self.assertIsInstance(m2.user, User)