Changeset - 23ee011f0419
[Not reviewed]
0 4 0
Lance Edgar (lance) - 11 years ago 2014-01-26 16:55:47
lance@edbob.org
Make `get_sync_engines()` require a config object.
4 files changed with 17 insertions and 16 deletions:
0 comments (0 inline, 0 general)
rattail/db/sync/__init__.py
Show inline comments
 
@@ -46,17 +46,20 @@ from .. import get_engines
 
log = logging.getLogger(__name__)
 

	
 

	
 
def get_sync_engines():
 
    keys = edbob.config.get('rattail.db', 'syncs')
 
def get_sync_engines(config):
 
    """
 
    Fetch the database engines to which data should be synchronized.
 
    """
 
    keys = config.get('rattail.db', 'syncs')
 
    if not keys:
 
        return None
 

	
 
    engines = get_engines(edbob.config)
 
    engines = get_engines(config)
 
    sync_engines = {}
 
    for key in keys.split(','):
 
        key = key.strip()
 
        sync_engines[key] = engines[key]
 
    log.debug("get_sync_engines: Found engine keys: %s" % ','.join(sync_engines.keys()))
 
    log.debug("get_sync_engines: found engine keys: {0}".format(','.join(sync_engines.keys())))
 
    return sync_engines
 

	
 

	
rattail/db/sync/linux.py
Show inline comments
 
@@ -36,7 +36,7 @@ from . import get_sync_engines, synchronize_changes
 
class SyncDaemon(Daemon):
 

	
 
    def run(self):
 
        remote_engines = get_sync_engines()
 
        remote_engines = get_sync_engines(edbob.config)
 
        if remote_engines:
 
            local_engine = get_default_engine(edbob.config)
 
            synchronize_changes(local_engine, remote_engines)
tests/db/sync/test_init.py
Show inline comments
 
@@ -333,22 +333,20 @@ class SynchronizerTests(SyncTestCase):
 

	
 
class ModuleTests(TestCase):
 

	
 
    @patch.multiple('rattail.db.sync', edbob=DEFAULT, get_engines=DEFAULT)
 
    def test_get_sync_engines(self, edbob, get_engines):
 
    def test_get_sync_engines(self):
 
        config = Mock()
 
        config.get.return_value = None
 
        self.assertIsNone(sync.get_sync_engines(config))
 

	
 
        # nothing configured
 
        edbob.config.get.return_value = None
 
        self.assertTrue(sync.get_sync_engines() is None)
 

	
 
        # fake config with 2 out of 3 engines synced
 
        with patch('rattail.db.sync.get_engines') as get_engines:
 
            get_engines.return_value = {
 
                'one': 'first',
 
                'two': 'second',
 
                'three': 'third',
 
                }
 
        edbob.config.get.return_value = 'one, two'
 
        engines = sync.get_sync_engines()
 
        self.assertEqual(engines, {'one': 'first', 'two': 'second'})
 
            config.get.return_value = 'one, two'
 
            self.assertEqual(sync.get_sync_engines(config), {'one': 'first', 'two': 'second'})
 
            get_engines.assert_called_once_with(config)
 

	
 
    @patch.multiple('rattail.db.sync', edbob=DEFAULT, Synchronizer=DEFAULT)
 
    def test_synchronize_changes(self, edbob, Synchronizer):
tests/db/sync/test_linux.py
Show inline comments
 
@@ -19,7 +19,7 @@ class SyncDaemonTests(TestCase):
 
        # no remote engines configured
 
        get_sync_engines.return_value = None
 
        daemon.run()
 
        get_sync_engines.assert_called_once_with()
 
        get_sync_engines.assert_called_once_with(edbob.config)
 
        self.assertFalse(get_default_engine.called)
 
        self.assertFalse(synchronize_changes.called)
 

	
0 comments (0 inline, 0 general)