chainsyncer/tests/base.py

55 lines
1.4 KiB
Python
Raw Normal View History

2021-04-04 15:03:58 +02:00
# standard imports
import logging
2021-02-17 12:44:35 +01:00
import unittest
import tempfile
import os
#import pysqlite
2021-04-04 15:03:58 +02:00
# external imports
from chainlib.chain import ChainSpec
# local imports
2021-02-17 12:44:35 +01:00
from chainsyncer.db import dsn_from_config
from chainsyncer.db.models.base import SessionBase
script_dir = os.path.realpath(os.path.dirname(__file__))
2021-04-04 15:03:58 +02:00
logging.basicConfig(level=logging.DEBUG)
2021-02-17 12:44:35 +01:00
class TestBase(unittest.TestCase):
def setUp(self):
db_dir = tempfile.mkdtemp()
self.db_path = os.path.join(db_dir, 'test.sqlite')
config = {
'DATABASE_ENGINE': 'sqlite',
'DATABASE_DRIVER': 'pysqlite',
'DATABASE_NAME': self.db_path,
}
dsn = dsn_from_config(config)
SessionBase.poolable = False
SessionBase.transactional = False
SessionBase.procedural = False
2021-04-04 15:03:58 +02:00
SessionBase.connect(dsn, debug=False)
2021-02-17 12:44:35 +01:00
f = open(os.path.join(script_dir, '..', 'sql', 'sqlite', '1.sql'), 'r')
sql = f.read()
f.close()
conn = SessionBase.engine.connect()
conn.execute(sql)
f = open(os.path.join(script_dir, '..', 'sql', 'sqlite', '2.sql'), 'r')
sql = f.read()
f.close()
conn = SessionBase.engine.connect()
conn.execute(sql)
2021-04-04 15:03:58 +02:00
self.chain_spec = ChainSpec('evm', 'foo', 42, 'bar')
2021-02-17 12:44:35 +01:00
def tearDown(self):
SessionBase.disconnect()
os.unlink(self.db_path)