Ejemplo n.º 1
0
def test_validate_download(cbcloud_api_mock, hashes):
    """Unit test _validate_download function."""
    cbcloud_api_mock.mock_request("POST", "/ubs/v1/orgs/test/file/_download",
                                  FILE_DOWNLOAD_RESP)
    hash_dl = _download_hashes(cbcloud_api_mock.api, hashes, 60)
    found_hashes, redownload_found_hashes = _validate_download(
        cbcloud_api_mock.api, hash_dl, 60)
    assert len(found_hashes) == 1
    assert redownload_found_hashes is None
Ejemplo n.º 2
0
def test_validate_download_not_found(cbapi_mock, hashes):
    """Unit test _validate_download function with hashes not in UBS."""
    with pytest.raises(Exception):
        cbapi_mock.mock_request("POST", "/ubs/v1/orgs/test/file/_download",
                                Exception)
        hash_dl = _download_hashes(cbapi_mock.api, hashes, 60)
        check_hash_dl, retry = _validate_download(cbapi_mock.api, hash_dl, 60)
        assert check_hash_dl is None
        assert retry is None
Ejemplo n.º 3
0
def test_download_binary_metadata_not_found(cbapi_mock, hashes):
    """Unit test _download_binary_metadata function with hashes not in UBS."""
    with pytest.raises(Exception):
        cbapi_mock.mock_request("POST", "/ubs/v1/orgs/test/file/_download",
                                Exception)  # put in the Exception
        hash_dl = _download_hashes(cbapi_mock.api, hashes, 60)
        assert hash_dl is None
        check_hash_dl, retry = _validate_download(cbapi_mock.api, hash_dl, 60)
        with pytest.raises(ValueError):
            try_meta = _download_binary_metadata(cbapi_mock.api, check_hash_dl)
            assert try_meta is None
        assert check_hash_dl is None
        assert retry is None
Ejemplo n.º 4
0
def test_download_binary_metadata(cbcloud_api_mock, hashes):
    """Unit test _download_binary_metadata function."""
    cbcloud_api_mock.mock_request("POST", "/ubs/v1/orgs/test/file/_download",
                                  FILE_DOWNLOAD_RESP)
    hash_dl = _download_hashes(cbcloud_api_mock.api, hashes, 60)
    found_hashes, redownload_found_hashes = _validate_download(
        cbcloud_api_mock.api, hash_dl, 60)
    cbcloud_api_mock.mock_request(
        "GET",
        f"/ubs/v1/orgs/test/sha256/{found_hashes[0]['sha256']}/metadata",
        METADATA_DOWNLOAD_RESP[found_hashes[0]['sha256']])
    metadata = _download_binary_metadata(cbcloud_api_mock.api, found_hashes[0])
    assert type(metadata) == dict
    for key in METADATA_VALID.keys():
        assert key in metadata
    for key in metadata.keys():
        assert key in METADATA_VALID
Ejemplo n.º 5
0
def test_validate_download_empty(cbcloud_api_mock):
    """Unit test _validate_download function with empty input."""
    assert _validate_download(cbcloud_api_mock.api, None, 60) == (None, None)