summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorScott Bahling <sbahling@suse.com>2020-01-26 00:53:21 +0100
committerScott Bahling <sbahling@suse.com>2020-01-26 00:53:21 +0100
commitf728ee98064776a186a154e6c931ec3c87719b98 (patch)
tree4860d6698be2fdb8d458a5066c737bcfb06c1379 /test
parent488fe5d1b1eabbf971cfacc573401e53e88274f1 (diff)
downloadobsapi-f728ee98064776a186a154e6c931ec3c87719b98.tar.gz
obsapi-f728ee98064776a186a154e6c931ec3c87719b98.tar.xz
obsapi-f728ee98064776a186a154e6c931ec3c87719b98.zip
Add RepoFlags class and api.get_repo_flags method
Diffstat (limited to 'test')
-rw-r--r--test/test_api.py15
-rw-r--r--test/test_repo_flags.py121
2 files changed, 136 insertions, 0 deletions
diff --git a/test/test_api.py b/test/test_api.py
index 1830a3d..9f57364 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -101,6 +101,21 @@ def test_get_binary_fileinfo():
bfinfo = api.get_binary_fileinfo(prj, pkg, repo, arch, binary)
+def check_get_repo_flags(flag_type, prj, pkg, expected):
+ repo_flags = api.get_repo_flags(flag_type, prj, pkg)
+ assert repo_flags.flag_type == flag_type
+ assert len(list(repo_flags.flags)) == expected
+
+
+def test_get_repo_build_flags():
+ xml = api.get_meta(prj)
+ check_get_repo_flags('build', prj, None, 0)
+ xml = api.get_meta(prj, pkg)
+ meta = etree.fromstring(xml)
+ build = meta.find('build')
+ check_get_repo_flags('build', prj, pkg, len(build))
+
+
def test_lock_project():
api.lock(prj)
xml = api.get_meta(prj)
diff --git a/test/test_repo_flags.py b/test/test_repo_flags.py
new file mode 100644
index 0000000..08a39d6
--- /dev/null
+++ b/test/test_repo_flags.py
@@ -0,0 +1,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.setting == 'enable':
+ assert flag.repo == 'SLE_12_SP3'
+ assert flag.arch == 'x86_64'
+ if flag.setting == 'disable':
+ assert flag.repo 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.setting == 'enable':
+ assert flag.repo 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.setting == 'enable'
+ assert flag.repo == 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.setting == 'disable'
+ assert flag.repo == repo
+ assert flag.arch == arch
+
+
+def test_repo_flags_set_invalid():
+ repoflags = RepoFlags()
+ with pytest.raises(ValueError):
+ repoflags.set('invalid')