mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-27 07:48:26 +00:00
test_schema.py fixed
This commit is contained in:
parent
6ebeac9f04
commit
6f62561793
@ -26,6 +26,9 @@ class TarantoolDB:
|
|||||||
if reset_database:
|
if reset_database:
|
||||||
self.drop_database()
|
self.drop_database()
|
||||||
self.init_database()
|
self.init_database()
|
||||||
|
self.SPACE_NAMES = ["abci_chains", "assets", "blocks", "blocks_tx",
|
||||||
|
"elections", "meta_data", "pre_commits", "validators",
|
||||||
|
"transactions", "inputs", "outputs", "keys"]
|
||||||
|
|
||||||
def space(self, space_name: str):
|
def space(self, space_name: str):
|
||||||
return self.db_connect.space(space_name)
|
return self.db_connect.space(space_name)
|
||||||
@ -35,12 +38,12 @@ class TarantoolDB:
|
|||||||
|
|
||||||
def drop_database(self):
|
def drop_database(self):
|
||||||
db_config = Config().get()["database"]
|
db_config = Config().get()["database"]
|
||||||
self.run_command(command=self.drop_path, config=db_config)
|
return self.run_command(command=self.drop_path, config=db_config)
|
||||||
|
|
||||||
def init_database(self):
|
def init_database(self):
|
||||||
db_config = Config().get()["database"]
|
db_config = Config().get()["database"]
|
||||||
|
|
||||||
self.run_command(command=self.init_path, config=db_config)
|
return self.run_command(command=self.init_path, config=db_config)
|
||||||
|
|
||||||
def run_command(self, command: str, config: dict):
|
def run_command(self, command: str, config: dict):
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -51,6 +54,6 @@ class TarantoolDB:
|
|||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
universal_newlines=True,
|
universal_newlines=True,
|
||||||
bufsize=0,
|
bufsize=0,
|
||||||
shell=True)
|
shell=True).stdout.readlines()
|
||||||
# TODO verify if subprocess creation worked properly
|
# TODO verify if subprocess creation worked properly
|
||||||
return True # if ret > 0 else False
|
return True if "nil value" not in ret else False
|
||||||
|
|||||||
@ -6,13 +6,14 @@
|
|||||||
from planetmint.config import Config
|
from planetmint.config import Config
|
||||||
from planetmint.backend import Connection
|
from planetmint.backend import Connection
|
||||||
from planetmint.backend.tarantool.connection import TarantoolDB
|
from planetmint.backend.tarantool.connection import TarantoolDB
|
||||||
|
|
||||||
|
|
||||||
def test_init_database_is_graceful_if_db_exists():
|
def test_init_database_is_graceful_if_db_exists():
|
||||||
|
|
||||||
|
|
||||||
conn = TarantoolDB('localhost', 3303)
|
conn = TarantoolDB('localhost', 3303)
|
||||||
conn.drop_database()
|
conn.drop_database()
|
||||||
conn.init_database()
|
conn.init_database()
|
||||||
|
|
||||||
|
|
||||||
def test_create_tables():
|
def test_create_tables():
|
||||||
from planetmint.backend import schema
|
from planetmint.backend import schema
|
||||||
|
|
||||||
@ -30,6 +31,8 @@ def test_create_tables():
|
|||||||
# 'transactions', 'assets', 'metadata', 'blocks', 'utxos', 'validators', 'elections',
|
# 'transactions', 'assets', 'metadata', 'blocks', 'utxos', 'validators', 'elections',
|
||||||
# 'pre_commit', 'abci_chains',
|
# 'pre_commit', 'abci_chains',
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# indexes = conn.conn[dbname]['assets'].index_information().keys()
|
# indexes = conn.conn[dbname]['assets'].index_information().keys()
|
||||||
# assert set(indexes) == {'_id_', 'asset_id', 'text'}
|
# assert set(indexes) == {'_id_', 'asset_id', 'text'}
|
||||||
@ -59,13 +62,22 @@ def test_create_tables():
|
|||||||
# assert set(indexes.keys()) == {'_id_', 'height'}
|
# assert set(indexes.keys()) == {'_id_', 'height'}
|
||||||
# assert indexes['height']['unique']
|
# assert indexes['height']['unique']
|
||||||
|
|
||||||
|
def _check_spaces_by_list(conn, space_names):
|
||||||
|
_exists = []
|
||||||
|
for name in space_names:
|
||||||
|
try:
|
||||||
|
conn.space(name)
|
||||||
|
_exists.append(name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return _exists
|
||||||
|
|
||||||
def test_drop(dummy_db):
|
|
||||||
from planetmint import backend
|
|
||||||
from planetmint.backend import schema
|
|
||||||
|
|
||||||
|
def test_drop(): # remove dummy_db as argument
|
||||||
conn = TarantoolDB('localhost', 3303)
|
conn = TarantoolDB('localhost', 3303)
|
||||||
assert assets in conn.spaces('assets')
|
|
||||||
conn.drop_database()
|
conn.drop_database()
|
||||||
assert assets not in conn.conn.list_database_names()
|
actual_spaces = _check_spaces_by_list(conn=conn, space_names=conn.SPACE_NAMES)
|
||||||
|
assert [] == actual_spaces
|
||||||
|
# conn.init_database()
|
||||||
|
# actual_spaces1 = _check_spaces_by_list(conn=conn, space_names=conn.SPACE_NAMES)
|
||||||
|
# assert conn.SPACE_NAMES == actual_spaces1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user