Blame view

tests/backend_tests.py 1.57 KB
f079f974   hitier   Backend tests get...
1
2
import os
import sys
506d2f02   hitier   Initialize unit t...
3
import unittest
f079f974   hitier   Backend tests get...
4
from shutil import copyfile
b48d8e69   hitier   Changed charges_b...
5

506d2f02   hitier   Initialize unit t...
6
from pdc_config import TestConfig
7b74daf6   hitier   New User role man...
7
8
from app import create_app, db_mgr, db
from app.auth.models import User
a84fcae0   hitier   Extract code to c...
9
from tests.common_db_feed import resources_to_instancedb
506d2f02   hitier   Initialize unit t...
10
11


506d2f02   hitier   Initialize unit t...
12
13
class BaseTestCase(unittest.TestCase):
    def setUp(self):
f079f974   hitier   Backend tests get...
14
        # initialise app
506d2f02   hitier   Initialize unit t...
15
        self.app = create_app(TestConfig)
a84fcae0   hitier   Extract code to c...
16
        self.db_path = resources_to_instancedb(self.app)
f079f974   hitier   Backend tests get...
17
18
19
20
21
22
23

        # force db path to newly create file
        self.app.config.update(
            SQLALCHEMY_DATABASE_URI='sqlite:///' + self.db_path
        )

        # update flask context
506d2f02   hitier   Initialize unit t...
24
25
        self.app_context = self.app.app_context()
        self.app_context.push()
506d2f02   hitier   Initialize unit t...
26
27

    def tearDown(self):
f079f974   hitier   Backend tests get...
28
29
        if os.path.isfile(self.db_path):
            os.remove(self.db_path)
506d2f02   hitier   Initialize unit t...
30
31
32
33
        self.app_context.pop()

    def test_always_true(self):
        self.assertTrue(True)
1aeda847   hitier   Two db request wr...
34
35
36
37
38
39
40
41
42
43
44


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)
9c7c1dfa   hitier   Fix test with new...
45
        self.assertEqual(17, len(all_charges))
7b74daf6   hitier   New User role man...
46

b48d8e69   hitier   Changed charges_b...
47
48
49
50
51
52
53
54
55
    def test_charges_by_agent_stacked(self):
        stacked_charges = db_mgr.charges_by_agent_stacked(60)
        # Waiting for 17 periods + headers line
        self.assertEqual(18, len(stacked_charges))

    def test_charges_by_project_stacked(self):
        stacked_charges = db_mgr.charges_by_project_stacked(60)
        # Waiting for 17 periods + headers line
        self.assertEqual(18, len(stacked_charges))