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
|
import pytest
from obsapi.repoflags import RepoFlags
xml1 = """<project name="home:sbahling:obsapi:test">
<title>Test project for obsapi unit tests</title>
<description/>
<person userid="sbahling" role="maintainer"/>
<repository name="SLE_15_SP1">
<path project="SUSE:SLE-15-SP1:GA" repository="standard"/>
<arch>x86_64</arch>
</repository>
<repository name="SLE_12_SP3">
<path project="SUSE:SLE-12-SP3:GA" repository="standard"/>
<arch>x86_64</arch>
</repository>
</project>"""
xml2 = """<package name="suse-hello-1.0" project="home:sbahling:obsapi:test">
<title>Example from Kernel Module Packages Manual</title>
<description/>
<build>
<enable arch="x86_64" repository="SLE_12_SP3"/>
<disable/>
</build>
<debuginfo>
<enable/>
</debuginfo>
<useforbuild>
<disable arch="x86_64" repository="SLE_15_SP1"/>
</useforbuild>
</package>"""
flag_types = ['build', 'publish', 'useforbuild', 'debuginfo']
def test_repo_flags_default_type():
repo_flags = RepoFlags()
assert repo_flags.flag_type == 'build'
@pytest.mark.parametrize('flag_type', flag_types)
def test_repo_flags_flag_type(flag_type):
repo_flags = RepoFlags(flag_type)
assert repo_flags.flag_type == flag_type
assert repo_flags.root.tag == flag_type
def test_repo_flags_invalid_flag_type():
with pytest.raises(ValueError):
RepoFlags('invalid')
def test_repo_flags_pass_xml_without_flags():
repo_flags = RepoFlags(xml=xml1)
assert repo_flags.flag_type == 'build'
def test_repo_flags_pass_xml_with_flags():
repo_flags = RepoFlags(xml=xml2)
assert repo_flags.flag_type in flag_types
def test_repo_flags_xml_build_flags():
repo_flags = RepoFlags('build', xml=xml2)
assert repo_flags.flag_type == 'build'
for flag in repo_flags.flags:
if flag.status == 'enable':
assert flag.repository == 'SLE_12_SP3'
assert flag.arch == 'x86_64'
if flag.status == 'disable':
assert flag.repository is None
assert flag.arch is None
def test_repo_flags_xml_debuginfo_flags():
repo_flags = RepoFlags('debuginfo', xml=xml2)
assert repo_flags.flag_type == 'debuginfo'
for flag in repo_flags.flags:
if flag.status == 'enable':
assert flag.repository is None
assert flag.arch is None
def test_repo_flags_xml_new_flags():
repo_flags = RepoFlags('publish', xml=xml2)
assert repo_flags.flag_type == 'publish'
assert len(list(repo_flags.flags)) == 0
params = [('useforbuild', 'SLE_15_SP1', 'x86_64'),
('publish', None, None),
('debuginfo', None, 'aarch64'),
('build', 'SLE_12_SP3', None)
]
@pytest.mark.parametrize('flag_type, repo, arch', params)
def test_repo_flags_enable(flag_type, repo, arch):
repoflags = RepoFlags(flag_type)
repoflags.enable(repo=repo, arch=arch)
for flag in repoflags.flags:
assert flag.status == 'enable'
assert flag.repository == repo
assert flag.arch == arch
@pytest.mark.parametrize('flag_type, repo, arch', params)
def test_repo_flags_disable(flag_type, repo, arch):
repoflags = RepoFlags(flag_type)
repoflags.disable(repo=repo, arch=arch)
for flag in repoflags.flags:
assert flag.status == 'disable'
assert flag.repository == repo
assert flag.arch == arch
def test_repo_flags_set_invalid():
repoflags = RepoFlags()
with pytest.raises(ValueError):
repoflags.set('invalid')
|