Add store test, move store to subdir module
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# standard imports
|
||||
import tempfile
|
||||
import unittest
|
||||
import shutil
|
||||
|
||||
# external imports
|
||||
from shep.store.file import SimpleFileStoreFactory
|
||||
@@ -13,22 +14,10 @@ from chainqueue import (
|
||||
)
|
||||
|
||||
# test imports
|
||||
from tests.common import MockCounter
|
||||
|
||||
|
||||
|
||||
class MockContentStore:
|
||||
|
||||
def __init__(self):
|
||||
self.store = {}
|
||||
|
||||
|
||||
def put(self, k, v):
|
||||
self.store[k] = v
|
||||
|
||||
|
||||
def get(self, k):
|
||||
return self.store.get(k)
|
||||
from tests.common import (
|
||||
MockCounter,
|
||||
MockContentStore,
|
||||
)
|
||||
|
||||
|
||||
class TestShepBase(unittest.TestCase):
|
||||
@@ -41,3 +30,7 @@ class TestShepBase(unittest.TestCase):
|
||||
counter = MockCounter()
|
||||
chain_spec = ChainSpec('foo', 'bar', 42, 'baz')
|
||||
self.store = Store(chain_spec, self.state, content_store, counter)
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.path)
|
||||
|
||||
@@ -79,7 +79,6 @@ class MockCacheTokenTx(CacheTokenTx):
|
||||
z = h.digest()
|
||||
tx_hash = z.hex()
|
||||
|
||||
#tx = CacheTokenTx(normalizer=self.normalizer)
|
||||
self.init(tx_hash, nonce, sender, recipient, value)
|
||||
self.set('src_token', token)
|
||||
self.set('dst_token', token)
|
||||
@@ -90,4 +89,15 @@ class MockCacheTokenTx(CacheTokenTx):
|
||||
return self
|
||||
|
||||
|
||||
class MockContentStore:
|
||||
|
||||
def __init__(self):
|
||||
self.store = {}
|
||||
|
||||
|
||||
def put(self, k, v):
|
||||
self.store[k] = v
|
||||
|
||||
|
||||
def get(self, k):
|
||||
return self.store.get(k)
|
||||
|
||||
@@ -18,6 +18,7 @@ from tests.common import (
|
||||
MockCounter,
|
||||
MockTokenCache,
|
||||
MockCacheTokenTx,
|
||||
MockContentStore,
|
||||
)
|
||||
from tests.base_shep import TestShepBase
|
||||
|
||||
@@ -25,20 +26,6 @@ logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class MockContentStore:
|
||||
|
||||
def __init__(self):
|
||||
self.store = {}
|
||||
|
||||
|
||||
def put(self, k, v):
|
||||
self.store[k] = v
|
||||
|
||||
|
||||
def get(self, k):
|
||||
return self.store.get(k)
|
||||
|
||||
|
||||
class TestIntegrateBase(TestShepBase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
52
tests/test_store.py
Normal file
52
tests/test_store.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# standard imports
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
import logging
|
||||
import shutil
|
||||
|
||||
# external imports
|
||||
|
||||
# local imports
|
||||
from chainqueue.store.fs import (
|
||||
IndexStore,
|
||||
CounterStore,
|
||||
)
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
class TestStoreImplementations(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.path = tempfile.mkdtemp()
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.path)
|
||||
|
||||
|
||||
def test_basic_index(self):
|
||||
store = IndexStore(self.path)
|
||||
hx = os.urandom(32).hex()
|
||||
data = 'foo_bar_baz'
|
||||
store.put(hx, data)
|
||||
r = store.get(hx)
|
||||
self.assertEqual(data, r)
|
||||
|
||||
|
||||
def test_basic_counter(self):
|
||||
store = CounterStore(self.path)
|
||||
v = store.next()
|
||||
self.assertEqual(v, 0)
|
||||
v = store.next()
|
||||
self.assertEqual(v, 1)
|
||||
|
||||
store = CounterStore(self.path)
|
||||
v = store.next()
|
||||
self.assertEqual(v, 2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user