def test_get_workspace_diff(app, default_user,
                            sample_yadage_workflow_in_db,
                            sample_serial_workflow_in_db,
                            tmp_shared_volume_path,
                            sample_workflow_workspace):
    """Test get workspace differences."""
    # create the workspaces for the two workflows
    workspace_path_a = next(sample_workflow_workspace(
        str(sample_serial_workflow_in_db.id_)))
    workspace_path_b = next(sample_workflow_workspace(
        str(sample_yadage_workflow_in_db.id_)))

    sample_serial_workflow_in_db.get_workspace = lambda: str(
        sample_serial_workflow_in_db.id_)
    sample_yadage_workflow_in_db.get_workspace = lambda: str(
        sample_yadage_workflow_in_db.id_)
    # modify the contents in one file
    with open(
            os.path.join(
                workspace_path_a, 'data',
                'World_historical_and_predicted_populations_in_percentage.csv'
            ), 'a') as f:
        f.write('An extra line')
        f.flush()
    with app.test_client() as client:
        res = client.get(url_for(
            'api.get_workflow_diff',
            workflow_id_or_name_a=sample_serial_workflow_in_db.id_,
            workflow_id_or_name_b=sample_yadage_workflow_in_db.id_),
            query_string={'user': default_user.id_},
            content_type='application/json')
        assert res.status_code == 200
        response_data = json.loads(res.get_data(as_text=True))
        assert 'An extra line' in response_data['workspace_listing']
Exemple #2
0
def test_calculate_file_access_time(sample_workflow_workspace):  # noqa: F811
    """Test calculate_file_access_time."""
    sample_workflow_workspace_path = next(sample_workflow_workspace("sample"))
    access_times = calculate_file_access_time(sample_workflow_workspace_path)
    all_file_paths = list(Path(sample_workflow_workspace_path).rglob("*.*"))
    for file_path in all_file_paths:
        assert str(file_path) in access_times
Exemple #3
0
def test_calculate_hash_of_dir(sample_workflow_workspace):
    """Test calculate_hash_of_dir."""
    non_existing_dir_hash = calculate_hash_of_dir('a/b/c')
    assert non_existing_dir_hash == -1
    sample_workflow_workspace_path = next(sample_workflow_workspace('sample'))
    dir_hash = calculate_hash_of_dir(sample_workflow_workspace_path)
    assert dir_hash == '8d287a3e2240b1762862d485a424363c'
    include_only_path = os.path.join(sample_workflow_workspace_path, 'code',
                                     'worldpopulation.ipynb')
    hash_of_single_file = calculate_hash_of_dir(sample_workflow_workspace_path,
                                                [include_only_path])
    assert hash_of_single_file == '18ce945e21ab4db472525abe1e0f8080'
    empty_dir_hash = calculate_hash_of_dir(sample_workflow_workspace_path, [])
    md5_hash = md5()
    assert empty_dir_hash == md5_hash.hexdigest()
Exemple #4
0
def test_calculate_hash_of_dir(sample_workflow_workspace):
    """Test calculate_hash_of_dir."""
    non_existing_dir_hash = calculate_hash_of_dir("a/b/c")
    assert non_existing_dir_hash == -1
    sample_workflow_workspace_path = next(sample_workflow_workspace("sample"))
    dir_hash = calculate_hash_of_dir(sample_workflow_workspace_path)
    assert dir_hash == "8d287a3e2240b1762862d485a424363c"
    include_only_path = os.path.join(sample_workflow_workspace_path, "code",
                                     "worldpopulation.ipynb")
    hash_of_single_file = calculate_hash_of_dir(sample_workflow_workspace_path,
                                                [include_only_path])
    assert hash_of_single_file == "18ce945e21ab4db472525abe1e0f8080"
    empty_dir_hash = calculate_hash_of_dir(sample_workflow_workspace_path, [])
    md5_hash = md5()
    assert empty_dir_hash == md5_hash.hexdigest()
Exemple #5
0
def test_calculate_hash_of_dir(sample_workflow_workspace):  # noqa: F811
    """Test calculate_hash_of_dir."""
    non_existing_dir_hash = calculate_hash_of_dir("a/b/c")
    assert non_existing_dir_hash == -1

    test_workspace_path = pkg_resources.resource_filename(
        "pytest_reana", "test_workspace")
    sample_workflow_workspace_path = next(sample_workflow_workspace("sample"))
    shutil.rmtree(sample_workflow_workspace_path)
    shutil.copytree(test_workspace_path, sample_workflow_workspace_path)
    dir_hash = calculate_hash_of_dir(sample_workflow_workspace_path)
    assert dir_hash == "cb2669b4d7651aa717b6952fce85575f"
    include_only_path = os.path.join(sample_workflow_workspace_path, "code",
                                     "worldpopulation.ipynb")
    hash_of_single_file = calculate_hash_of_dir(sample_workflow_workspace_path,
                                                [include_only_path])
    assert hash_of_single_file == "18ce945e21ab4db472525abe1e0f8080"
    empty_dir_hash = calculate_hash_of_dir(sample_workflow_workspace_path, [])
    md5_hash = md5()
    assert empty_dir_hash == md5_hash.hexdigest()
    shutil.rmtree(sample_workflow_workspace_path)