コード例 #1
0
    def test_upload_files(self):
        options = argparse.Namespace()
        stdout = StdOutIO()
        command = commands.Command(options, stdout=stdout)
        uploader = mock.create_autospec(upload.PackageUploader,
                                        host='http://localhost:8000')
        upload_results = [None, exceptions.PackageConflictError('foo')]

        def upload_side_effect(*args):
            result = upload_results.pop()
            if isinstance(result, Exception):
                raise result
            return result

        uploader.upload.side_effect = upload_side_effect

        command._upload_files(
            uploader,
            ['packages/mock-1.0.1.tar.gz', 'packages/coverage-3.7.1.tar.gz'])

        stdout.seek(0)
        assert uploader.upload.call_args_list == [
            mock.call('packages/mock-1.0.1.tar.gz'),
            mock.call('packages/coverage-3.7.1.tar.gz'),
        ]
        assert stdout.read() == (
            'Uploading packages to http://localhost:8000\n'
            'Uploading packages/mock-1.0.1.tar.gz... already uploaded.\n'
            'Uploading packages/coverage-3.7.1.tar.gz... success.\n')
コード例 #2
0
    def test_packages(self, upload_mock, download_mock):
        upload_results = [None, exceptions.PackageConflictError('foo')]

        def upload_side_effect(*args):
            result = upload_results.pop()
            if isinstance(result, Exception):
                raise result
            return result

        upload_mock.side_effect = upload_side_effect
        download_mock.return_value = [
            'packages/coverage-3.7.1.tar.gz', 'packages/mock-1.0.1.tar.gz'
        ]
        argv = [
            'packages',
            'coverage==3.7.1',
            'mock',
            '-i',
            'http://localhost:8000',
            '-u',
            'foo',
            '-p',
            'bar',
            '-d',
            'packages',
        ]
        stdout = StdOutIO()

        commands.main(argv=argv, stdout=stdout)

        stdout.seek(0)
        content = stdout.read()
        assert content == (
            'Uploading packages to http://localhost:8000\n'
            'Uploading packages/coverage-3.7.1.tar.gz... already uploaded.\n'
            'Uploading packages/mock-1.0.1.tar.gz... success.\n')

        assert len(download_mock.call_args_list) == 1
        downloader = download_mock.call_args[0][0]
        assert downloader.download_path == 'packages'
        expected_call = mock.call(downloader,
                                  requirements=['coverage==3.7.1', 'mock'],
                                  requirements_file=None,
                                  no_use_wheel=False)
        assert download_mock.call_args == expected_call

        assert len(upload_mock.call_args_list) == 2
        uploader = upload_mock.call_args[0][0]
        assert uploader.host == 'http://localhost:8000'
        assert uploader.username == 'foo'
        assert uploader.password == 'bar'
        expected_calls = [
            mock.call(uploader, 'packages/coverage-3.7.1.tar.gz'),
            mock.call(uploader, 'packages/mock-1.0.1.tar.gz'),
        ]
        assert upload_mock.call_args_list == expected_calls
コード例 #3
0
    def test_upload_file_conflict(self):
        options = argparse.Namespace()
        stdout = StdOutIO()
        command = commands.Command(options, stdout=stdout)
        uploader = mock.create_autospec(upload.PackageUploader)
        uploader.upload.side_effect = exceptions.PackageConflictError('foo')

        command._upload_file(uploader, 'mock-1.0.1.tar.gz')

        stdout.seek(0)
        assert uploader.upload.call_args == mock.call('mock-1.0.1.tar.gz')
        assert stdout.read() == (
            'Uploading mock-1.0.1.tar.gz... already uploaded.\n')