From cd12f43cd2c98826bb0ea092ef590a91e5842886 Mon Sep 17 00:00:00 2001 From: Scott Bahling Date: Thu, 6 Feb 2020 22:16:02 +0100 Subject: Handle passing bytes to the FileInfo class Move class to own file and enhance tests --- test/binary_fileinfo.xml | 40 ++++++++++++++++++++++++++++++++++++++++ test/test_api.py | 23 +++++++---------------- test/test_fileinfo.py | 26 ++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 test/binary_fileinfo.xml create mode 100644 test/test_fileinfo.py (limited to 'test') 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 @@ + + apache2 + 2.4.41 + 12.1 + src + The Apache Web Server + 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. + 7657917 + 1580719265 + apache-rpm-macros-control + apr-devel >= 1.5.0 + apr-util-devel + automake + db-devel + ed + firewall-macros + libcap-devel + libxml2-devel + lua-devel + openldap2-devel + openssl-devel >= 0.9.8a + pcre-devel + pkgconfig + pkgconfig(libbrotlidec) + pkgconfig(libbrotlienc) + pkgconfig(libnghttp2) >= 1.2.1 + pkgconfig(libsystemd) + pkgconfig(systemd) + systemd-rpm-macros + xz + zlib-devel + 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 @@ -47,6 +47,12 @@ def project_config(): return f.read() +@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 """ @@ -94,21 +100,6 @@ def binarylist(): """ -@pytest.fixture -def binary_fileinfo(): - return """ -suse-helloi -1.0 -1.1 -src -Sample Kernel Module Package -This package contains the hello.ko module. -51811507137122 -kmod-compat -kernel-syms -""" - - @pytest.fixture def project_meta(): return """ @@ -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')) -- cgit v1.2.3