diff --git a/rattail/db/sync/__init__.py b/rattail/db/sync/__init__.py index ed78bf69615bd0e0ad92c7956f53ac25924cf489..ca4cd434073d4fb04591fe98ab8c81b5d6b6d9ca 100644 --- a/rattail/db/sync/__init__.py +++ b/rattail/db/sync/__init__.py @@ -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 diff --git a/rattail/db/sync/linux.py b/rattail/db/sync/linux.py index 307aeb1bbbe3c3743d2f926726c98add250247d7..7510bb891cc0936bbd3d198c5f90512f12e1d527 100644 --- a/rattail/db/sync/linux.py +++ b/rattail/db/sync/linux.py @@ -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) diff --git a/tests/db/sync/test_init.py b/tests/db/sync/test_init.py index 9c35143788ca53dc572e07eda81c54467bbfd8b6..7812689862a50eaddd3bd91e91a712656f5cfa44 100644 --- a/tests/db/sync/test_init.py +++ b/tests/db/sync/test_init.py @@ -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): - - # 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 - 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'}) + def test_get_sync_engines(self): + config = Mock() + config.get.return_value = None + self.assertIsNone(sync.get_sync_engines(config)) + + with patch('rattail.db.sync.get_engines') as get_engines: + get_engines.return_value = { + 'one': 'first', + 'two': 'second', + 'three': 'third', + } + 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): diff --git a/tests/db/sync/test_linux.py b/tests/db/sync/test_linux.py index 53350746b02960ad75b5b8102e28b44f7845063d..448f8524d9e6c269ae50a7b0932e0d873bb8f1d4 100644 --- a/tests/db/sync/test_linux.py +++ b/tests/db/sync/test_linux.py @@ -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)