예제 #1
0
파일: sql.py 프로젝트: k1r91/course2
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()
예제 #2
0
파일: test_db.py 프로젝트: k1r91/course2
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()
예제 #3
0
파일: sql.py 프로젝트: k1r91/course2
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()
예제 #4
0
파일: sql.py 프로젝트: k1r91/course2
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()
예제 #5
0
파일: reports.py 프로젝트: k1r91/course2
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))
예제 #6
0
파일: test_db.py 프로젝트: k1r91/course2
 def setUp(self):
     self.db_trans = DB()
     self.db_org = DatabaseOrganization()
예제 #7
0
 def initialize_bases(self):
     self.db_trans = DB()
     self.db_org = DatabaseOrganization()