PageRenderTime 385ms CodeModel.GetById 191ms app.highlight 19ms RepoModel.GetById 172ms app.codeStats 1ms

/sqlautocode/tests/base.py

https://code.google.com/p/sqlautocode/
Python | 91 lines | 65 code | 20 blank | 6 comment | 4 complexity | 1f03f8f8c60d0be5761a9eebe4ddcd9d MD5 | raw file
 1import os
 2from sqlalchemy import *
 3
 4
 5metadata = MetaData()
 6
 7environment =  Table('environment', metadata,
 8    Column(u'environment_id', Numeric(precision=10, scale=0, asdecimal=True), primary_key=True, nullable=False),
 9            Column(u'environment_name', String(length=100, convert_unicode=False, assert_unicode=None), primary_key=False, nullable=False),
10            Column(u'database_host', String(length=100, convert_unicode=False, assert_unicode=None), primary_key=False, nullable=False),
11            Column(u'database_port', String(length=5, convert_unicode=False, assert_unicode=None), primary_key=False, nullable=False),
12            Column(u'database_sid', String(length=32, convert_unicode=False, assert_unicode=None), primary_key=False, nullable=False),
13            Column(u'database_user', String(length=100, convert_unicode=False, assert_unicode=None), primary_key=False, nullable=False),
14            Column(u'database_pass', String(length=100, convert_unicode=False, assert_unicode=None), primary_key=False, nullable=False),
15    
16    
17    )
18
19
20report =  Table('report', metadata,
21    Column(u'report_id', Numeric(precision=10, scale=0, asdecimal=True), primary_key=True, nullable=False),
22            Column(u'environment_id', Numeric(precision=10, scale=0, asdecimal=True), primary_key=False, nullable=False),
23            Column(u'report_name', String(length=50, convert_unicode=False, assert_unicode=None), primary_key=False, nullable=False),
24            Column(u'report_description', String(length=4000, convert_unicode=False, assert_unicode=None), primary_key=False),
25            Column(u'deleted', Numeric(precision=1, scale=0, asdecimal=True), primary_key=False, nullable=False),
26            Column(u'created_date', DateTime(timezone=False), primary_key=False, nullable=False),
27            Column(u'created_by', Numeric(precision=10, scale=0, asdecimal=True), primary_key=False, nullable=False),
28            Column(u'updated_date', DateTime(timezone=False), primary_key=False, nullable=False),
29            Column(u'updated_by', Numeric(precision=10, scale=0, asdecimal=True), primary_key=False, nullable=False),
30            Column(u'deleted_date', DateTime(timezone=False), primary_key=False),
31            Column(u'deleted_by', Numeric(precision=10, scale=0, asdecimal=True), primary_key=False),
32            ForeignKeyConstraint([u'environment_id'], [u'environment.environment_id'], name='REPORT_FK_ENV_ID'),
33    
34    )
35
36
37ui_report =  Table('ui_report', metadata,
38    Column(u'ui_report_id', Numeric(precision=10, scale=0, asdecimal=True), primary_key=True, nullable=False),
39            Column(u'report_id', Numeric(precision=10, scale=0, asdecimal=True), primary_key=False, nullable=False),
40            Column(u'environment_id', Numeric(precision=10, scale=0, asdecimal=True), primary_key=False, nullable=False),
41            Column(u'ui_report_name', String(length=100, convert_unicode=False, assert_unicode=None), primary_key=False, nullable=False),
42            Column(u'ui_report_description', String(length=4000, convert_unicode=False, assert_unicode=None), primary_key=False),
43            Column(u'enabled', Numeric(precision=1, scale=0, asdecimal=True), primary_key=False, nullable=False),
44            Column(u'deleted', Numeric(precision=1, scale=0, asdecimal=True), primary_key=False, nullable=False),
45            Column(u'created_date', DateTime(timezone=False), primary_key=False, nullable=False),
46            Column(u'created_by', Numeric(precision=10, scale=0, asdecimal=True), primary_key=False, nullable=False),
47            Column(u'updated_date', DateTime(timezone=False), primary_key=False, nullable=False),
48            Column(u'updated_by', Numeric(precision=10, scale=0, asdecimal=True), primary_key=False, nullable=False),
49            Column(u'deleted_date', DateTime(timezone=False), primary_key=False),
50            Column(u'deleted_by', Numeric(precision=10, scale=0, asdecimal=True), primary_key=False),
51            ForeignKeyConstraint([u'report_id'], [u'report.report_id'], name='UI_REPORT_FK_REPORT_ID'),
52            ForeignKeyConstraint([u'environment_id'], [u'environment.environment_id'], name='UI_REPORT_FK_ENV_ID'),
53    
54    )
55
56bound = False
57def make_test_db():
58    global bound, metadata
59    if not bound:
60        testdb_filename = os.path.abspath(os.path.dirname(__file__))+'/data/testdb.db'
61        #try:
62        #    os.remove(testdb_filename)
63        #except OSError:
64        #    pass
65        
66        db = 'sqlite:///'+testdb_filename
67        
68        test_engine = create_engine(db)
69        metadata.bind =test_engine
70        #metadata.create_all()
71        bound = True
72    return metadata
73
74bound_multi = False
75metadata_multi = MetaData()
76def make_test_db_multi():
77    global bound_multi, metadata_multi
78    if not bound_multi:
79        testdb_filename = os.path.abspath(os.path.dirname(__file__))+'/data/multi.db'
80        #testdb_filename = os.path.abspath(os.path.dirname(__file__))+'/data/devdata.db'
81        
82        db = 'sqlite:///'+testdb_filename
83        
84        test_engine = create_engine(db)
85        metadata_multi.bind =test_engine
86        metadata_multi.reflect()
87        bound_multi = True
88    return metadata_multi
89
90
91