2022-03-12 14:48:40 +01:00
|
|
|
# standard imports
|
|
|
|
import tempfile
|
|
|
|
import unittest
|
2022-03-12 15:12:02 +01:00
|
|
|
import logging
|
2022-03-12 14:48:40 +01:00
|
|
|
|
|
|
|
# external imports
|
|
|
|
from shep.store.file import SimpleFileStoreFactory
|
|
|
|
from chainlib.chain import ChainSpec
|
|
|
|
|
|
|
|
# local imports
|
|
|
|
from chainqueue import (
|
|
|
|
Store,
|
|
|
|
Status,
|
|
|
|
)
|
|
|
|
|
|
|
|
# test imports
|
|
|
|
from tests.common import (
|
|
|
|
MockCounter,
|
2022-03-12 15:12:02 +01:00
|
|
|
MockTokenCache,
|
|
|
|
MockCacheTokenTx,
|
2022-03-12 14:48:40 +01:00
|
|
|
)
|
2022-03-12 15:12:02 +01:00
|
|
|
from tests.base_shep import TestShepBase
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
logg = logging.getLogger()
|
2022-03-12 14:48:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2022-03-12 15:12:02 +01:00
|
|
|
class TestIntegrateBase(TestShepBase):
|
2022-03-12 14:48:40 +01:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.path = tempfile.mkdtemp()
|
|
|
|
factory = SimpleFileStoreFactory(self.path).add
|
|
|
|
self.state = Status(factory)
|
|
|
|
content_store = MockContentStore()
|
|
|
|
counter = MockCounter()
|
|
|
|
chain_spec = ChainSpec('foo', 'bar', 42, 'baz')
|
|
|
|
self.cache = MockTokenCache()
|
|
|
|
self.store = Store(chain_spec, self.state, content_store, counter, cache=self.cache)
|
|
|
|
|
|
|
|
|
2022-03-12 15:12:02 +01:00
|
|
|
def test_integration_valid(self):
|
|
|
|
self.store.put(b'foo'.hex(), b'bar'.hex(), cache_adapter=MockCacheTokenTx)
|
2022-03-12 14:48:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|