2021-01-15 08:53:01 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
|
|
|
import os
|
|
|
|
from collections import defaultdict
|
|
|
|
from unittest import TestCase, mock, main
|
|
|
|
|
|
|
|
from pungi.scripts.create_packages_json import PackagesGenerator, RepoInfo
|
|
|
|
|
|
|
|
FOLDER_WITH_TEST_DATA = os.path.join(
|
|
|
|
os.path.dirname(
|
|
|
|
os.path.abspath(__file__)
|
|
|
|
),
|
|
|
|
'data/test_create_packages_json/',
|
|
|
|
)
|
|
|
|
|
|
|
|
test_repo_info = RepoInfo(
|
|
|
|
path=FOLDER_WITH_TEST_DATA,
|
|
|
|
folder='test_repo',
|
|
|
|
name='TestRepo',
|
|
|
|
arch='x86_64',
|
|
|
|
is_remote=False,
|
2021-06-15 13:16:10 +00:00
|
|
|
is_reference=True,
|
2021-01-15 08:53:01 +00:00
|
|
|
)
|
|
|
|
|
2021-06-04 09:36:03 +00:00
|
|
|
test_repo_info_2 = RepoInfo(
|
|
|
|
path=FOLDER_WITH_TEST_DATA,
|
|
|
|
folder='test_repo_2',
|
|
|
|
name='TestRepo2',
|
|
|
|
arch='x86_64',
|
|
|
|
is_remote=False,
|
2021-06-15 13:16:10 +00:00
|
|
|
is_reference=True,
|
2021-06-04 09:36:03 +00:00
|
|
|
)
|
|
|
|
|
2021-01-15 08:53:01 +00:00
|
|
|
|
|
|
|
class TestPackagesJson(TestCase):
|
2022-04-29 18:25:59 +00:00
|
|
|
def test_01_get_remote_file_content(self):
|
2021-01-15 08:53:01 +00:00
|
|
|
"""
|
|
|
|
Test the getting of content from a remote file
|
|
|
|
"""
|
|
|
|
request_object = mock.Mock()
|
|
|
|
request_object.raise_for_status = lambda: True
|
|
|
|
request_object.content = b'TestContent'
|
|
|
|
with mock.patch(
|
|
|
|
'pungi.scripts.create_packages_json.requests.get',
|
|
|
|
return_value=request_object,
|
|
|
|
) as mock_requests_get, mock.patch(
|
|
|
|
'pungi.scripts.create_packages_json.tempfile.NamedTemporaryFile',
|
|
|
|
) as mock_tempfile:
|
|
|
|
mock_tempfile.return_value.__enter__.return_value.name = 'tmpfile'
|
2022-04-29 18:25:59 +00:00
|
|
|
file_name = PackagesGenerator.get_remote_file_content(
|
|
|
|
file_url='fakeurl')
|
2021-01-15 08:53:01 +00:00
|
|
|
mock_requests_get.assert_called_once_with(url='fakeurl')
|
2022-05-01 00:41:40 +00:00
|
|
|
mock_tempfile.assert_called_once_with(delete=True)
|
2021-01-15 08:53:01 +00:00
|
|
|
mock_tempfile.return_value.__enter__().\
|
|
|
|
write.assert_called_once_with(b'TestContent')
|
|
|
|
self.assertEqual(
|
|
|
|
file_name,
|
|
|
|
'tmpfile',
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_02_generate_additional_packages(self):
|
|
|
|
pg = PackagesGenerator(
|
|
|
|
repos=[
|
|
|
|
test_repo_info,
|
2021-06-04 09:36:03 +00:00
|
|
|
test_repo_info_2,
|
2021-01-15 08:53:01 +00:00
|
|
|
],
|
|
|
|
excluded_packages=['zziplib-utils'],
|
2021-06-15 13:16:10 +00:00
|
|
|
included_packages=['389-ds-base-new*'],
|
2021-01-15 08:53:01 +00:00
|
|
|
)
|
|
|
|
test_packages = defaultdict(
|
|
|
|
lambda: defaultdict(
|
|
|
|
lambda: defaultdict(
|
|
|
|
list,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2021-06-04 09:36:03 +00:00
|
|
|
test_packages['TestRepo2']['x86_64']['zziplib'] = \
|
|
|
|
[
|
|
|
|
'zziplib.i686',
|
2021-12-20 11:53:21 +00:00
|
|
|
'zziplib.x86_64',
|
2021-06-04 09:36:03 +00:00
|
|
|
]
|
2021-06-15 13:16:10 +00:00
|
|
|
test_packages['TestRepo2']['x86_64']['389-ds-base-new'] = \
|
|
|
|
[
|
|
|
|
'389-ds-base-new.x86_64',
|
|
|
|
]
|
2021-12-20 11:53:21 +00:00
|
|
|
test_packages['TestRepo']['x86_64']['zziplib'] = \
|
|
|
|
[
|
|
|
|
'zziplib.x86_64',
|
|
|
|
]
|
2021-01-15 08:53:01 +00:00
|
|
|
result = pg.generate_packages_json()
|
|
|
|
self.assertEqual(
|
|
|
|
test_packages,
|
|
|
|
result,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|