sandcastle-ng

Scripts for the deployment of Sandcastle (GNU Taler)
Log | Files | Refs | README

test_sandcastle_upgrade.py (2152B)


      1 # This file is in the public domain.
      2 
      3 import importlib.machinery
      4 import importlib.util
      5 import tempfile
      6 import unittest
      7 from pathlib import Path
      8 from types import SimpleNamespace
      9 from unittest.mock import patch
     10 
     11 from buildscripts.package_config import load_config, parse_config, write_config
     12 
     13 
     14 ROOT = Path(__file__).resolve().parents[1]
     15 LOADER = importlib.machinery.SourceFileLoader(
     16     "sandcastle_upgrade", str(ROOT / "sandcastle-upgrade")
     17 )
     18 SPEC = importlib.util.spec_from_loader(LOADER.name, LOADER)
     19 UPGRADE = importlib.util.module_from_spec(SPEC)
     20 LOADER.exec_module(UPGRADE)
     21 
     22 
     23 class UpgradeTests(unittest.TestCase):
     24     def test_shared_repository_is_queried_once_and_tags_are_written(self):
     25         config = parse_config(
     26             {
     27                 "repositories": {
     28                     "workspace": {"url": "git://example.test/workspace.git"}
     29                 },
     30                 "packages": {
     31                     "one": {"repository": "workspace", "tag": "v1.0.0"},
     32                     "two": {"repository": "workspace", "tag": "v1.0.0"},
     33                 },
     34             }
     35         )
     36         with tempfile.TemporaryDirectory() as temporary:
     37             config_path = Path(temporary) / "packages.toml"
     38             write_config(config_path, config)
     39             arguments = SimpleNamespace(components=["one", "two"], dev=False, dry=False)
     40             with patch.object(
     41                 UPGRADE, "list_remote_tags", return_value=["v1.0.0", "v1.0.1"]
     42             ) as list_remote_tags:
     43                 UPGRADE.upgrade(arguments, config_path)
     44 
     45             updated = load_config(config_path)
     46             self.assertEqual("v1.0.1", updated.packages["one"].tag)
     47             self.assertEqual("v1.0.1", updated.packages["two"].tag)
     48             list_remote_tags.assert_called_once_with("git://example.test/workspace.git")
     49 
     50     def test_unknown_package_is_rejected(self):
     51         with self.assertRaisesRegex(UPGRADE.ConfigError, "unknown package"):
     52             UPGRADE.upgrade(
     53                 SimpleNamespace(components=["missing"], dev=False, dry=True),
     54                 ROOT / "packages.toml",
     55             )
     56 
     57 
     58 if __name__ == "__main__":
     59     unittest.main()