forked from unimatrix/web
48 lines
2.2 KiB
Python
48 lines
2.2 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
spec = importlib.util.spec_from_file_location('board_publisher', Path(__file__).with_name('publish-system-board-repair.py'))
|
|
publisher = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(publisher)
|
|
|
|
|
|
class BoardPublicationGuardTest(unittest.TestCase):
|
|
def test_publisher_uses_the_existing_promoter_state_directory(self):
|
|
promotion_spec = importlib.util.spec_from_file_location('promoter_for_board_publication', Path(__file__).with_name('promote-safe-v3.py'))
|
|
promoter = importlib.util.module_from_spec(promotion_spec)
|
|
promotion_spec.loader.exec_module(promoter)
|
|
self.assertEqual(publisher.PROMOTION_STATE, promoter.STATE)
|
|
|
|
def test_changed_native_helpers_are_refused_without_overwriting_them(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
source, target = root / 'source', root / 'target'
|
|
source.mkdir()
|
|
target.mkdir()
|
|
for name in publisher.FILES:
|
|
(source / name).write_text('reviewed new helper')
|
|
for name in publisher.EXPECTED:
|
|
(target / name).write_text('unexpected native customization')
|
|
with self.assertRaisesRegex(RuntimeError, 'unreviewed changes'):
|
|
publisher.publication_changes(source, target)
|
|
for name in publisher.EXPECTED:
|
|
self.assertEqual((target / name).read_text(), 'unexpected native customization')
|
|
self.assertFalse((target / publisher.FILES[0]).exists())
|
|
|
|
def test_repeated_completed_publication_needs_no_writes(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
source, target = root / 'source', root / 'target'
|
|
source.mkdir()
|
|
target.mkdir()
|
|
for name in publisher.FILES:
|
|
(source / name).write_text('same approved helper')
|
|
(target / name).write_text('same approved helper')
|
|
self.assertEqual(publisher.publication_changes(source, target), [])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|

Staff