testSQLengines.py 2.53 KB
Newer Older
1
2
#!/usr/bin/env python2
import os
3
import sys
4
5
sys.path.append("asn2dataModel")

6
7
8
9
10
import logging
import unittest

from sqlalchemy import create_engine

11
12
from commonTests import AllTests
from lotsofdatatypes_model import Base
13

14
15
from lotsofdatatypes_model import My2ndInt_SQL
from LotsOfDataTypes_asn import My2ndInt
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

logging.basicConfig(filename="sql.log")
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)


class CompleteTestingOfSQLMapperWithSQLite(AllTests, unittest.TestCase):
    #engine = create_engine('sqlite:///:memory:', echo=True)
    engine = create_engine('sqlite:///test.db', echo=False)
    Base.metadata.create_all(engine)
    from sqlalchemy.orm import sessionmaker

    SessionFactory = sessionmaker(bind=engine)
    session = SessionFactory()


class CompleteTestingOfSQLMapperWithPostgreSQL(AllTests, unittest.TestCase):
    #engine = create_engine('sqlite:///:memory:', echo=True)
33
    if os.getenv('CIRCLECI') is None:
34
        dburi = 'postgresql+psycopg2://taste:tastedb@localhost/circle_test'
35
36
37
    else:
        dburi = 'postgresql+psycopg2://ubuntu:@localhost/circle_test'
    engine = create_engine(dburi, echo=False)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    Base.metadata.create_all(engine)
    from sqlalchemy.orm import sessionmaker

    SessionFactory = sessionmaker(bind=engine)
    session = SessionFactory()


#jclass CompleteTestingOfSQLMapperWithMySQL(AllTests, unittest.TestCase):
#j    #engine = create_engine('sqlite:///:memory:', echo=True)
#j    engine = create_engine(
#j        'mysql://taste:tastedb@localhost/test', echo=False)
#j    Base.metadata.create_all(engine)
#j    from sqlalchemy.orm import sessionmaker
#j
#j    SessionFactory = sessionmaker(bind=engine)
#j    session = SessionFactory()
#j
#j    def test2_IntegerWithOverridenConstraints(self):
#j        a = My2ndInt()
#j        #
#j        # MySQL does not enforce range constraints.
#j        # Stupid DB engine...
#j        #
#j        ##a.Set(20)  # Valid in referenced type, but overriden in this one
#j        ##bMustFailAndHasFailed = False
#j        ##try:
#j        ##    aa2 = My2ndInt_SQL(a)
#j        ##    aid2 = aa2.save(self.session)
#j        ##except exc.IntegrityError:
#j        ##    bMustFailAndHasFailed = True
#j        ##assert bMustFailAndHasFailed
#j        self.session.rollback()
#j        a.Set(7)
#j        aa2 = My2ndInt_SQL(a)
#j        aid2 = aa2.save(self.session)
#j        self.session.commit()
#j        o2 = My2ndInt_SQL.loadFromDB(self.session, aid2)
#j        assert a.Get() == o2.data
#j        assert a.Get() == o2.asn1.Get()


if __name__ == "__main__":
    unittest.main()