コード例 #1
0
ファイル: views.py プロジェクト: lshumlich/python-playground
def data():
    html = ""
    try:
        db_instance = config.get_database_instance()
        shower = Shower()

        table = request.args.get('table')
        attr = request.args.get('attr')
        key = request.args.get('key')
        links = {}
        links['BAid'] = '?table=BAInfo&attr=BAid&key='
        links['WellEvent'] = '?table=WellInfo&attr=Well&key='

        tables = db_instance.get_table_names()
        header = None
        rows = None
        print('Table:', table)
        if table:
            header = shower.show_columns(table)
            rows = shower.show_table(table, attr, key)
        html = render_template('data.html',
                               table=table,
                               tables=tables,
                               header=header,
                               rows=rows,
                               links=links)
    except Exception as e:
        print('views.data: ***Error:', e)
        traceback.print_exc(file=sys.stdout)
    return html
コード例 #2
0
    def test_execute_statement_delete_table(self):
        self.assertEqual(
            config.get_environment(),
            'unittest')  # Destructive Tests must run in unittest environment
        dbi = config.get_database_instance()
        dbu = DatabaseUtilities()
        dbu.delete_all_tables()
        self.assertEqual(len(dbi.get_table_names()), 0,
                         'These should be no tables in the database.')

        statement = """
            CREATE TABLE table1 ('ID' int, 'Name' text);
            CREATE TABLE table2 ('ID' int, 'Name' text);
            CREATE TABLE table3 ('ID' int, 'Name' text);
        """
        dbi.execute_statement(statement)
        self.assertEqual(len(dbi.get_table_names()), 3)
        self.assertIn('table2', dbi.get_table_names())

        dbu.delete_table('table2')
        self.assertEqual(len(dbi.get_table_names()), 2)
        self.assertNotIn('table2', dbi.get_table_names())

        dbu.delete_all_tables()
        self.assertEqual(len(dbi.get_table_names()), 0,
                         'These should be no tables in the database.')
コード例 #3
0
def get_link_row():
    utils = Utils()
    db = config.get_database()
    try:
        print('AppServer.get_link_row running', request.method)
        print('Instance:', config.get_database_name(), config.get_environment())
        print('Tables', config.get_database_instance().get_table_names())
        data = utils.json_decode(request)
        link = db.select("LinkTab", TabName=data['TabName'], AttrName=data['AttrName'])
        print('link', link)
        if not link:
            data['ID'] = 0
            data['LinkName'] = ''
            data['BaseTab'] = 0
            data['ShowAttrs'] = ''
        else:
            data['ID'] = link[0].ID
            data['LinkName'] = link[0].LinkName
            data['BaseTab'] = link[0].BaseTab
            data['ShowAttrs'] = link[0].ShowAttrs

        return json.dumps(data)

    except Exception as e:
        print('AppServer.link: ***Error:', e)
        traceback.print_exc(file=sys.stdout)
コード例 #4
0
 def test_set_methods(self):
     """ this tests all of the set methods since they need to work together """
     save_config_file = config.ConfigObject.CONFIG_FILE 
     
     # Test the default with no file is 'unittest'
     config.reset()
     config.ConfigObject.CONFIG_FILE = 'badfile.xxx'
     self.assertEqual(config.get_environment(), 'unittest')
     
     config.ConfigObject.CONFIG_FILE = save_config_file
     
     # test that if we the database name we have an unknown environmentwe
     config.reset()
     config.set_database_name(':memory:')
     self.assertEqual(config.get_environment(), '????')
     
     # test that if we the database name we have an unknown environmentwe
     config.reset()
     config.set_enviornment('test')
     self.assertTrue(config.get_database_name())
     
     # test that we have an instance and database
     config.reset()
     self.assertTrue(config.get_environment()) # All these values must be set... Can't test to what though
     self.assertTrue(config.get_database_name())
     self.assertTrue(config.get_database_instance())
     self.assertTrue(config.get_database())
