diff --git a/tests/test_feeder.py b/tests/test_feeder.py index 32c16e4..47265f9 100644 --- a/tests/test_feeder.py +++ b/tests/test_feeder.py @@ -1,4 +1,5 @@ import logging +from unittest import mock import pytest @@ -20,3 +21,23 @@ def test_sql_error_logging(caplog): with pytest.raises(Exception): feeder.ex('COIN') assert 'Failed to execute' in caplog.text + + +def test_post_sync_commands(mock_cursor_execute, wcs, postgres_db, olap_cmd): + with olap_cmd.config() as config: + config.set( + 'wcs-olap', + 'post-sync-commands', + "NOTIFY coucou, '{schema}';\nSELECT * FROM information_schema.tables") + + queries = [] + + def side_effect(query, *args, **kwargs): + queries.append(query) + return mock.DEFAULT + + with mock_cursor_execute(side_effect=side_effect): + assert olap_cmd() == 0 + + # verify post-sync-commands are in the last executed queries + assert queries[-1] == "NOTIFY coucou, 'olap';\nSELECT * FROM information_schema.tables" diff --git a/wcs_olap/feeder.py b/wcs_olap/feeder.py index bd1dee4..85580f5 100644 --- a/wcs_olap/feeder.py +++ b/wcs_olap/feeder.py @@ -632,6 +632,9 @@ class WcsOlapFeeder(object): model_path = os.path.join(self.config['cubes_model_dirs'], '%s.model' % self.schema) with open(model_path, 'w') as f: json.dump(self.model, f, indent=2, sort_keys=True) + post_sync_commands = self.config.get('post-sync-commands') + if post_sync_commands: + self.ex(post_sync_commands) finally: # prevent connection from remaining open self.cur.close()