Beispiel #1
0
def test_s3uri_get_presigned_url(s3_v6_txt):
    u = S3URI(s3_v6_txt)
    # 2 seconds duration
    url = u.get_presigned_url(duration=2)

    u_url = HTTPURL(url)
    assert u_url.is_valid and u_url.read() == v6_txt_contents()
    time.sleep(5)
    # should expire in 2 seconds
    with pytest.raises(HTTPError):
        # forbidden since it's already expired
        u_url.read()
Beispiel #2
0
def test_gcsuri_get_presigned_url(gcs_v6_txt, gcp_private_key_file):
    u = GCSURI(gcs_v6_txt)
    # 2 seconds duration
    url = u.get_presigned_url(duration=2,
                              private_key_file=gcp_private_key_file)

    u_url = HTTPURL(url)
    assert u_url.is_valid and u_url.read() == v6_txt_contents()
Beispiel #3
0
def test_gcsuri_get_public_url(gcs_v6_txt):
    url = GCSURI(gcs_v6_txt).get_public_url()
    u_url = HTTPURL(url)
    assert u_url.is_valid and u_url.read() == v6_txt_contents()
Beispiel #4
0
def test_s3uri_get_public_url(s3_public_url_test_v6_file):
    url = S3URI(s3_public_url_test_v6_file).get_public_url()
    u_url = HTTPURL(url)
    assert u_url.is_valid
    assert u_url.read() == v6_txt_contents()
Beispiel #5
0
def test_httpurl_read(url_v6_txt):
    u = HTTPURL(url_v6_txt)
    assert u.read() == v6_txt_contents()
    assert u.read(byte=True) == v6_txt_contents().encode()
Beispiel #6
0
def test_httpurl_cp(url_v6_txt, local_test_path, s3_test_path,
                    gcs_test_path) -> "AutoURI":
    """Test copying local_v6_txt to the following destination storages:
        local_test_path: url -> local
        s3_test_path: url -> s3
        gcs_test_path: url -> gcs

    Parameters to be tested:
        no_lock:
            Copy with no locking mechanism. There is no way to test this thoroughly here.
            This will be tested with multiple threads later in test_rece_cond.py.
        no_checksum:
            Don't check md5-hash/size/mtime to skip copying (even if file already exists on destination).
        make_md5_file:
            Make md5 file on destination only when it's REQUIRED.
            It's required only if we need to compare md5 hash of source and target.
    """
    u = HTTPURL(url_v6_txt)
    basename = os.path.basename(url_v6_txt)

    for test_path in (local_test_path, s3_test_path, gcs_test_path):
        u_dest = AutoURI(os.path.join(test_path, "test_httpurl_cp", basename))
        if u_dest.exists:
            u_dest.rm()

        assert not u_dest.exists
        _, ret = u.cp(u_dest, return_flag=True)
        assert u_dest.exists and u.read() == u_dest.read() and ret == 0
        u_dest.rm()

        assert not u_dest.exists
        # cp without lock will be tested throughly in test_race_cond.py
        _, ret = u.cp(u_dest, no_lock=True, return_flag=True)
        assert u_dest.exists and u.read() == u_dest.read() and ret == 0
        u_dest.rm()

        # trivial: copy without checksum when target doesn't exists
        assert not u_dest.exists
        _, ret = u.cp(u_dest, no_checksum=True, return_flag=True)
        assert u_dest.exists and u.read() == u_dest.read() and ret == 0

        # copy without checksum when target exists
        m_dest = u_dest.get_metadata()
        assert m_dest.exists
        time.sleep(1)
        _, ret = u.cp(u_dest, no_checksum=True, return_flag=True)
        # compare new mtime vs old mtime
        # new time should be larger if it's overwritten as intended
        assert u_dest.mtime > m_dest.mtime and u.read() == u_dest.read(
        ) and ret == 0

        # copy with checksum when target exists
        m_dest = u_dest.get_metadata()
        assert m_dest.exists
        _, ret = u.cp(u_dest, return_flag=True)
        # compare new mtime vs old mtime
        # new time should be the same as old time
        assert u_dest.mtime == m_dest.mtime and u.read() == u_dest.read(
        ) and ret == 1

        # make_md5_file works only when it's required
        # i.e. when we need to compare md5 hash of src vs target
        # so target must exist prior to test it
        assert u_dest.exists
        # delete md5 file if exists
        u_dest_md5_file = AutoURI(u_dest.uri + URIBase.MD5_FILE_EXT)
        if u_dest_md5_file.exists:
            u_dest_md5_file.rm()
        _, ret = u.cp(u_dest, make_md5_file=True, return_flag=True)
        assert u_dest.exists and u.read() == u_dest.read() and ret == 1
        u_dest.rm()