Commit 1aeda84735c0e3850b2be74a237203b422633736
1 parent
9183e41e
Exists in
master
and in
4 other branches
Two db request wrappers
Showing
2 changed files
with
28 additions
and
1 deletions
Show diff stats
app/db_mgr.py
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +from app.models import db, Agent, Charge | ||
2 | + | ||
3 | + | ||
4 | +def agents(): | ||
5 | + all_agents = [a.firstname for a in Agent.query.all()] | ||
6 | + return all_agents | ||
7 | + | ||
8 | + | ||
9 | +def charges_by_agent(agent_id): | ||
10 | + # all_charges = db.session.query(Charge).all() | ||
11 | + sql_txt = "select sum(charge_rate), p.name from charge inner join period p on charge.period_id = p.id\ | ||
12 | + where agent_id={} group by period_id order by p.name"\ | ||
13 | + .format(agent_id) | ||
14 | + request = db.session.execute(sql_txt) | ||
15 | + return request.fetchall() |
tests/backend_tests.py
1 | import unittest | 1 | import unittest |
2 | from pdc_config import TestConfig | 2 | from pdc_config import TestConfig |
3 | -from app import create_app | 3 | +from app import create_app, db_mgr |
4 | 4 | ||
5 | 5 | ||
6 | class BaseTestCase(unittest.TestCase): | 6 | class BaseTestCase(unittest.TestCase): |
@@ -15,3 +15,15 @@ class BaseTestCase(unittest.TestCase): | @@ -15,3 +15,15 @@ class BaseTestCase(unittest.TestCase): | ||
15 | 15 | ||
16 | def test_always_true(self): | 16 | def test_always_true(self): |
17 | self.assertTrue(True) | 17 | self.assertTrue(True) |
18 | + | ||
19 | + | ||
20 | +class DbMgrTestCase(BaseTestCase): | ||
21 | + | ||
22 | + def test_agents(self): | ||
23 | + all_agents = db_mgr.agents() | ||
24 | + print(len(all_agents)) | ||
25 | + self.assertEqual(548, len(all_agents)) | ||
26 | + | ||
27 | + def test_charges_by_agent(self): | ||
28 | + all_charges = db_mgr.charges_by_agent(355) | ||
29 | + self.assertEqual(6, len(all_charges)) |