Archived
1 parent
f5bdd7e21c
commit
affe28ad71
110 files changed
+52936
-14
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from scripts import gitea_release
|
||||
|
||||
|
||||
def test_release_creates_draft_uploads_and_publishes(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
Path('VERSION').write_text('1.2.3', encoding='utf-8')
|
||||
for key, value in {'GITHUB_REF_NAME':'v1.2.3', 'GITHUB_SERVER_URL':'https://git.example', 'GITHUB_REPOSITORY':'owner/project', 'GITEA_RELEASE_TOKEN':'test-token'}.items():
|
||||
monkeypatch.setenv(key, value)
|
||||
calls = []
|
||||
def archive(args, **kwargs):
|
||||
if args[1] == 'archive':
|
||||
path = next(arg.removeprefix('--output=') for arg in args if arg.startswith('--output='))
|
||||
Path(path).write_bytes(b'test archive')
|
||||
class Response:
|
||||
def __enter__(self): return self
|
||||
def __exit__(self, *args): pass
|
||||
def read(self): return b'{"id": 42}'
|
||||
def urlopen(request, timeout):
|
||||
calls.append(request)
|
||||
return Response()
|
||||
monkeypatch.setattr(gitea_release.subprocess, 'run', archive)
|
||||
monkeypatch.setattr(gitea_release, 'urlopen', urlopen)
|
||||
gitea_release.main()
|
||||
assert [r.method for r in calls] == ['POST', 'POST', 'PATCH']
|
||||
assert json.loads(calls[0].data)['draft'] is True
|
||||
assert b'test archive' in calls[1].data
|
||||
assert json.loads(calls[2].data)['draft'] is False
|
||||
|
||||
|
||||
def test_release_rejects_version_mismatch(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
Path('VERSION').write_text('1.0.0', encoding='utf-8')
|
||||
monkeypatch.setenv('GITHUB_REF_NAME', 'v1.0.1')
|
||||
with pytest.raises(ValueError, match='VERSION'):
|
||||
gitea_release.main()
|
||||
Reference in new issue
Block a user