tests.py
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
import unittest
from configparser import ConfigParser
import transaction
from pyramid import testing
from sqlalchemy import create_engine
from opensipkd.base.models import (
DBSession,
Base
)
from opensipkd.base import main
# def _initTestingDB():
# engine = create_engine('postgresql://aagusti:a@localhost/demo')
# Base.metadata.create_all(engine)
# DBSession.configure(bind=engine)
# # with transaction.manager:
# # model = Page('FrontPage', 'This is the front page')
# # DBSession.add(model)
# return DBSession
def settings():
config = ConfigParser()
config.read('/home/aagusti/apps/base/test.ini')
dictionary = {}
for section in config.sections():
dictionary[section] = {}
for option in config.options(section):
try:
dictionary[section][option] = config.get(section, option)
except:
pass
return dictionary
class PageModelTests(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
config = settings()
main(self.config, **config['app:main'])
def tearDown(self):
# self.session.remove()
testing.tearDown()
def test_view_fn_query_table(self):
from pyramid.httpexceptions import HTTPForbidden
from opensipkd.base.models import query_table
res = query_table('routes', ['id'])
row = res.first()
assert row.id == 1
def test_view_fn_query_table2(self):
from pyramid.httpexceptions import HTTPForbidden
from opensipkd.base.models import query_table
res = query_table('routes', ['id', 'nama'], [('id', '=', 2)])
row = res.first()
assert row.id == 2
if __name__ == "__main__":
print("START")
config = testing.setUp()
cfg = settings()
main(config, **cfg['app:main'])
from opensipkd.base.models import query_table
res = query_table('routes', ['id', 'nama', 'kode'],
[('|', ('nama', 'ilike', "a%"),
('kode', 'ilike', 'g%'))])
for row in res.all():
print(row.id, row.nama, row.kode)