Exemplo n.º 1
0
def test_link_creation_from_url(mock_token, app, git_url, git_archive,
                                token_key):
    """Given a git url, this test checks if the url creation works correctly."""
    if utils.get_access_token(token_key) is None:
        pytest.skip("No access token found for Git integration. Skipping.")

    repo = GitAPI.create(url=git_url, user_id=1)
    archive_url = repo.archive_repo_url()
    assert archive_url == git_archive.format(get_access_token(token_key))
Exemplo n.º 2
0
def test_download_gitlab_archive_private(client, db, get_git_attributes,
                                         json_headers):
    owner, deposit, pid, bucket, headers = get_git_attributes
    data = {
        'url': 'https://gitlab.cern.ch/analysispreservation/test-private-repo',
        'type': 'repo',
        'for_download': True,
        'for_connection': False
    }

    if get_access_token('GITLAB') is None:
        pytest.skip("No access token found for Git integration. Skipping.")

    resp = client.post('/deposits/{}/actions/upload'.format(pid),
                       headers=headers + json_headers,
                       data=json.dumps(data))
    assert resp.status_code == 201

    resp = client.get('/deposits/{}/files'.format(pid), headers=headers)
    assert resp.status_code == 200

    obj = ObjectVersion.get(
        bucket.id, 'analysispreservation_test-private-repo_master.tar.gz')
    tar_obj = tarfile.open(obj.file.uri)
    repo_file_name = tar_obj.getmembers()[1]
    repo_content = tar_obj.extractfile(repo_file_name).read()

    assert repo_content == 'test repo for cap'
Exemplo n.º 3
0
def test_download_archive_branch(client, db, get_git_attributes, json_headers,
                                 git_url, git, git_record):
    """Given a git url, check if the link correctly identifies the repo, downloads its data,
       and then CAP is able to retrieve them from a bucket.
    """
    owner, deposit, pid, bucket, headers = get_git_attributes
    data = {
        'url': git_url,
        'type': 'repo',
        'for_download': True,
        'for_connection': False
    }

    if get_access_token(git) is None:
        pytest.skip("No access token found for Git integration. Skipping.")

    resp = client.post('/deposits/{}/actions/upload'.format(pid),
                       headers=headers + json_headers,
                       data=json.dumps(data))
    assert resp.status_code == 201

    resp = client.get('/deposits/{}/files'.format(pid), headers=headers)
    assert resp.status_code == 200

    obj = ObjectVersion.get(bucket.id, git_record)
    tar_obj = tarfile.open(obj.file.uri)
    repo_file_name = tar_obj.getmembers()[1]
    repo_content = tar_obj.extractfile(repo_file_name).read()

    assert repo_content == 'test repo for cap - branch\n'
Exemplo n.º 4
0
def test_download_file_branch(client, db, get_git_attributes, json_headers,
                              git_url, git, git_record):
    owner, deposit, pid, bucket, headers = get_git_attributes
    data = {
        'url': git_url,
        'type': 'url',
        'for_download': True,
        'for_connection': False
    }

    if get_access_token(git) is None:
        pytest.skip("No access token found for Git integration. Skipping.")

    resp = client.post('/deposits/{}/actions/upload'.format(pid),
                       headers=headers + json_headers,
                       data=json.dumps(data))
    assert resp.status_code == 201

    resp = client.get('/deposits/{}/files'.format(pid), headers=headers)
    assert resp.status_code == 200

    obj = ObjectVersion.get(bucket.id, git_record)
    open_file = open(obj.file.uri)
    repo_content = open_file.read()
    assert repo_content == 'test repo for cap - branch\n'
Exemplo n.º 5
0
def test_missing_env_variable(mocked_token, app):
    mocked_token.return_value = None
    assert utils.get_access_token("GITHUB") is None