summaryrefslogtreecommitdiff
path: root/examples/flask_alchemy/test_demoapp.py
blob: b485a924add2491b94b84a3aac23f31660388b86 (plain)
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
import os
import unittest
import tempfile

import demoapp
import demoapp_factories

class DemoAppTestCase(unittest.TestCase):

    def setUp(self):
        demoapp.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
        demoapp.app.config['TESTING'] = True
        self.app = demoapp.app.test_client()
        self.db = demoapp.db
        self.db.create_all()

    def tearDown(self):
        self.db.drop_all()

    def test_user_factory(self):
        user = demoapp_factories.UserFactory()
        self.db.session.commit()
        self.assertIsNotNone(user.id)
        self.assertEqual(1, len(demoapp.User.query.all()))

    def test_userlog_factory(self):
        userlog = demoapp_factories.UserLogFactory()
        self.db.session.commit()
        self.assertIsNotNone(userlog.id)
        self.assertIsNotNone(userlog.user.id)
        self.assertEqual(1, len(demoapp.User.query.all()))
        self.assertEqual(1, len(demoapp.UserLog.query.all()))

if __name__ == '__main__':
    unittest.main()