Skip to content

Commit

Permalink
start unit tests for db
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Sep 15, 2017
1 parent 95a709e commit e375537
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ venv/
.tox/
coverage/
.coverage
.cache
6 changes: 4 additions & 2 deletions xcat/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import xcat.cli as cli
from xcat.db import DB
from xcat.protocol import Protocol
from xcat.tests.utils import mktrade
import xcat.tests.utils as testutils
from xcat.trades import Trade # , Contract


class SimpleTestCase(unittest.TestCase):
def setUp(self):
self.trade = mktrade()
self.trade = testutils.mktrade()

def test_exporttrade(self):
self.__class__.hexstr = cli.exporttrade('test')
Expand All @@ -20,6 +20,7 @@ def test_importtrade(self):


class CliTest(SimpleTestCase):

def test_findtrade(self):
# trade = cli.findtrade('test')
pass
Expand All @@ -33,6 +34,7 @@ def test_fundsell(self):
protocol = Protocol()

trade = db.get('new')

status = cli.seller_check_status(trade)
print("Trade status: {0}\n".format(status))
self.assertEqual(status, 'init')
Expand Down
9 changes: 7 additions & 2 deletions xcat/tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

class TestCLI(unittest.TestCase):

def test_save_state(self):
pass
@mock.patch('xcat.cli.DB')
@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):
pass
Expand Down
53 changes: 53 additions & 0 deletions xcat/tests/unit/test_db.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e375537

Please sign in to comment.