mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
added conftest.py
This commit is contained in:
parent
5987299748
commit
1e437983a4
@ -14,6 +14,8 @@ BACKENDS = { # This is path to MongoDBClass
|
||||
}
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# backend = get_planetmint_config_value("backend")
|
||||
# if not backend:
|
||||
# backend = 'tarantool_db'
|
||||
@ -22,8 +24,9 @@ logger = logging.getLogger(__name__)
|
||||
# current_backend = getattr(import_module(modulepath), class_name)
|
||||
|
||||
|
||||
def Connection(host: str = None, port: int = None, login: str = None, password: str = None, backend: str = None, **kwargs):
|
||||
|
||||
def Connection(host: str = None, port: int = None, login: str = None, password: str = None, backend: str = None,
|
||||
**kwargs):
|
||||
# TODO To add parser for **kwargs, when mongodb is used
|
||||
backend = backend or get_planetmint_config_value("backend") if not kwargs.get("backend") else kwargs["backend"]
|
||||
host = host or get_planetmint_config_value("host") if kwargs.get("host") is None else kwargs["host"]
|
||||
port = port or get_planetmint_config_value("port") if not kwargs.get("port") is None else kwargs["port"]
|
||||
@ -36,3 +39,4 @@ def Connection(host: str = None, port: int = None, login: str = None, password:
|
||||
return Class(host=host, port=port, user=login, password=password)
|
||||
elif backend == "localmongodb":
|
||||
return ""
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ def module_dispatch_registrar(module):
|
||||
|
||||
|
||||
def get_planetmint_config_value(key, default_value=None):
|
||||
print(planetmint.config["database"]) # backend ,po rt
|
||||
return planetmint.config['database'].get(key, default_value)
|
||||
|
||||
|
||||
|
||||
8
tests/backend/tarantool/conftest.py
Normal file
8
tests/backend/tarantool/conftest.py
Normal file
@ -0,0 +1,8 @@
|
||||
import pytest
|
||||
from planetmint.backend import connection
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db_conn():
|
||||
conn = connection.Connection(backend="tarantool_db")
|
||||
return conn
|
||||
@ -10,15 +10,16 @@ import pytest
|
||||
# import pymongo
|
||||
|
||||
# # from planetmint.backend.connection import Connection, query
|
||||
from planetmint.backend.connection import Connection
|
||||
conn = Connection(backend="tarantool_db").get_connection()
|
||||
# from planetmint.backend.connection import Connection
|
||||
# conn = Connection(backend="tarantool_db").get_connection()
|
||||
|
||||
pytestmark = pytest.mark.bdb
|
||||
|
||||
|
||||
def test_get_txids_filtered(signed_create_tx, signed_transfer_tx):
|
||||
def test_get_txids_filtered(signed_create_tx, signed_transfer_tx, db_conn):
|
||||
from planetmint.backend.tarantool import query
|
||||
from planetmint.models import Transaction
|
||||
conn = db_conn.get_connection()
|
||||
# create and insert two blocks, one for the create and one for the
|
||||
# transfer transaction
|
||||
create_tx_dict = signed_create_tx.to_dict()
|
||||
@ -42,10 +43,11 @@ def test_get_txids_filtered(signed_create_tx, signed_transfer_tx):
|
||||
assert txids == {signed_transfer_tx.id}
|
||||
|
||||
|
||||
def test_write_assets():
|
||||
def test_write_assets(db_conn):
|
||||
# from planetmint.backend.connection import Connection
|
||||
from planetmint.backend.tarantool import query
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
assets = [
|
||||
{'id': "1", 'data': '1'},
|
||||
{'id': "2", 'data': '2'},
|
||||
@ -65,11 +67,11 @@ def test_write_assets():
|
||||
assert list(documents) == assets[:-1]
|
||||
|
||||
|
||||
def test_get_assets():
|
||||
def test_get_assets(db_conn):
|
||||
# from planetmint.backend.connection import Connection
|
||||
from planetmint.backend.tarantool import query
|
||||
# conn = Connection().get_connection()
|
||||
|
||||
conn = db_conn.get_connection()
|
||||
assets = [
|
||||
{'id': "1", 'data': '1'},
|
||||
{'id': "2", 'data': '2'},
|
||||
@ -166,11 +168,11 @@ def test_text_search(table):
|
||||
# ]
|
||||
|
||||
|
||||
def test_write_metadata():
|
||||
def test_write_metadata(db_conn):
|
||||
# from planetmint.backend.connection import Connection
|
||||
from planetmint.backend.tarantool import query
|
||||
# conn = Connection().get_connection()
|
||||
|
||||
conn = db_conn.get_connection()
|
||||
metadata = [
|
||||
{'id': "1", 'data': '1'},
|
||||
{'id': "2", 'data': '2'},
|
||||
@ -193,10 +195,9 @@ def test_write_metadata():
|
||||
assert list(metadatas) == metadata
|
||||
|
||||
|
||||
def test_get_metadata():
|
||||
# from planetmint.backend.connection import Connection
|
||||
def test_get_metadata(db_conn):
|
||||
from planetmint.backend.tarantool import query
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
|
||||
metadata = [
|
||||
{'id': "dd86682db39e4b424df0eec1413cfad65488fd48712097c5d865ca8e8e059b64", 'metadata': None},
|
||||
@ -210,10 +211,9 @@ def test_get_metadata():
|
||||
assert query.get_metadata(connection=conn, transaction_ids=[meta["id"]])
|
||||
|
||||
|
||||
def test_get_owned_ids(signed_create_tx, user_pk):
|
||||
# from planetmint.backend.connection import Connection
|
||||
def test_get_owned_ids(signed_create_tx, user_pk, db_conn):
|
||||
from planetmint.backend.tarantool import query
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
|
||||
# insert a transaction
|
||||
query.store_transactions(connection=conn, signed_transactions=[signed_create_tx.to_dict()])
|
||||
@ -223,11 +223,11 @@ def test_get_owned_ids(signed_create_tx, user_pk):
|
||||
assert founded[0] == tx_dict
|
||||
|
||||
|
||||
def test_get_spending_transactions(user_pk, user_sk):
|
||||
def test_get_spending_transactions(user_pk, user_sk, db_conn):
|
||||
from planetmint.models import Transaction
|
||||
# from planetmint.backend.connection import Connection
|
||||
from planetmint.backend.tarantool import query
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
|
||||
out = [([user_pk], 1)]
|
||||
tx1 = Transaction.create([user_pk], out * 3)
|
||||
@ -246,13 +246,11 @@ def test_get_spending_transactions(user_pk, user_sk):
|
||||
assert txns == [tx2.to_dict(), tx4.to_dict()]
|
||||
|
||||
|
||||
def test_get_spending_transactions_multiple_inputs():
|
||||
def test_get_spending_transactions_multiple_inputs(db_conn):
|
||||
from planetmint.models import Transaction
|
||||
from planetmint.common.crypto import generate_key_pair
|
||||
# from planetmint.backend.connection import Connection
|
||||
from planetmint.backend.tarantool import query
|
||||
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
|
||||
(alice_sk, alice_pk) = generate_key_pair()
|
||||
(bob_sk, bob_pk) = generate_key_pair()
|
||||
@ -292,12 +290,11 @@ def test_get_spending_transactions_multiple_inputs():
|
||||
assert [tx['id'] for tx in txns] == match
|
||||
|
||||
|
||||
def test_store_block():
|
||||
def test_store_block(db_conn):
|
||||
from planetmint.lib import Block
|
||||
# from planetmint.backend.connection import Connection
|
||||
from planetmint.backend.tarantool import query
|
||||
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
|
||||
block = Block(app_hash='random_utxo',
|
||||
height=3,
|
||||
@ -308,12 +305,11 @@ def test_store_block():
|
||||
assert len(blocks.data) == 1
|
||||
|
||||
|
||||
def test_get_block():
|
||||
def test_get_block(db_conn):
|
||||
from planetmint.lib import Block
|
||||
# from planetmint.backend.connection import Connection
|
||||
from planetmint.backend.tarantool import query
|
||||
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
|
||||
block = Block(app_hash='random_utxo',
|
||||
height=3,
|
||||
@ -423,11 +419,10 @@ def test_get_block():
|
||||
# assert retrieved_utxoset == unspent_outputs
|
||||
|
||||
|
||||
def test_store_pre_commit_state(db_context):
|
||||
# from planetmint.backend.connection import Connection
|
||||
def test_store_pre_commit_state(db_conn):
|
||||
from planetmint.backend.tarantool import query
|
||||
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
|
||||
state = dict(height=3, transactions=[])
|
||||
|
||||
@ -439,11 +434,11 @@ def test_store_pre_commit_state(db_context):
|
||||
# projection={'_id': False})
|
||||
|
||||
|
||||
def test_get_pre_commit_state(db_context):
|
||||
# from planetmint.backend.connection import Connection
|
||||
def test_get_pre_commit_state(db_conn):
|
||||
from planetmint.backend.tarantool import query
|
||||
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
|
||||
space = conn.space("pre_commits")
|
||||
all_pre = space.select([])
|
||||
for pre in all_pre.data:
|
||||
@ -456,11 +451,11 @@ def test_get_pre_commit_state(db_context):
|
||||
assert resp == state
|
||||
|
||||
|
||||
def test_validator_update():
|
||||
# from planetmint.backend.connection import Connection
|
||||
def test_validator_update(db_conn):
|
||||
|
||||
from planetmint.backend.tarantool import query
|
||||
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
|
||||
def gen_validator_update(height):
|
||||
return {'validators': [], 'height': height, 'election_id': f'election_id_at_height_{height}'}
|
||||
@ -518,11 +513,10 @@ def test_validator_update():
|
||||
{'height': 10, 'chain_id': 'another-id', 'is_synced': True},
|
||||
),
|
||||
])
|
||||
def test_store_abci_chain(description, stores, expected):
|
||||
# from planetmint.backend.connection import Connection
|
||||
def test_store_abci_chain(description, stores, expected, db_conn):
|
||||
from planetmint.backend.tarantool import query
|
||||
|
||||
# conn = Connection().get_connection()
|
||||
conn = db_conn.get_connection()
|
||||
|
||||
for store in stores:
|
||||
query.store_abci_chain(conn, **store)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user