-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_create_github_release.py
More file actions
56 lines (48 loc) · 1.97 KB
/
test_create_github_release.py
File metadata and controls
56 lines (48 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pytest
import requests
import requests_mock
from gardenlinux.github.release import create_github_release
from ..constants import TEST_GARDENLINUX_COMMIT, TEST_GARDENLINUX_RELEASE
def test_create_github_release_needs_github_token():
with requests_mock.Mocker():
with pytest.raises(ValueError) as exn:
create_github_release(
"gardenlinux",
"gardenlinux",
TEST_GARDENLINUX_RELEASE,
TEST_GARDENLINUX_COMMIT,
False,
"")
assert str(exn.value) == "GITHUB_TOKEN environment variable not set", \
"Expected an exception to be raised on missing GITHUB_TOKEN environment variable"
def test_create_github_release_raise_on_failure(caplog, github_token):
with requests_mock.Mocker() as m:
with pytest.raises(requests.exceptions.HTTPError):
m.post(
"https://api.github.com/repos/gardenlinux/gardenlinux/releases",
text="{}",
status_code=503
)
create_github_release(
"gardenlinux",
"gardenlinux",
TEST_GARDENLINUX_RELEASE,
TEST_GARDENLINUX_COMMIT,
False,
"")
assert any("Failed to create release" in record.message for record in caplog.records), "Expected a failure log record"
def test_create_github_release(caplog, github_token):
with requests_mock.Mocker() as m:
m.post(
"https://api.github.com/repos/gardenlinux/gardenlinux/releases",
text='{"id": 101}',
status_code=201
)
assert create_github_release(
"gardenlinux",
"gardenlinux",
TEST_GARDENLINUX_RELEASE,
TEST_GARDENLINUX_COMMIT,
False,
"") == 101
assert any("Release created successfully" in record.message for record in caplog.records), "Expected a success log record"