-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
42 lines (30 loc) · 990 Bytes
/
test.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
import unittest
from app import db, create_app
from app.models import User, Jrnl
from config import Config
class TestConfig(Config):
TESTING = True
SQLALCHEMY_DATABASE_URI = 'sqlite://'
ELASTICSEARCH_URL = None
class JrnlModelCase(unittest.TestCase):
def setUp(self):
self.app = create_app(TestConfig)
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
def test_add_post(self):
a = User(username='lukasz')
db.session.add(a)
db.session.commit()
p = Jrnl(author=a, body='Abc')
db.session.add(p)
db.session.commit()
self.assertEqual(1, Jrnl.get_news().count())
p = Jrnl(author=a, body='Bcd')
db.session.add(p)
db.session.commit()
self.assertEqual(2, Jrnl.get_news().count())
self.assertEqual('Bcd', Jrnl.get_news().first().body)