0001-feeder-add-option-post-sync-commands-56164.patch
tests/test_feeder.py | ||
---|---|---|
1 | 1 |
import logging |
2 |
from unittest import mock |
|
2 | 3 | |
3 | 4 |
import pytest |
4 | 5 | |
... | ... | |
20 | 21 |
with pytest.raises(Exception): |
21 | 22 |
feeder.ex('COIN') |
22 | 23 |
assert 'Failed to execute' in caplog.text |
24 | ||
25 | ||
26 |
def test_post_sync_commands(mock_cursor_execute, wcs, postgres_db, olap_cmd): |
|
27 |
with olap_cmd.config() as config: |
|
28 |
config.set( |
|
29 |
'wcs-olap', |
|
30 |
'post-sync-commands', |
|
31 |
"NOTIFY coucou, '{schema}';\nSELECT * FROM information_schema.tables") |
|
32 | ||
33 |
queries = [] |
|
34 | ||
35 |
def side_effect(query, *args, **kwargs): |
|
36 |
queries.append(query) |
|
37 |
return mock.DEFAULT |
|
38 | ||
39 |
with mock_cursor_execute(side_effect=side_effect): |
|
40 |
assert olap_cmd() == 0 |
|
41 | ||
42 |
# verify post-sync-commands are in the last executed queries |
|
43 |
assert queries[-1] == "NOTIFY coucou, 'olap';\nSELECT * FROM information_schema.tables" |
wcs_olap/feeder.py | ||
---|---|---|
632 | 632 |
model_path = os.path.join(self.config['cubes_model_dirs'], '%s.model' % self.schema) |
633 | 633 |
with open(model_path, 'w') as f: |
634 | 634 |
json.dump(self.model, f, indent=2, sort_keys=True) |
635 |
post_sync_commands = self.config.get('post-sync-commands') |
|
636 |
if post_sync_commands: |
|
637 |
self.ex(post_sync_commands) |
|
635 | 638 |
finally: |
636 | 639 |
# prevent connection from remaining open |
637 | 640 |
self.cur.close() |
638 |
- |