예제 #1
0
def galaxy_url_fetch(galaxy_context_example_invalid):
    req_spec = RequirementSpec(namespace='some_namespace',
                               name='some_name',
                               version_spec='==9.3.245')

    galaxy_url_fetch = galaxy_url.GalaxyUrlFetch(requirement_spec=req_spec, galaxy_context=galaxy_context_example_invalid)
    log.debug('galaxy_url_fetch: %s', galaxy_url_fetch)

    return galaxy_url_fetch
예제 #2
0
def test_local_file_fetch(mocker):
    tmp_file_fo = tempfile.NamedTemporaryFile(prefix='tmp',
                                              suffix='.tar.gz',
                                              delete=True)
    log.debug('tmp_file_fo.name=%s tmp_file=%s', tmp_file_fo.name, tmp_file_fo)

    requirement_spec_ = RequirementSpec(namespace='namespace',
                                        name='name',
                                        version_spec='==1.2.3',
                                        fetch_method=FetchMethods.LOCAL_FILE,
                                        src=tmp_file_fo.name)

    mocker.patch(
        'ansible_galaxy.fetch.local_file.LocalFileFetch._load_repository_archive',
        return_value=mocker.Mock(name='mockRepoArchive'))
    mocker.patch(
        'ansible_galaxy.fetch.local_file.LocalFileFetch._load_repository',
        return_value=mocker.Mock(name='mockRepo'))
    local_fetch = local_file.LocalFileFetch(requirement_spec_)

    find_results = local_fetch.find()
    results = local_fetch.fetch(find_results=find_results)

    log.debug('results: %s', results)
    local_fetch.cleanup()

    # LocalFileFetch is acting directly on an existing file, so it's cleanup
    # should _not_ delete the file
    assert os.path.isfile(tmp_file_fo.name)

    # results = {'archive_path': '/tmp/tmpcle_fdtp.tar.gz', 'fetch_method': 'local_file',
    # 'custom': {'local_path': '/tmp/tmpcle_fdtp.tar.gz'},
    # 'content': {'galaxy_namespace': None, 'repo_name': '/tmp/tmpcle_fdtp.tar',
    # 'fetched_name': <Mock name='mockRepo.repository_spec.name' id='139946600228288'>}}
    assert results['archive_path'] == tmp_file_fo.name
    assert results['fetch_method'] == 'local_file'
    assert results['custom']['local_path'] == tmp_file_fo.name

    log.debug('should unlink %s here', tmp_file_fo.name)
예제 #3
0
def test_find_new_deps_from_installed(galaxy_context):
    repo_spec = RepositorySpec(namespace='some_namespace',
                               name='some_name',
                               version='4.3.2')

    req_spec = RequirementSpec(namespace='some_required_namespace',
                               name='some_required_name',
                               version_spec='==1.0.0')

    some_requirement = Requirement(repository_spec=repo_spec,
                                   op=RequirementOps.EQ,
                                   requirement_spec=req_spec)

    installed_repo = Repository(
        repo_spec, requirements=[some_requirement, some_requirement])
    res = install.find_new_deps_from_installed(galaxy_context,
                                               [installed_repo])

    log.debug('res: %s', res)
    assert isinstance(res, list)
    assert isinstance(res[0], Requirement)
    assert res[0].requirement_spec == req_spec
예제 #4
0
def test_editable_fetch_fetch(galaxy_context, mocker, tmpdir):
    name = 'mazer_fetch_test_editable'
    namespace_override = 'some_editable_namespace'

    tmp_working_path = tmpdir.mkdir('some_working_tree')
    dest_tmp_path = tmp_working_path.mkdir('some_checkout')

    req_spec = RequirementSpec(namespace=namespace_override,
                               name=name,
                               fetch_method='EDITABLE',
                               src=dest_tmp_path,
                               version_spec='*')
    # RepositorySpec(namespace='some_editable_namespace', name='some_checkout',
    #                version=None, fetch_method='EDITABLE', scm=None,
    #                spec_string='/tmp/pytest-of-adrian/pytest-79/test_editable_fetch_fetch0/some_checkout',
    #                src='/tmp/pytest-of-adrian/pytest-79/test_editable_fetch_fetch0/some_checkout')
    log.debug('req_spec: %r', req_spec)

    fetcher = editable.EditableFetch(galaxy_context, req_spec)

    find_results = {
        'custom': {
            'real_path': dest_tmp_path.strpath
        },
        'content': []
    }

    res = fetcher.fetch(find_results=find_results)
    log.debug('res: %s', res)

    expected_link_name = os.path.join(galaxy_context.collections_path,
                                      COLLECTIONS_PYTHON_NAMESPACE,
                                      namespace_override, name)
    log.debug('expected_link_name: %s', expected_link_name)

    assert isinstance(res, dict)
    assert res['archive_path'] == dest_tmp_path.strpath
    assert res['custom']['symlinked_repo_root'] == expected_link_name