コード例 #5
0
ファイル: views.py プロジェクト: lshumlich/python-playground
def get_link_row():
    utils = Utils()
    db = config.get_database()
    try:
        print('AppServer.get_link_row running', request.method)
        print('Instance:', config.get_database_name(),
              config.get_environment())
        print('Tables', config.get_database_instance().get_table_names())
        data = utils.json_decode(request)
        link = db.select("LinkTab",
                         TabName=data['TabName'],
                         AttrName=data['AttrName'])
        print('link', link)
        if not link:
            data['ID'] = 0
            data['LinkName'] = ''
            data['BaseTab'] = 0
            data['ShowAttrs'] = ''
        else:
            data['ID'] = link[0].ID
            data['LinkName'] = link[0].LinkName
            data['BaseTab'] = link[0].BaseTab
            data['ShowAttrs'] = link[0].ShowAttrs

        return json.dumps(data)

    except Exception as e:
        print('AppServer.link: ***Error:', e)
        traceback.print_exc(file=sys.stdout)
コード例 #6
0
def data():
    html = ""
    try:
        db_instance = config.get_database_instance()
        shower = Shower()

        table = request.args.get('table')
        attr = request.args.get('attr')
        key = request.args.get('key')
        links = {}
        links['BAid'] = '?table=BAInfo&attr=BAid&key='
        links['WellEvent'] = '?table=WellInfo&attr=Well&key='

        tables = db_instance.get_table_names()
        header = None
        rows = None
        print('Table:', table)
        if table:
            header = shower.show_columns(table)
            rows = shower.show_table(table, attr, key)
        html = render_template('admin/data.html', table=table, tables=tables, header=header, rows=rows, links=links)
    except Exception as e:
        print('views.data: ***Error:', e)
        traceback.print_exc(file=sys.stdout)
    return html
コード例 #7
0
    def test_set_methods(self):
        """ this tests all of the set methods since they need to work together """
        save_config_file = config.ConfigObject.CONFIG_FILE

        # Test the default with no file is 'unittest'
        config.reset()
        config.ConfigObject.CONFIG_FILE = 'badfile.xxx'
        self.assertEqual(config.get_environment(), 'unittest')

        config.ConfigObject.CONFIG_FILE = save_config_file

        # test that if we the database name we have an unknown environmentwe
        config.reset()
        config.set_database_name('MyTest.db')
        self.assertEqual(config.get_environment(), '????')
        os.remove('MyTest.db')

        # test that if we the database name we have an unknown environmentwe
        config.reset()
        config.set_enviornment('test')
        self.assertTrue(config.get_database_name())

        # test that we have an instance and database
        config.reset()
        self.assertTrue(config.get_environment(
        ))  # All these values must be set... Can't test to what though
        self.assertTrue(config.get_database_name())
        self.assertTrue(config.get_database_instance())
        self.assertTrue(config.get_database())
コード例 #8
0
 def setUp(self):
     self.assertEqual(config.get_environment(),'unittest') # Distructive Tests must run in unittest enviornment
     self.dbi = config.get_database_instance()
     self.db = config.get_database()
     self.dbu = DatabaseUtilities()
     self.db_create = DatabaseCreate()
     
     self.dbu.delete_all_tables()
コード例 #9
0
    def setUp(self):
        self.assertEqual('unittest', config.get_environment())  # Destructive Tests must run in unittest environment
        self.dbi = config.get_database_instance()
        self.db = config.get_database()
        self.dbu = DatabaseUtilities()
        self.db_create = DatabaseCreate()

        self.dbu.delete_all_tables()
コード例 #10
0
    def setUp(self):
        self.assertEqual(config.get_environment(),'unittest') # Distructive Tests must run in unittest enviornment
        db_utils = DatabaseUtilities()
        db_utils.delete_all_tables()

        instance = config.get_database_instance()
        instance.execute('create table ' + self.TEST_TABLE_NAME  + ' (myKey int, myText text, myDate date)')
        instance.commit()
        
        instance.execute('insert into ' + self.TEST_TABLE_NAME + " values (1, 'Test Item One', '2016-02-14')")
        instance.execute('insert into ' + self.TEST_TABLE_NAME + " values (2, 'Test Item Two', '2016-02-14')")
        instance.commit()
