示例#1
0
    def test_fetch_file(self):
        remote_dep = _make_dep(location='remote')
        local_dep = _make_dep(location='local')
        project_dep = _make_dep(location='project')
        p1 = Path('path1')
        p2 = Path('path2')
        p3 = Path('path3')
        context = DependencyContext([], Language({}, 'lang'),
                                    Configuration({}, [], None))

        context._handle_remote_resolution = MagicMock(return_value=p1)
        context._handle_local_resolution = MagicMock(return_value=p2)
        context._handle_project_resolution = MagicMock(return_value=p3)

        r1 = context._fetch_file(remote_dep, 'remote.name')
        r2 = context._fetch_file(local_dep, 'local.name')
        r3 = context._fetch_file(project_dep, 'project.name')

        context._handle_remote_resolution.assert_called_once_with(
            'remote.name')
        context._handle_local_resolution.assert_called_once_with('local.name')
        context._handle_project_resolution.assert_called_once_with(
            'dep', 'project.name')

        assert r1 is p1
        assert r2 is p2
        assert r3 is p3
示例#2
0
    def test_to_local_file_no_path(self):
        mock_fetch = MagicMock(return_value=None)
        dep = _make_dep()
        context = DependencyContext([], Language({}, 'lang'),
                                    Configuration({}, [], None))

        context._fetch_file = mock_fetch

        assert context.to_local_path(dep, 'file.txt') is None

        mock_fetch.assert_called_once_with(dep, 'file.txt')
示例#3
0
    def test_to_local_file_empty_signatures(self):
        path = 'file.txt'
        mock_fetch = MagicMock(return_value=path)
        dep = _make_dep()
        context = DependencyContext([], Language({}, 'lang'),
                                    Configuration({}, [], None))

        context._fetch_file = mock_fetch

        assert context.to_local_path(dep, 'file.txt', {}) is path

        mock_fetch.assert_called_once_with(dep, 'file.txt')
示例#4
0
    def test_to_local_file_good_passed_signatures(self, tmpdir):
        directory = Path(str(tmpdir))
        path = directory / 'file.txt'
        mock_fetch = MagicMock(return_value=path)
        dep = _make_dep()
        context = DependencyContext([], Language({}, 'lang'),
                                    Configuration({}, [], None))
        context._fetch_file = mock_fetch

        path.write_text("file content.\n")

        signatures = sign_path(path)

        assert context.to_local_path(dep, 'file.txt', signatures) is path
        assert mock_fetch.mock_calls == [call(dep, 'file.txt')]
示例#5
0
    def test_to_local_file_bad_passed_signatures(self, tmpdir):
        directory = Path(str(tmpdir))
        path = directory / 'file.txt'
        mock_fetch = MagicMock(return_value=path)
        dep = _make_dep()
        context = DependencyContext([], Language({}, 'lang'),
                                    Configuration({}, [], None))
        context._fetch_file = mock_fetch

        path.write_text("file content.\n")

        with pytest.raises(ValueError) as info:
            context.to_local_path(dep, 'file.txt', {'sha512': 'bad-signature'})

        assert info.value.args[
            0] == 'Dependency path:\n\nCould not verify the signature of the file file.txt.'
        assert mock_fetch.mock_calls == [call(dep, 'file.txt')]
示例#6
0
    def test_to_local_file_good_file_signatures(self, tmpdir):
        directory = Path(str(tmpdir))
        path = directory / 'file.txt'
        file_names = ['file.txt']
        file_names.extend([f'file.txt.{sn}' for sn in supported_signatures])
        mock_fetch = MagicMock(
            side_effect=[directory / name for name in file_names])
        dep = _make_dep()
        context = DependencyContext([], Language({}, 'lang'),
                                    Configuration({}, [], None))
        context._fetch_file = mock_fetch
        file_names = ['file.txt']
        file_names.extend([f'file.txt.{sn}' for sn in supported_signatures])

        path.write_text("file content.\n")

        sign_path_to_files(path)

        assert context.to_local_path(dep, 'file.txt') == path
        assert mock_fetch.mock_calls == [
            call(dep, 'file.txt'),
            call(dep, f'file.txt.{supported_signatures[0]}')
        ]