forked from user-cont/release-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_load_release_conf.py
147 lines (127 loc) · 5.45 KB
/
test_load_release_conf.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from pathlib import Path
import pytest
from release_bot.configuration import configuration
class TestLoadReleaseConf:
def setup_method(self):
""" setup any state tied to the execution of the given method in a
class. setup_method is invoked for every test method of a class.
"""
configuration.set_logging(level=10)
configuration.debug = True
def teardown_method(self, method):
""" teardown any state that was previously setup with a setup_method
call.
"""
@pytest.fixture
def empty_conf(self):
"""
Emulates an empty configuration
:return:
"""
return ""
@pytest.fixture
def non_existing_conf(self):
"""
Emulates missing configuration
:return:
"""
return False
@pytest.fixture
def valid_new_release(self):
"""
Emulates valid new_release dict
:return:
"""
new_release = {'version': '0.1.0',
'commitish': 'xxx',
'author_name': 'John Doe',
'author_email': '[email protected]',
'fedora': False,
'fedora_branches': [],
'changelog': [],
'tempdir': None}
return new_release
@pytest.fixture
def missing_items_conf(self):
"""
Emulates configuration with missing required items
:return:
"""
return (Path(__file__).parent / "src/missing_items_conf.yaml").read_text()
@pytest.fixture
def missing_author_conf(self):
"""
Emulates configuration with missing author
:return:
"""
return (Path(__file__).parent / "src/missing_author.yaml").read_text()
@pytest.fixture
def valid_conf(self):
"""
Emulates valid configuration
:return:
"""
return (Path(__file__).parent / "src/release-conf.yaml").read_text()
def test_empty_conf(self, empty_conf):
# if there are any required items, this test must fail
if configuration.REQUIRED_ITEMS['release-conf']:
with pytest.raises(SystemExit) as error:
configuration.load_release_conf(empty_conf)
assert error.type == SystemExit
assert error.value.code == 1
def test_non_exiting_conf(self, non_existing_conf):
# if there are any required items, this test must fail
if configuration.REQUIRED_ITEMS['release-conf']:
with pytest.raises(SystemExit) as error:
configuration.load_release_conf(non_existing_conf)
assert error.type == SystemExit
assert error.value.code == 1
def test_missing_required_items(self, missing_items_conf):
backup = configuration.REQUIRED_ITEMS['release-conf']
# set trigger_on_issue as required
configuration.REQUIRED_ITEMS['release-conf'] = ['trigger_on_issue']
with pytest.raises(SystemExit) as error:
configuration.load_release_conf(missing_items_conf)
assert error.type == SystemExit
assert error.value.code == 1
configuration.REQUIRED_ITEMS['release-conf'] = backup
def test_author_overwrites(self, missing_author_conf, valid_new_release):
author_name = valid_new_release['author_name']
author_email = valid_new_release['author_email']
release_conf = configuration.load_release_conf(missing_author_conf)
valid_new_release.update(release_conf)
assert valid_new_release['author_name'] == author_name
assert valid_new_release['author_email'] == author_email
def test_fedora_disabling(self, valid_conf, valid_new_release):
# fas_username is empty
release_conf = configuration.load_release_conf(valid_conf)
valid_new_release.update(release_conf)
assert valid_new_release['fedora'] is False
def test_normal_use_case(self, valid_conf, valid_new_release):
# set fas_username because without it, fedora releasing will be disabled
configuration.fas_username = 'test'
# test if all items in configuration are properly loaded
release_conf = configuration.load_release_conf(valid_conf)
valid_new_release.update(release_conf)
assert valid_new_release['changelog'] == ['Example changelog entry',
'Another changelog entry']
assert valid_new_release['author_name'] == 'John Smith'
assert valid_new_release['author_email'] == '[email protected]'
assert valid_new_release['fedora'] is True
# this assertion also tests if branches are correct data type
assert valid_new_release['fedora_branches'] == ['f27', 'f28', '13']
assert valid_new_release['labels'] == ['bot', 'release-bot', 'user-cont']