hub: [getRPMFile] add strict behavior
This commit is contained in:
parent
d3ef006842
commit
473bc1460b
4 changed files with 120 additions and 4 deletions
80
tests/test_hub/test_getRPMFile.py
Normal file
80
tests/test_hub/test_getRPMFile.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
|
||||
import mock
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
except ImportError:
|
||||
import unittest
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestGetRPMFile(unittest.TestCase):
|
||||
|
||||
@mock.patch('kojihub.get_rpm')
|
||||
def test_getRPMFile_no_rpminfo(self, get_rpm):
|
||||
def mock_get_rpm(rpmID, strict=False):
|
||||
if strict:
|
||||
raise koji.GenericError('msg')
|
||||
else:
|
||||
return None
|
||||
|
||||
get_rpm.side_effect = mock_get_rpm
|
||||
re = kojihub.RootExports().getRPMFile(1, 'filename')
|
||||
self.assertEquals(re, {})
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.RootExports().getRPMFile(1, 'filename', strict=True)
|
||||
self.assertEquals(cm.exception.args[0], 'msg')
|
||||
|
||||
@mock.patch('kojihub.get_rpm', return_value={'id': 1, 'build_id': None})
|
||||
def test_getRPMFile_external_rpm(self, get_rpm):
|
||||
re = kojihub.RootExports().getRPMFile(1, 'filename')
|
||||
self.assertEquals(re, {})
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.RootExports().getRPMFile(1, 'filename', strict=True)
|
||||
self.assertEquals(cm.exception.args[0],
|
||||
'Can not get RPM file,'
|
||||
' because RPM: 1 is not internal')
|
||||
|
||||
@mock.patch('kojihub.get_rpm', return_value={'id': 1, 'build_id': 1})
|
||||
@mock.patch('kojihub.get_build', return_value={'id': 1})
|
||||
@mock.patch('koji.pathinfo.build', return_value='fakebuildpath')
|
||||
@mock.patch('koji.pathinfo.rpm', return_value='fakerpmrelpath')
|
||||
@mock.patch('os.path.exists', return_value=False)
|
||||
def test_getRPMFile_no_rpmfile(self, ope, pr, pb, get_build, get_rpm):
|
||||
re = kojihub.RootExports().getRPMFile(1, 'filename')
|
||||
self.assertEquals(re, {})
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.RootExports().getRPMFile(1, 'filename', strict=True)
|
||||
self.assertEquals(cm.exception.args[0],
|
||||
"RPM package file of 1 doesn't exist")
|
||||
|
||||
@mock.patch('kojihub.get_rpm', return_value={'id': 1, 'build_id': 1})
|
||||
@mock.patch('kojihub.get_build')
|
||||
@mock.patch('koji.pathinfo')
|
||||
def test_getRPMFile(self, pi, build, rpm):
|
||||
pi.build.return_value = os.path.join(os.path.dirname(__file__),
|
||||
'../test_lib/data/rpms')
|
||||
pi.rpm.return_value = 'test-files-1-1.fc27.noarch.rpm'
|
||||
getRPMFile = kojihub.RootExports().getRPMFile
|
||||
res = getRPMFile(1, '/fileA')
|
||||
self.assertDictEqual(res, {'digest_algo': 'sha256',
|
||||
'user': 'root',
|
||||
'mtime': int(1535536271),
|
||||
'digest': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
|
||||
'size': 0,
|
||||
'group': 'root',
|
||||
'name': '/fileA',
|
||||
'rpm_id': 1,
|
||||
'flags': 0,
|
||||
'mode': int(0o100755),
|
||||
'md5': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'})
|
||||
res = getRPMFile(1, '/fileB')
|
||||
self.assertEquals(res, {})
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
res = getRPMFile(1, '/fileB', strict=True)
|
||||
self.assertEquals(cm.exception.args[0],
|
||||
'No file: /fileB found in RPM: 1')
|
||||
BIN
tests/test_lib/data/rpms/test-files-1-1.fc27.noarch.rpm
Normal file
BIN
tests/test_lib/data/rpms/test-files-1-1.fc27.noarch.rpm
Normal file
Binary file not shown.
20
tests/test_lib/data/specs/test-files._spec
Normal file
20
tests/test_lib/data/specs/test-files._spec
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
Name: test-files
|
||||
Version: 1
|
||||
Release: 1%{?dist}
|
||||
Summary: Testing files header fields
|
||||
|
||||
License: none
|
||||
|
||||
%description
|
||||
Testing files header fields
|
||||
|
||||
%install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
install -d $RPM_BUILD_ROOT/foo/bar
|
||||
install -pm 0755 fileA $RPM_BUILD_ROOT
|
||||
install -pm 0600 foo/bar/fileB $RPM_BUILD_ROOT/foo/bar
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
/fileA
|
||||
/foo/bar/fileB
|
||||
Loading…
Add table
Add a link
Reference in a new issue