diff options
| author | Scott Bahling <sbahling@suse.com> | 2020-02-06 22:16:02 +0100 |
|---|---|---|
| committer | Scott Bahling <sbahling@suse.com> | 2020-02-06 22:35:43 +0100 |
| commit | cd12f43cd2c98826bb0ea092ef590a91e5842886 (patch) | |
| tree | fc13c2f90a9e3190ab172b1556dc1eb3caa124b4 /test | |
| parent | c86fdd52a30ca1833149d46b7fee9135a74e4598 (diff) | |
| download | obsapi-cd12f43cd2c98826bb0ea092ef590a91e5842886.tar.gz obsapi-cd12f43cd2c98826bb0ea092ef590a91e5842886.tar.xz obsapi-cd12f43cd2c98826bb0ea092ef590a91e5842886.zip | |
Handle passing bytes to the FileInfo class
Move class to own file and enhance tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/binary_fileinfo.xml | 40 | ||||
| -rw-r--r-- | test/test_api.py | 23 | ||||
| -rw-r--r-- | test/test_fileinfo.py | 26 |
3 files changed, 73 insertions, 16 deletions
diff --git a/test/binary_fileinfo.xml b/test/binary_fileinfo.xml new file mode 100644 index 0000000..28a8dd5 --- /dev/null +++ b/test/binary_fileinfo.xml @@ -0,0 +1,40 @@ +<fileinfo filename="apache2-2.4.41-12.1.src.rpm"> + <name>apache2</name> + <version>2.4.41</version> + <release>12.1</release> + <arch>src</arch> + <summary>The Apache Web Server</summary> + <description>This version of httpd is a major release of the 2.4 stable branch, +and represents the best available version of Apache HTTP Server. +New features include Loadable MPMs, major improvements to OCSP support, +mod_lua, Dynamic Reverse Proxy configuration, Improved Authentication/ +Authorization, FastCGI Proxy, New Expression Parser, and a Small Object +Caching API. + + See /usr/share/doc/packages/apache2/, http://httpd.apache.org/, and +http://httpd.apache.org/docs-2.4/upgrading.html.</description> + <size>7657917</size> + <mtime>1580719265</mtime> + <requires>apache-rpm-macros-control</requires> + <requires>apr-devel >= 1.5.0</requires> + <requires>apr-util-devel</requires> + <requires>automake</requires> + <requires>db-devel</requires> + <requires>ed</requires> + <requires>firewall-macros</requires> + <requires>libcap-devel</requires> + <requires>libxml2-devel</requires> + <requires>lua-devel</requires> + <requires>openldap2-devel</requires> + <requires>openssl-devel >= 0.9.8a</requires> + <requires>pcre-devel</requires> + <requires>pkgconfig</requires> + <requires>pkgconfig(libbrotlidec)</requires> + <requires>pkgconfig(libbrotlienc)</requires> + <requires>pkgconfig(libnghttp2) >= 1.2.1</requires> + <requires>pkgconfig(libsystemd)</requires> + <requires>pkgconfig(systemd)</requires> + <requires>systemd-rpm-macros</requires> + <requires>xz</requires> + <requires>zlib-devel</requires> +</fileinfo> diff --git a/test/test_api.py b/test/test_api.py index 5769543..e45a284 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -48,6 +48,12 @@ def project_config(): @pytest.fixture +def binary_fileinfo(): + with open(os.path.join(test_dir, 'binary_fileinfo.xml'), 'rb') as f: + return f.read() + + +@pytest.fixture def source_info(): return """<sourceinfo package="suse-hello-1.0" rev="1" vrev="1" srcmd5="7054c47fb2ebde13fc62ee64d0a3b1bc" verifymd5="7054c47fb2ebde13fc62ee64d0a3b1bc"> <filename>suse-hello.spec</filename> @@ -95,21 +101,6 @@ def binarylist(): @pytest.fixture -def binary_fileinfo(): - return """<fileinfo filename="suse-hello-1.0-1.1.src.rpm"> -<name>suse-hello</name>i -<version>1.0</version> -<release>1.1</release> -<arch>src</arch> -<summary>Sample Kernel Module Package</summary> -<description>This package contains the hello.ko module.</description> -<size>5181</size><mtime>1507137122</mtime> -<requires>kmod-compat</requires> -<requires>kernel-syms</requires> -</fileinfo>""" - - -@pytest.fixture def project_meta(): return """<project name="home:sbahling:obsapi:test"> <title>Test project for obsapi unit tests</title> @@ -340,7 +331,7 @@ def test_source_info(requests_mock, source_info, rev): def test_get_binary_fileinfo(requests_mock, binary_fileinfo): matcher = re.compile('/build/.*/.*/.*/.*/.*?view=fileinfo') - requests_mock.get(matcher, text=binary_fileinfo) + requests_mock.get(matcher, content=binary_fileinfo) binary = 'suse-hello-1.0-1.1.src.rpm' expected_bfinfo = etree.fromstring(binary_fileinfo) diff --git a/test/test_fileinfo.py b/test/test_fileinfo.py new file mode 100644 index 0000000..18d1f15 --- /dev/null +++ b/test/test_fileinfo.py @@ -0,0 +1,26 @@ +import os +import pytest +from lxml import etree +from obsapi import FileInfo +from . import test_dir + + +with open(os.path.join(test_dir, 'binary_fileinfo.xml'), 'rb') as f: + xml_as_bytes = f.read() + + +with open(os.path.join(test_dir, 'binary_fileinfo.xml'), 'r') as f: + xml_as_str = f.read() + + +@pytest.mark.parametrize('xml', (xml_as_bytes, xml_as_str)) +def test_fileinfo(xml): + finfo = FileInfo(xml) + root = etree.fromstring(xml) + assert finfo.name == root.find('name').text + assert finfo.version == root.find('version').text + assert finfo.release == root.find('release').text + assert finfo.arch == root.find('arch').text + assert finfo.summary == root.find('summary').text + assert finfo.description == root.find('description').text + assert len(finfo.requires) == len(root.findall('requires')) |