コード例 #11
0
    def test_get_column_name(self):
        instance = config.get_database_instance()
        db_utils = DatabaseUtilities()
        db_utils.delete_all_tables()

        instance.execute('create table ' + self.TEST_TABLE_NAME  + ' (myKey int, myText text, myDate date)')
        instance.execute('insert into ' + self.TEST_TABLE_NAME + " values (1, 'Test Item One', '2016-02-14')")
        
        instance.execute('select * from ' + self.TEST_TABLE_NAME)
        
        columns = instance.get_column_names()
        self.assertEqual(columns[0],'myKey')
        self.assertEqual(columns[1],'myText')
        self.assertEqual(columns[2],'myDate')
コード例 #12
0
    def test_all_features(self):
        instance = config.get_database_instance()

        self.assertIn(self.TEST_TABLE_NAME, instance.get_table_names(), 'Should have created table: ' + self.TEST_TABLE_NAME)

        selectStmt = 'select * from ' + self.TEST_TABLE_NAME + ' order by myKey'
        values = instance.execute(selectStmt)

        rows = []
        for row in values:
            rows.append(row)

        self.assertEqual(2,len(rows), 'Should be two rows in the table')
        self.assertEqual(1,rows[0][0], 'First key should be 1')
        self.assertEqual(2,rows[1][0], 'First key should be 1')
コード例 #13
0
    def test_run(self):
        #Testing loading an Excel spreadsheet into an sqlite3 database.
#         print ("Creating temporary database %s" % self.TEST_DATABASE)

        self.assertEqual(config.get_environment(),'unittest') # Distructive Tests must run in unittest enviornment

        dbu = DatabaseUtilities()
        dbc = DatabaseCreate()
        loader = Loader()
        dbu.delete_all_tables()
        dbc.create_all()
        dbi = config.get_database_instance()
        
        
        loader.connect()
        loader.open_excel(self.TEST_SPREADSHEET)
        shower = Shower()
        shower.connect()

        #Test that the worksheet has x number of tabs
        self.assertEqual(len(loader.wb.get_sheet_names()), 2)

        #Test that each tab has x number of columns
        self.assertEqual(len(loader.wb['Well'].columns), 12)
        self.assertEqual(len(loader.wb['Royalty Master'].columns), 11)

        #Test that each tab has x number of rows
        self.assertEqual(len(loader.wb['Well'].rows), 9)
        self.assertEqual(len(loader.wb['Royalty Master'].rows), 11)

#         print(dbi.get_table_names())
#         self.assertEqual(len(dbi.get_table_names()), 0)
# 
#         #Test that we have x number of tables
        loader.load_all_sheets()
#         self.assertEqual(len(dbi.get_table_names()), 2)

        #test that each table has x number of columns
        self.assertEqual(len(shower.show_table('Well')), 8)
        self.assertEqual(len(shower.show_table('RoyaltyMaster')), 10)

        #test that each table has x number of row
        self.assertEqual(len(shower.show_columns('Well')), 12)
        self.assertEqual(len(shower.show_columns('RoyaltyMaster')), 11)

        #test column type
        self.assertEqual(shower.column_type('Well', 'ID'), 'integer')
        loader.commit()
コード例 #14
0
    def test_get_column_name(self):
        instance = config.get_database_instance()
        db_utils = DatabaseUtilities()
        db_utils.delete_all_tables()

        instance.execute('create table ' + self.TEST_TABLE_NAME +
                         ' (myKey int, myText text, myDate date)')
        instance.execute('insert into ' + self.TEST_TABLE_NAME +
                         " values (1, 'Test Item One', '2016-02-14')")

        instance.execute('select * from ' + self.TEST_TABLE_NAME)

        columns = instance.get_column_names()
        self.assertEqual(columns[0], 'myKey')
        self.assertEqual(columns[1], 'myText')
        self.assertEqual(columns[2], 'myDate')
