From 6f17f19463716fe7cac80a660f2ffdfe002a9cf0 Mon Sep 17 00:00:00 2001 From: Jakub Kadlčík Date: Feb 04 2019 08:02:47 +0000 Subject: [cli] properly rewrite download-build to use APIv3 The download-build was reimplemented to APIv3 some time ago, but with mistakes. The command wasn't working at all. This commits finishes it. There are also changes to tests related to download-build command. It was necessary to use `configure_mock`, because we needed to mock a `name` value, which is unfortunately `MagicMock`'s property used for string representation of such object. --- diff --git a/cli/copr_cli/main.py b/cli/copr_cli/main.py index f910b5c..382f788 100644 --- a/cli/copr_cli/main.py +++ b/cli/copr_cli/main.py @@ -465,16 +465,17 @@ class Commands(object): def action_download_build(self, args): build = self.client.build_proxy.get(args.build_id) - base_len = len(os.path.split(build.results)) + base_len = len(os.path.split(build.repo_url)) + build_chroots = self.client.build_chroot_proxy.get_list(args.build_id) - for chroot, url in build.results_by_chroot.items(): - if args.chroots and chroot not in args.chroots: + for chroot in build_chroots: + if args.chroots and chroot.name not in args.chroots: continue cmd = "wget -r -nH --no-parent --reject 'index.html*'".split(' ') - cmd.extend(['-P', os.path.join(args.dest, chroot)]) + cmd.extend(['-P', os.path.join(args.dest, chroot.name)]) cmd.extend(['--cut-dirs', str(base_len + 4)]) - cmd.append(url) + cmd.append(chroot.result_url) subprocess.call(cmd) @requires_api_auth diff --git a/cli/tests/test_cli.py b/cli/tests/test_cli.py index 2508c67..9866a29 100644 --- a/cli/tests/test_cli.py +++ b/cli/tests/test_cli.py @@ -281,19 +281,22 @@ def test_delete_project(config_from_file, project_proxy_delete, capsys): @mock.patch('copr_cli.main.subprocess') @mock.patch('copr.v3.proxies.build.BuildProxy.get') +@mock.patch('copr.v3.proxies.build_chroot.BuildChrootProxy.get_list') @mock.patch('copr_cli.main.config_from_file', return_value=mock_config) -def test_download_build(config_from_file, build_proxy_get, mock_sp, capsys): - build_proxy_get.return_value = \ - MagicMock( - data={"chroots": { - u'epel-6-x86_64': u'succeeded', u'epel-6-i386': u'succeeded' - }}, - results="http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20", - results_by_chroot={ - u'epel-6-x86_64': u'http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20', - u'epel-6-i386': u'http://example.com/results/epel-6-i386/python-copr-1.50-1.fc20', - } - ) +def test_download_build(config_from_file, build_chroot_proxy_get_list, build_proxy_get, mock_sp, capsys): + build_proxy_get.return_value = MagicMock( + repo_url="http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20") + + mock_ch1 = MagicMock() + mock_ch1.configure_mock( + name="epel-6-x86_64", + result_url="http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20") + + mock_ch2 = MagicMock() + mock_ch2.configure_mock( + name="epel-6-i386", + result_url="http://example.com/results/epel-6-i386/python-copr-1.50-1.fc20") + build_chroot_proxy_get_list.return_value = [mock_ch1, mock_ch2] mock_sp.call.return_value = None main.main(argv=["download-build", "foo"]) @@ -318,19 +321,22 @@ def test_download_build(config_from_file, build_proxy_get, mock_sp, capsys): @mock.patch('copr_cli.main.subprocess') @mock.patch('copr.v3.proxies.build.BuildProxy.get') +@mock.patch('copr.v3.proxies.build_chroot.BuildChrootProxy.get_list') @mock.patch('copr_cli.main.config_from_file', return_value=mock_config) -def test_download_build_select_chroot(config_from_file, build_proxy_get, mock_sp, capsys): - build_proxy_get.return_value = \ - MagicMock( - data={"chroots": { - u'epel-6-x86_64': u'succeeded', u'epel-6-i386': u'succeeded' - }}, - results="http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20", - results_by_chroot={ - u'epel-6-x86_64': u'http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20', - u'epel-6-i386': u'http://example.com/results/epel-6-i386/python-copr-1.50-1.fc20', - } - ) +def test_download_build_select_chroot(config_from_file, build_chroot_proxy_get_list, build_proxy_get, mock_sp, capsys): + build_proxy_get.return_value = MagicMock( + repo_url="http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20") + + mock_ch1 = MagicMock() + mock_ch1.configure_mock( + name="epel-6-x86_64", + result_url="http://example.com/results/epel-6-x86_64/python-copr-1.50-1.fc20") + + mock_ch2 = MagicMock() + mock_ch2.configure_mock( + name="epel-6-i386", + result_url="http://example.com/results/epel-6-i386/python-copr-1.50-1.fc20") + build_chroot_proxy_get_list.return_value = [mock_ch1, mock_ch2] mock_sp.call.return_value = None main.main(argv=["download-build", "foo", "-r", "epel-6-x86_64"])