def get_org_types(): db_tr = DB() db_trans = db_tr.cursor db_or = DatabaseOrganization() db_org = db_or.cursor query = 'SELECT * FROM org_type' return db_org.execute(query).fetchall()
class TestDb(unittest.TestCase): def setUp(self): self.db_trans = DB() self.db_org = DatabaseOrganization() def test_db_trans_already_filled(self): """To pass test, run first db.py """ with self.assertRaises(sqlite3.IntegrityError): self.db_trans.fill_terminal() def test_db_org_already_filled(self): """To pass test, run first db.py """ with self.assertRaises(sqlite3.IntegrityError): self.db_org.fill_collectors()
def get_org_by_type(type_id): db_tr = DB() db_trans = db_tr.cursor db_or = DatabaseOrganization() db_org = db_or.cursor query = 'SELECT organization.id, organization.name, org_type.name, organization.logo FROM organization INNER JOIN' \ ' org_type ON org_type.id=organization.type WHERE organization.type=?' return db_org.execute(query, (type_id, )).fetchall()
def get_org_and_types(): db_tr = DB() db_trans = db_tr.cursor db_or = DatabaseOrganization() db_org = db_or.cursor query = '''SELECT organization.id, organization.name, org_type.name FROM organization INNER JOIN org_type ON organization.type=org_type.id''' return db_org.execute(query).fetchall()
import os from datetime import datetime from collections import OrderedDict from deco import time_it from db import DatabaseOrganization, DB db_org = DatabaseOrganization() db_trans = DB() org_cursor = db_org.conn.cursor() trans_cursor = db_trans.conn.cursor() def check_instance(date): if date and not isinstance(date, datetime): raise TypeError('Parameter {} must be a datetime.datetime class.'.format(date)) def select_transactions_by_var(variable, id, start=None, end=None): check_instance(start) check_instance(end) if start and end and start > end: raise ValueError('Start date must be lower than and date') if not start: query = '''SELECT datetime FROM ps_transaction LIMIT 1''' datetime_data = trans_cursor.execute(query).fetchone()[0] start = datetime.strptime(datetime_data, '%Y-%m-%d %H:%M:%S') if not end: end = datetime.now().strftime('%Y-%m-%d %H:%M:%S') query = 'SELECT * FROM ps_transaction WHERE {} = ? AND datetime >=? AND datetime <= ? AND type = 1'.format(variable) result = trans_cursor.execute(query, (id, start, end))
def setUp(self): self.db_trans = DB() self.db_org = DatabaseOrganization()
def initialize_bases(self): self.db_trans = DB() self.db_org = DatabaseOrganization()