コード例 #15
0
    def test_all_features(self):
        instance = config.get_database_instance()

        self.assertIn(self.TEST_TABLE_NAME, instance.get_table_names(),
                      'Should have created table: ' + self.TEST_TABLE_NAME)

        selectStmt = 'select * from ' + self.TEST_TABLE_NAME + ' order by myKey'
        values = instance.execute(selectStmt)

        rows = []
        for row in values:
            rows.append(row)

        self.assertEqual(2, len(rows), 'Should be two rows in the table')
        self.assertEqual(1, rows[0][0], 'First key should be 1')
        self.assertEqual(2, rows[1][0], 'First key should be 1')
コード例 #16
0
    def setUp(self):
        self.assertEqual(
            config.get_environment(),
            'unittest')  # Distructive Tests must run in unittest enviornment
        db_utils = DatabaseUtilities()
        db_utils.delete_all_tables()

        instance = config.get_database_instance()
        instance.execute('create table ' + self.TEST_TABLE_NAME +
                         ' (myKey int, myText text, myDate date)')
        instance.commit()

        instance.execute('insert into ' + self.TEST_TABLE_NAME +
                         " values (1, 'Test Item One', '2016-02-14')")
        instance.execute('insert into ' + self.TEST_TABLE_NAME +
                         " values (2, 'Test Item Two', '2016-02-14')")
        instance.commit()
コード例 #17
0
    def test_run(self):

        self.assertEqual(
            config.get_environment(),
            'unittest')  # Distructive Tests must run in unittest enviornment

        dbu = DatabaseUtilities()
        # dbc = DatabaseCreate()
        loader = Loader()
        dbu.delete_all_tables()
        dbi = config.get_database_instance()
        db = config.get_database()

        loader.open_excel(self.TEST_SPREADSHEET)

        # Test that the worksheet has x number of tabs
        self.assertEqual(len(loader.wb.get_sheet_names()), 2)

        # Test that each tab has x number of columns
        self.assertEqual(len(loader.wb['Well'].columns), 12)
        self.assertEqual(len(loader.wb['Royalty Master'].columns), 11)

        # Test that each tab has x number of rows
        self.assertEqual(len(loader.wb['Well'].rows), 9)
        self.assertEqual(len(loader.wb['Royalty Master'].rows), 11)

        loader.load_all_sheets()

        # Test that we have x number of tables
        self.assertEqual(len(dbi.get_table_names()), 2)

        # check the rows and columns for well
        rows = db.select('Well')
        self.assertEqual(len(rows), 8)
        self.assertEqual(len(dbi.get_column_names()), 12)

        # check the rows and columns for royalty master
        rows = db.select('RoyaltyMaster')
        self.assertEqual(len(rows), 10)
        self.assertEqual(len(dbi.get_column_names()), 11)
コード例 #18
0
    def test_execute_statement_delete_table(self):
        self.assertEqual(config.get_environment(), 'unittest')  # Distructive Tests must run in unittest enviornment
        dbi = config.get_database_instance()
        dbu = DatabaseUtilities()
        dbu.delete_all_tables()
        self.assertEqual(len(dbi.get_table_names()), 0, 'These should be no tables in the database.')
        
        statement = """
            CREATE TABLE table1 ('ID' int, 'Name' text);
            CREATE TABLE table2 ('ID' int, 'Name' text);
            CREATE TABLE table3 ('ID' int, 'Name' text);
        """
        dbi.execute_statement(statement)
        self.assertEqual(len(dbi.get_table_names()), 3)
        self.assertIn('table2', dbi.get_table_names())

        dbu.delete_table('table2')
        self.assertEqual(len(dbi.get_table_names()), 2)
        self.assertNotIn('table2', dbi.get_table_names())
        
        dbu.delete_all_tables()
        self.assertEqual(len(dbi.get_table_names()), 0, 'These should be no tables in the database.')
