-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
121 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,12 @@ auto-checkout = | |
find-links = http://op:[email protected]/op/ | ||
|
||
[sources] | ||
openprocurement_client = git https://github.com/openprocurement/openprocurement.client.python branch=use_requests | ||
openprocurement_client = git https://github.com/openprocurement/openprocurement.client.python branch=upstream | ||
|
||
[test] | ||
recipe = zc.recipe.egg:scripts | ||
dependent-scripts = true | ||
eggs = | ||
openprocurement.bridge.basic [test] | ||
|
||
redis | ||
lazydb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
from mock import MagicMock, patch | ||
from openprocurement.bridge.basic.storages.redis_plugin import redis_includeme, lazy_includeme | ||
|
||
|
||
class TestDbs(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.config = { | ||
'storage_config': { | ||
'cache_host': '127.0.0.1', | ||
'cache_port': '6379', | ||
'cache_db_name': '0' | ||
} | ||
} | ||
with patch('openprocurement.bridge.basic.storages.redis_plugin.redis') as mocked_redis: | ||
StrictRedis_mock = MagicMock() | ||
StrictRedis_mock.configure_mock(**{'set': None, 'exists': None}) | ||
mocked_redis.StrictRedis.return_value = StrictRedis_mock | ||
|
||
self.db = redis_includeme(self.config) | ||
self.db.db = dict() | ||
|
||
def set_value(key, value): | ||
self.db.db[key] = value | ||
|
||
self.db.set_value = set_value | ||
self.db.has_value = lambda x: x in self.db.db | ||
|
||
@patch('openprocurement.bridge.basic.storages.redis_plugin.redis') | ||
def test_redis_includeme(self, mocked_redis): | ||
config = { | ||
'storage_config': { | ||
'cache_host': '127.0.0.1', | ||
'cache_port': '6379', | ||
'cache_db_name': '0' | ||
} | ||
} | ||
StrictRedis_mock = MagicMock() | ||
StrictRedis_mock.configure_mock(**{'set': None, 'exists': None}) | ||
mocked_redis.StrictRedis.return_value = StrictRedis_mock | ||
|
||
db = redis_includeme(config) | ||
|
||
self.assertEqual(db._backend, 'redis') | ||
self.assertEqual(db._db_name, config['storage_config']['cache_db_name']) | ||
self.assertEqual(db._port, config['storage_config']['cache_port']) | ||
self.assertEqual(db._host, config['storage_config']['cache_host']) | ||
self.assertEqual(db._host, config['storage_config']['cache_host']) | ||
self.assertEqual(db.set_value, None) | ||
self.assertEqual(db.has_value, None) | ||
|
||
@patch('openprocurement.bridge.basic.storages.redis_plugin.Db') | ||
def test_cache_host_in_config(self, mocked_db): | ||
db = lazy_includeme(self.config) | ||
|
||
self.assertEqual(db._backend, 'lazydb') | ||
self.assertEqual(db._db_name, self.config['storage_config']['cache_db_name']) | ||
|
||
def test_get(self): | ||
self.assertEquals(self.db.get('test'), None) | ||
self.db.set_value('test', 'test') | ||
self.assertEquals(self.db.get('test'), 'test') | ||
|
||
def test_put(self): | ||
self.db.put('test_put', 'test_put') | ||
self.assertEquals(self.db.get('test_put'), 'test_put') | ||
|
||
def test_has(self): | ||
self.assertEquals(self.db.has('test_has'), False) | ||
self.db.set_value('test_has', 'test_has') | ||
self.assertEquals(self.db.has('test_has'), True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters