dana-medical-site/deploy/test_price_import_defaults.py

20 lines
949 B
Python

"""Inspect legacy generators without importing them (they have file-writing side effects)."""
import ast
from pathlib import Path
import unittest
class ImportDefaultsTest(unittest.TestCase):
def test_imported_items_are_draft(self):
root = Path(__file__).resolve().parents[1] / 'migrations' / 'import'
for name in ('build_price_map.py', 'rebuild_price_from_1c_only.py'):
with self.subTest(script=name):
tree = ast.parse((root / name).read_text(encoding='utf-8'))
inserts = [node.value for node in ast.walk(tree) if isinstance(node, ast.Constant) and isinstance(node.value,str) and 'INSERT INTO price_items' in node.value]
self.assertTrue(inserts)
for sql in inserts:
self.assertIn('SELECT id,%s,%s,%s,false',sql)
self.assertNotIn('%s,true FROM price_sections',sql)
if __name__ == '__main__':
unittest.main()