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,66 +6,78 @@
|
|||||||
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
|
||||||
|
|
||||||
conn = TarantoolDB('localhost', 3303)
|
conn = TarantoolDB('localhost', 3303)
|
||||||
#conn = Connection()
|
# conn = Connection()
|
||||||
#dbname = Config().get()['database']['name']
|
# dbname = Config().get()['database']['name']
|
||||||
|
|
||||||
# The db is set up by the fixtures so we need to remove it
|
# The db is set up by the fixtures so we need to remove it
|
||||||
conn.drop_database()
|
conn.drop_database()
|
||||||
conn.init_database()
|
conn.init_database()
|
||||||
|
|
||||||
# TOTO verify spaces
|
# TOTO verify spaces
|
||||||
#collection_names = conn.conn[dbname].list_collection_names()
|
# collection_names = conn.conn[dbname].list_collection_names()
|
||||||
#assert set(collection_names) == {
|
# assert set(collection_names) == {
|
||||||
# '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()
|
|
||||||
#assert set(indexes) == {'_id_', 'asset_id', 'text'}
|
|
||||||
#
|
|
||||||
#index_info = conn.conn[dbname]['transactions'].index_information()
|
|
||||||
#indexes = index_info.keys()
|
|
||||||
#assert set(indexes) == {
|
|
||||||
# '_id_', 'transaction_id', 'asset_id', 'outputs', 'inputs'}
|
|
||||||
#assert index_info['transaction_id']['unique']
|
|
||||||
#
|
|
||||||
#index_info = conn.conn[dbname]['blocks'].index_information()
|
|
||||||
#indexes = index_info.keys()
|
|
||||||
#assert set(indexes) == {'_id_', 'height'}
|
|
||||||
#assert index_info['height']['unique']
|
|
||||||
#
|
|
||||||
#index_info = conn.conn[dbname]['utxos'].index_information()
|
|
||||||
#assert set(index_info.keys()) == {'_id_', 'utxo'}
|
|
||||||
#assert index_info['utxo']['unique']
|
|
||||||
#assert index_info['utxo']['key'] == [('transaction_id', 1),
|
|
||||||
# ('output_index', 1)]
|
|
||||||
#
|
|
||||||
#indexes = conn.conn[dbname]['elections'].index_information()
|
|
||||||
#assert set(indexes.keys()) == {'_id_', 'election_id_height'}
|
|
||||||
#assert indexes['election_id_height']['unique']
|
|
||||||
#
|
|
||||||
#indexes = conn.conn[dbname]['pre_commit'].index_information()
|
|
||||||
#assert set(indexes.keys()) == {'_id_', 'height'}
|
|
||||||
#assert indexes['height']['unique']
|
|
||||||
|
|
||||||
|
|
||||||
def test_drop(dummy_db):
|
#
|
||||||
from planetmint import backend
|
# indexes = conn.conn[dbname]['assets'].index_information().keys()
|
||||||
from planetmint.backend import schema
|
# assert set(indexes) == {'_id_', 'asset_id', 'text'}
|
||||||
|
#
|
||||||
|
# index_info = conn.conn[dbname]['transactions'].index_information()
|
||||||
|
# indexes = index_info.keys()
|
||||||
|
# assert set(indexes) == {
|
||||||
|
# '_id_', 'transaction_id', 'asset_id', 'outputs', 'inputs'}
|
||||||
|
# assert index_info['transaction_id']['unique']
|
||||||
|
#
|
||||||
|
# index_info = conn.conn[dbname]['blocks'].index_information()
|
||||||
|
# indexes = index_info.keys()
|
||||||
|
# assert set(indexes) == {'_id_', 'height'}
|
||||||
|
# assert index_info['height']['unique']
|
||||||
|
#
|
||||||
|
# index_info = conn.conn[dbname]['utxos'].index_information()
|
||||||
|
# assert set(index_info.keys()) == {'_id_', 'utxo'}
|
||||||
|
# assert index_info['utxo']['unique']
|
||||||
|
# assert index_info['utxo']['key'] == [('transaction_id', 1),
|
||||||
|
# ('output_index', 1)]
|
||||||
|
#
|
||||||
|
# indexes = conn.conn[dbname]['elections'].index_information()
|
||||||
|
# assert set(indexes.keys()) == {'_id_', 'election_id_height'}
|
||||||
|
# assert indexes['election_id_height']['unique']
|
||||||
|
#
|
||||||
|
# indexes = conn.conn[dbname]['pre_commit'].index_information()
|
||||||
|
# assert set(indexes.keys()) == {'_id_', 'height'}
|
||||||
|
# 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(): # 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