start unit tests for db
This commit is contained in:
parent
95a709e819
commit
e375537af4
|
@ -12,3 +12,4 @@ venv/
|
||||||
.tox/
|
.tox/
|
||||||
coverage/
|
coverage/
|
||||||
.coverage
|
.coverage
|
||||||
|
.cache
|
||||||
|
|
|
@ -2,13 +2,13 @@ import unittest
|
||||||
import xcat.cli as cli
|
import xcat.cli as cli
|
||||||
from xcat.db import DB
|
from xcat.db import DB
|
||||||
from xcat.protocol import Protocol
|
from xcat.protocol import Protocol
|
||||||
from xcat.tests.utils import mktrade
|
import xcat.tests.utils as testutils
|
||||||
from xcat.trades import Trade # , Contract
|
from xcat.trades import Trade # , Contract
|
||||||
|
|
||||||
|
|
||||||
class SimpleTestCase(unittest.TestCase):
|
class SimpleTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.trade = mktrade()
|
self.trade = testutils.mktrade()
|
||||||
|
|
||||||
def test_exporttrade(self):
|
def test_exporttrade(self):
|
||||||
self.__class__.hexstr = cli.exporttrade('test')
|
self.__class__.hexstr = cli.exporttrade('test')
|
||||||
|
@ -20,6 +20,7 @@ class SimpleTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
class CliTest(SimpleTestCase):
|
class CliTest(SimpleTestCase):
|
||||||
|
|
||||||
def test_findtrade(self):
|
def test_findtrade(self):
|
||||||
# trade = cli.findtrade('test')
|
# trade = cli.findtrade('test')
|
||||||
pass
|
pass
|
||||||
|
@ -33,6 +34,7 @@ class CliTest(SimpleTestCase):
|
||||||
protocol = Protocol()
|
protocol = Protocol()
|
||||||
|
|
||||||
trade = db.get('new')
|
trade = db.get('new')
|
||||||
|
|
||||||
status = cli.seller_check_status(trade)
|
status = cli.seller_check_status(trade)
|
||||||
print("Trade status: {0}\n".format(status))
|
print("Trade status: {0}\n".format(status))
|
||||||
self.assertEqual(status, 'init')
|
self.assertEqual(status, 'init')
|
||||||
|
|
|
@ -7,8 +7,13 @@ import xcat.cli as cli
|
||||||
|
|
||||||
class TestCLI(unittest.TestCase):
|
class TestCLI(unittest.TestCase):
|
||||||
|
|
||||||
def test_save_state(self):
|
@mock.patch('xcat.cli.DB')
|
||||||
pass
|
@mock.patch('xcat.cli.utils')
|
||||||
|
def test_save_state(self, mock_utils, mock_db):
|
||||||
|
cli.save_state('fake_trade', 'fake_id')
|
||||||
|
|
||||||
|
mock_utils.save.assert_called_with('fake_trade')
|
||||||
|
mock_db.return_value.create.assert_called_with('fake_trade', 'fake_id')
|
||||||
|
|
||||||
def test_checkSellStatus(self):
|
def test_checkSellStatus(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
import unittest
|
||||||
|
import unittest.mock as mock
|
||||||
|
import xcat.db as db
|
||||||
|
import xcat.tests.utils as utils
|
||||||
|
|
||||||
|
|
||||||
|
class TestDB(unittest.TestCase):
|
||||||
|
|
||||||
|
@mock.patch('xcat.db.plyvel')
|
||||||
|
def setUp(self, mock_plyvel):
|
||||||
|
self.db = db.DB()
|
||||||
|
|
||||||
|
def test_init(self):
|
||||||
|
self.assertIsInstance(self.db.db, mock.Mock)
|
||||||
|
self.assertIsInstance(self.db.preimageDB, mock.Mock)
|
||||||
|
|
||||||
|
@mock.patch('xcat.db.json')
|
||||||
|
def test_create_with_dict(self, mock_json):
|
||||||
|
test_id = 'test trade id'
|
||||||
|
trade_string = 'trade string'
|
||||||
|
mock_json.dumps.return_value = trade_string
|
||||||
|
test_trade = utils.test_trade
|
||||||
|
|
||||||
|
self.db.create(test_trade, test_id)
|
||||||
|
|
||||||
|
mock_json.dumps.assert_called_with(test_trade)
|
||||||
|
self.db.db.put.assert_called_with(
|
||||||
|
str.encode(test_id),
|
||||||
|
str.encode(trade_string))
|
||||||
|
|
||||||
|
def test_create_with_trade(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_createByFundtx(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_get(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_instantiate(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_save_secret(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_get_secret(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_dump(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_print_entries(self):
|
||||||
|
pass
|
Loading…
Reference in New Issue