Blame view

tests/backend_tests.py 1.57 KB
506d2f02   hitier   Initialize unit t...
1
2
import unittest
from pdc_config import TestConfig
7b74daf6   hitier   New User role man...
3
4
from app import create_app, db_mgr, db
from app.auth.models import User
506d2f02   hitier   Initialize unit t...
5
6
7
8
9


class BaseTestCase(unittest.TestCase):
    def setUp(self):
        # configure data base
506d2f02   hitier   Initialize unit t...
10
11
12
        self.app = create_app(TestConfig)
        self.app_context = self.app.app_context()
        self.app_context.push()
7b74daf6   hitier   New User role man...
13
        db.create_all()
42c07429   hitier   Default role valu...
14
        admin = User(email='admin@nowhere.org', name='admin', login='admin', password='admin', role='admin')
7b74daf6   hitier   New User role man...
15
16
        db.session.add(admin)
        db.session.commit()
506d2f02   hitier   Initialize unit t...
17
18
19
20
21
22

    def tearDown(self):
        self.app_context.pop()

    def test_always_true(self):
        self.assertTrue(True)
1aeda847   hitier   Two db request wr...
23
24
25
26
27
28
29
30
31
32
33
34


class DbMgrTestCase(BaseTestCase):

    def test_agents(self):
        all_agents = db_mgr.agents()
        print(len(all_agents))
        self.assertEqual(548, len(all_agents))

    def test_charges_by_agent(self):
        all_charges = db_mgr.charges_by_agent(355)
        self.assertEqual(6, len(all_charges))
7b74daf6   hitier   New User role man...
35
36
37
38
39
40


class AuthModelTestCase(BaseTestCase):

    def test_setrole(self):
        admin = User.query.filter(User.name == 'admin').one_or_none()
42c07429   hitier   Default role valu...
41
        admin.set_role("ADMIN")
7b74daf6   hitier   New User role man...
42
43
44
        db.session.commit()
        admin = User.query.filter(User.name == 'admin').one_or_none()
        self.assertTrue(admin is not None)
42c07429   hitier   Default role valu...
45
46
        self.assertTrue(admin.has_role("ADMIN"))
        self.assertFalse(admin.has_role("SERVICE"))
7b74daf6   hitier   New User role man...
47
48

    def test_setrole_valueerror(self):
42c07429   hitier   Default role valu...
49
        admin = User(email='me@nowhere.org', name='me', login='me', password='me', role='admin')
7b74daf6   hitier   New User role man...
50
        with self.assertRaises(ValueError) as ve:
42c07429   hitier   Default role valu...
51
            admin.set_role("NOSUCHROLE")