mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +00:00
Merge branch 'fixed_config' into asset_change
This commit is contained in:
commit
d3cc8c3c5e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
planetmint_environment/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class TarantoolDB:
|
class TarantoolDB:
|
||||||
def __init__(self, host: str = None, port: int = None, user: str = None, password: str = None,
|
def __init__(self, host: str = "localhost", port: int = 3303, user: str = None, password: str = None,
|
||||||
reset_database: bool = False):
|
reset_database: bool = False):
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
@ -24,30 +24,33 @@ class TarantoolDB:
|
|||||||
self.db_connect = tarantool.connect(host=self.host, port=self.port)
|
self.db_connect = tarantool.connect(host=self.host, port=self.port)
|
||||||
self.init_path = Config().get()["database"]["init_config"]["absolute_path"]
|
self.init_path = Config().get()["database"]["init_config"]["absolute_path"]
|
||||||
self.drop_path = Config().get()["database"]["drop_config"]["absolute_path"]
|
self.drop_path = Config().get()["database"]["drop_config"]["absolute_path"]
|
||||||
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",
|
self.SPACE_NAMES = ["abci_chains", "assets", "blocks", "blocks_tx",
|
||||||
"elections", "meta_data", "pre_commits", "validators",
|
"elections", "meta_data", "pre_commits", "validators",
|
||||||
"transactions", "inputs", "outputs", "keys"]
|
"transactions", "inputs", "outputs", "keys"]
|
||||||
|
|
||||||
|
def _reconnect(self):
|
||||||
|
self.db_connect = tarantool.connect(host=self.host, port=self.port)
|
||||||
|
|
||||||
def space(self, space_name: str):
|
def space(self, space_name: str):
|
||||||
try:
|
return self.db_connect.space(space_name)
|
||||||
return self.db_connect.space(space_name)
|
|
||||||
except tarantool.error.SchemaError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_connection(self):
|
def get_connection(self):
|
||||||
return self.db_connect
|
return self.db_connect
|
||||||
|
|
||||||
def drop_database(self):
|
def drop_database(self):
|
||||||
db_config = Config().get()["database"]
|
db_config = Config().get()["database"]
|
||||||
return self.run_command(command=self.drop_path, config=db_config)
|
cmd_resp = self.run_command(command=self.drop_path, config=db_config)
|
||||||
|
self._reconnect()
|
||||||
|
return cmd_resp
|
||||||
|
|
||||||
def init_database(self):
|
def init_database(self):
|
||||||
db_config = Config().get()["database"]
|
db_config = Config().get()["database"]
|
||||||
|
cmd_resp = self.run_command(command=self.init_path, config=db_config)
|
||||||
return self.run_command(command=self.init_path, config=db_config)
|
self._reconnect()
|
||||||
|
return cmd_resp
|
||||||
|
|
||||||
def run_command(self, command: str, config: dict):
|
def run_command(self, command: str, config: dict):
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -57,7 +60,7 @@ class TarantoolDB:
|
|||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
universal_newlines=True,
|
universal_newlines=True,
|
||||||
bufsize=0,
|
bufsize=1,
|
||||||
shell=True).stdout.readlines()
|
shell=True).stdout.readlines()
|
||||||
# TODO verify if subprocess creation worked properly
|
# TODO verify if subprocess creation worked properly
|
||||||
return True if "nil value" not in ret else False
|
return True if "nil value" not in ret else False
|
||||||
|
|||||||
@ -1,47 +1,57 @@
|
|||||||
aiohttp==3.6.2
|
aiohttp==3.7.4
|
||||||
aniso8601==9.0.1
|
aniso8601==9.0.1
|
||||||
asn1crypto==1.4.0
|
|
||||||
async-timeout==3.0.1
|
async-timeout==3.0.1
|
||||||
attrs==21.4.0
|
attrs==21.4.0
|
||||||
base58==1.0.3
|
base58==2.1.0
|
||||||
BigchainDB==2.2.2
|
bigchaindb-abci==1.0.7
|
||||||
bigchaindb-abci==1.0.5
|
capturer==3.0
|
||||||
certifi==2021.10.8
|
certifi==2021.10.8
|
||||||
cffi==1.15.0
|
cffi==1.15.0
|
||||||
chardet==3.0.4
|
chardet==3.0.4
|
||||||
click==8.0.3
|
click==8.1.2
|
||||||
colorlog==4.1.0
|
colorlog==5.0.1
|
||||||
cryptoconditions==0.8.0
|
cryptography==3.4.7
|
||||||
cryptography==2.3.1
|
Flask==2.0.1
|
||||||
Flask==1.1.2
|
Flask-Cors==3.0.10
|
||||||
Flask-Cors==3.0.8
|
Flask-RESTful==0.3.9
|
||||||
Flask-RESTful==0.3.8
|
gevent==21.1.2
|
||||||
gevent==20.6.2
|
greenlet==1.1.2
|
||||||
greenlet==0.4.16
|
gunicorn==20.1.0
|
||||||
gunicorn==20.0.4
|
humanfriendly==10.0
|
||||||
idna==2.10
|
idna==2.10
|
||||||
itsdangerous==2.0.1
|
iniconfig==1.1.1
|
||||||
Jinja2==3.0.3
|
itsdangerous==2.1.2
|
||||||
|
Jinja2==3.1.1
|
||||||
jsonschema==3.2.0
|
jsonschema==3.2.0
|
||||||
logstats==0.3.0
|
logstats==0.3.0
|
||||||
MarkupSafe==2.0.1
|
MarkupSafe==2.1.1
|
||||||
multidict==4.7.6
|
msgpack==1.0.3
|
||||||
|
multidict==6.0.2
|
||||||
packaging==21.3
|
packaging==21.3
|
||||||
protobuf==3.6.1
|
Planetmint==0.9.0
|
||||||
|
planetmint-cryptoconditions==0.9.4
|
||||||
|
pluggy==1.0.0
|
||||||
|
protobuf==3.17.2
|
||||||
|
py==1.11.0
|
||||||
pyasn1==0.4.8
|
pyasn1==0.4.8
|
||||||
pycparser==2.21
|
pycparser==2.21
|
||||||
pymongo==3.7.2
|
pymongo==3.11.4
|
||||||
PyNaCl==1.1.2
|
PyNaCl==1.4.0
|
||||||
pyparsing==3.0.7
|
pyparsing==3.0.8
|
||||||
pyrsistent==0.18.1
|
pyrsistent==0.18.1
|
||||||
python-rapidjson==0.9.1
|
pytest==7.1.1
|
||||||
pytz==2021.3
|
python-rapidjson==1.0
|
||||||
PyYAML==5.3.1
|
pytz==2022.1
|
||||||
requests==2.23.0
|
PyYAML==5.4.1
|
||||||
setproctitle==1.1.10
|
requests==2.25.1
|
||||||
|
setproctitle==1.2.2
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
urllib3==1.25.11
|
tarantool==0.7.1
|
||||||
Werkzeug==2.0.3
|
tomli==2.0.1
|
||||||
|
typing-extensions==4.1.1
|
||||||
|
urllib3==1.26.9
|
||||||
|
Werkzeug==2.1.1
|
||||||
yarl==1.7.2
|
yarl==1.7.2
|
||||||
|
zenroom==2.1.0.dev1649760309
|
||||||
zope.event==4.5.0
|
zope.event==4.5.0
|
||||||
zope.interface==5.5.0.dev0
|
zope.interface==5.5.0.dev0
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from planetmint.backend.connection import Connection
|
from planetmint.backend.connection import Connection
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
@ -22,12 +24,6 @@ from planetmint.backend.connection import Connection
|
|||||||
# conn.drop_database()
|
# conn.drop_database()
|
||||||
# #_drop_db(conn, dbname)
|
# #_drop_db(conn, dbname)
|
||||||
|
|
||||||
#def _drop_db(conn, dbname):
|
|
||||||
# try:
|
|
||||||
# conn.drop_database()
|
|
||||||
# schema.drop_database(conn, dbname)
|
|
||||||
# except DatabaseDoesNotExist:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def db_conn():
|
def db_conn():
|
||||||
|
|||||||
@ -3,17 +3,9 @@
|
|||||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
from planetmint.config import Config
|
|
||||||
from planetmint.backend import Connection
|
|
||||||
from planetmint.backend.tarantool.connection import TarantoolDB
|
from planetmint.backend.tarantool.connection import TarantoolDB
|
||||||
|
|
||||||
|
|
||||||
# This function creates database, we have now only spaces so for now it is commented
|
|
||||||
# def test_init_database_is_graceful_if_db_exists():
|
|
||||||
# conn = TarantoolDB('localhost', 3303)
|
|
||||||
# conn.drop_database()
|
|
||||||
# conn.init_database()
|
|
||||||
|
|
||||||
def _check_spaces_by_list(conn, space_names):
|
def _check_spaces_by_list(conn, space_names):
|
||||||
_exists = []
|
_exists = []
|
||||||
for name in space_names:
|
for name in space_names:
|
||||||
@ -26,16 +18,15 @@ def _check_spaces_by_list(conn, space_names):
|
|||||||
|
|
||||||
|
|
||||||
def test_create_tables():
|
def test_create_tables():
|
||||||
conn = TarantoolDB('localhost', 3303)
|
db_conn = TarantoolDB("localhost", 3303)
|
||||||
# The db is set up by the fixtures so we need to remove it
|
db_conn.drop_database()
|
||||||
# conn.drop_database()
|
db_conn.init_database()
|
||||||
conn.init_database()
|
assert db_conn.SPACE_NAMES == _check_spaces_by_list(conn=db_conn, space_names=db_conn.SPACE_NAMES)
|
||||||
|
|
||||||
assert conn.SPACE_NAMES == _check_spaces_by_list(conn=conn, space_names=conn.SPACE_NAMES)
|
|
||||||
|
|
||||||
|
|
||||||
def test_drop(): # remove dummy_db as argument
|
def test_drop(): # remove dummy_db as argument
|
||||||
conn = TarantoolDB('localhost', 3303)
|
db_conn = TarantoolDB("localhost", 3303)
|
||||||
conn.drop_database()
|
db_conn.drop_database()
|
||||||
actual_spaces = _check_spaces_by_list(conn=conn, space_names=conn.SPACE_NAMES)
|
actual_spaces = _check_spaces_by_list(conn=db_conn, space_names=db_conn.SPACE_NAMES)
|
||||||
assert [] == actual_spaces
|
assert [] == actual_spaces
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user