Add authenticated photo uploads and GitHub Actions publishing
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
DEPLOY = ROOT / 'scripts/deploy-site.sh'
|
||||
|
||||
|
||||
class DeploymentTests(unittest.TestCase):
|
||||
def test_manifest_only_lists_rendered_photos(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
root = Path(folder)
|
||||
(root / '_site/art').mkdir(parents=True)
|
||||
job = 'a' * 64
|
||||
(root / '_site/art/index.html').write_text(f'<div id="photo-{job}"></div>')
|
||||
subprocess.run(['python3', str(ROOT / 'scripts/photo-manifest.py')], cwd=root,
|
||||
env=dict(os.environ, GITHUB_SHA='b' * 40), check=True)
|
||||
self.assertEqual(json.loads((root / '_site/photo-publication.json').read_text()),
|
||||
{'commit': 'b' * 40, 'photos': [job]})
|
||||
|
||||
@unittest.skipUnless(platform.system() == 'Linux', 'Production activation uses GNU mv and flock')
|
||||
def test_activation_failure_and_stale_workflow(self):
|
||||
activation = DEPLOY.read_text().split("<<'REMOTE'\n", 1)[1].rsplit('\nREMOTE', 1)[0]
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
root = Path(folder)
|
||||
(root / 'releases').mkdir()
|
||||
|
||||
def activate(number, complete=True):
|
||||
release = root / 'releases' / str(number)
|
||||
(release / 'art').mkdir(parents=True)
|
||||
(release / 'art/index.html').write_text(str(number))
|
||||
if complete:
|
||||
(release / 'photo-publication.json').write_text('{"photos":[]}')
|
||||
return subprocess.run(['bash', '-s', '--', str(root), str(release), str(number)],
|
||||
input=activation, text=True, capture_output=True)
|
||||
|
||||
self.assertEqual(activate(2).returncode, 0)
|
||||
self.assertEqual((root / 'current/art/index.html').read_text(), '2')
|
||||
self.assertNotEqual(activate(3, complete=False).returncode, 0)
|
||||
self.assertEqual((root / 'current/art/index.html').read_text(), '2')
|
||||
self.assertEqual(activate(1).returncode, 0)
|
||||
self.assertEqual((root / 'current/art/index.html').read_text(), '2')
|
||||
self.assertEqual(activate(4).returncode, 0)
|
||||
self.assertEqual((root / 'current/art/index.html').read_text(), '4')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user