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