コード例 #19
0
    def test_run(self):

        self.assertEqual(config.get_environment(), 'unittest')  # Distructive Tests must run in unittest enviornment

        dbu = DatabaseUtilities()
        # dbc = DatabaseCreate()
        loader = Loader()
        dbu.delete_all_tables()
        dbi = config.get_database_instance()
        db = config.get_database()

        loader.open_excel(self.TEST_SPREADSHEET)

        # Test that the worksheet has x number of tabs
        self.assertEqual(len(loader.wb.get_sheet_names()), 2)

        # Test that each tab has x number of columns
        self.assertEqual(len(loader.wb['Well'].columns), 12)
        self.assertEqual(len(loader.wb['Royalty Master'].columns), 11)

        # Test that each tab has x number of rows
        self.assertEqual(len(loader.wb['Well'].rows), 9)
        self.assertEqual(len(loader.wb['Royalty Master'].rows), 11)

        loader.load_all_sheets()

        # Test that we have x number of tables
        self.assertEqual(len(dbi.get_table_names()), 2)

        # check the rows and columns for well
        rows = db.select('Well')
        self.assertEqual(len(rows), 8)
        self.assertEqual(len(dbi.get_column_names()), 12)

        # check the rows and columns for royalty master
        rows = db.select('RoyaltyMaster')
        self.assertEqual(len(rows), 10)
        self.assertEqual(len(dbi.get_column_names()), 11)
コード例 #20
0
 def connect(self):
     self.dbi = config.get_database_instance()
コード例 #21
0
ファイル: admin.py プロジェクト: lshumlich/python-playground
 def connect(self):
     self.dbi = config.get_database_instance()
コード例 #22
0
 def test_get_database_instance_gives_same_instance(self):
     dbi1 = config.get_database_instance()
     dbi2 = config.get_database_instance()
     self.assertEqual(dbi1, dbi2, 'All instances must be the same.')
コード例 #23
0
        a = ET.SubElement(self.tab, 'UML:Attribute')
        a.set('xmi.id', 'A.' + str(self.attribute_count))
        a.set('name', attribute)

    def prettify(self):
        """Return a pretty-printed XML string for the Element.
        """
        rough_string = ElementTree.tostring(self.root, 'utf-8')
        reparsed = minidom.parseString(rough_string)
        return reparsed.toprettyxml(indent="  ")

# UML:Model

ea = EA_Tables()

dbi = config.get_database_instance()

tables = dbi.get_table_names()
for t in tables:
    ea.table(t)

    c = dbi.execute("PRAGMA table_info(" + t + ");")

    for row in c:
        ea.attribute(row[1])
        # print(row,row[1],row[2])

txt = ea.prettify()

f = open(config.get_temp_dir() + 'ea.xml', 'w')
f.write(txt)
コード例 #24
0
 def __init__(self):
     self.db_instance = config.get_database_instance()
     self.db_create = DatabaseCreate()
コード例 #25
0
 def __init__(self):
     self.dbi = config.get_database_instance()
コード例 #26
0
 def test_get_database_instance_gives_same_instance(self):
     dbi1 = config.get_database_instance()
     dbi2 = config.get_database_instance()
     self.assertEqual(dbi1, dbi2, 'All instances must be the same.')
コード例 #27
0
 def __init__(self):
     self.db_instance = config.get_database_instance()
     self.db_create = DatabaseCreate()
コード例 #28
0
 def __init__(self):
     self.dbi = config.get_database_instance()
コード例 #29
0
        a.set('xmi.id', 'A.' + str(self.attribute_count))
        a.set('name', attribute)

    def prettify(self):
        """Return a pretty-printed XML string for the Element.
        """
        rough_string = ElementTree.tostring(self.root, 'utf-8')
        reparsed = minidom.parseString(rough_string)
        return reparsed.toprettyxml(indent="  ")


# UML:Model

ea = EA_Tables()

dbi = config.get_database_instance()

tables = dbi.get_table_names()
for t in tables:
    ea.table(t)

    c = dbi.execute("PRAGMA table_info(" + t + ");")

    for row in c:
        ea.attribute(row[1])
        # print(row,row[1],row[2])

txt = ea.prettify()

f = open(config.get_temp_dir() + 'ea.xml', 'w')
f.write(txt)