Files
archy/scripts/tests/test_release_source_binding.py

60 lines
2.4 KiB
Python

"""Read-only metadata fixtures; no real release artifacts or signing keys."""
import copy
import importlib.util
from pathlib import Path
import unittest
spec = importlib.util.spec_from_file_location('binding', Path(__file__).parents[1] / 'check-release-source-binding.py')
binding = importlib.util.module_from_spec(spec)
spec.loader.exec_module(binding)
COMMIT = 'a' * 40
VERSION = '2.1.0-beta'
class SourceBindingTests(unittest.TestCase):
def setUp(self):
self.manifest = {'version': VERSION, 'source_commit': COMMIT, 'components': [{
'new_version': VERSION,
'download_url': 'https://registry.invalid/org/project/releases/download/v' + VERSION + '/archipelago',
}]}
def check(self, manifest=None, backend=VERSION, frontend=VERSION):
binding.validate(manifest or self.manifest, COMMIT, backend, frontend)
def test_matching_reviewed_source(self):
self.check()
def test_stale_manifest_and_component(self):
for target in ['manifest', 'component']:
with self.subTest(target=target):
value = copy.deepcopy(self.manifest)
if target == 'manifest':
value['version'] = '1.9.1-alpha'
else:
value['components'][0]['new_version'] = '1.9.1-alpha'
with self.assertRaises(ValueError):
self.check(value)
def test_backend_frontend_or_source_mismatch(self):
with self.assertRaises(ValueError):
self.check(backend='1.9.1-alpha')
with self.assertRaises(ValueError):
self.check(frontend='1.9.1-alpha')
self.manifest['source_commit'] = 'b' * 40
with self.assertRaises(ValueError):
self.check()
def test_stale_or_unbound_urls(self):
for url in ['https://registry.invalid/releases/download/v1.9.1-alpha/archipelago',
'http://registry.invalid/releases/download/v2.1.0-beta/archipelago',
'https://registry.invalid/releases/download/v2.1.0-beta/../old',
'https://registry.invalid/releases/download/v2.1.0-beta/app?old=1']:
with self.subTest(url=url):
self.manifest['components'][0]['download_url'] = url
with self.assertRaises(ValueError):
self.check()
if __name__ == '__main__':
unittest.main()