예제 #1
0
def test_gcsuri_mtime(gcs_v6_txt):
    u = GCSURI(gcs_v6_txt + ".tmp")
    u.write("temp file for testing")
    now = time.time()
    assert now - 10 < u.mtime < now + 10
    u.rm()
    assert not u.exists
예제 #2
0
def test_gcsuri_write(gcs_test_path):
    u = GCSURI(gcs_test_path + "/test_gcsuri_write.tmp")

    assert not u.exists
    u.write("test")
    assert u.exists and u.read() == "test"
    u.rm()

    # this will be tested more with multiple threads in test_race_cond.py
    assert not u.exists
    u.write("test2", no_lock=True)
    assert u.exists and u.read() == "test2"
    u.rm()
    assert not u.exists
예제 #3
0
def test_gcsuri_rm(gcs_test_path):
    u = GCSURI(gcs_test_path + "/test_gcsuri_rm.tmp")

    assert not u.exists
    u.write("")
    assert u.exists
    u.rm()
    assert not u.exists

    # this will be tested more with multiple threads in test_race_cond.py
    assert not u.exists
    u.write("", no_lock=True)
    assert u.exists
    u.rm()
    assert not u.exists
예제 #4
0
def test_httpurl_md5_from_file(gcs_v6_txt_url, url_v6_txt, v6_txt_md5_hash):
    u_gcs_md5 = GCSURI(gcs_v6_txt_url + URIBase.MD5_FILE_EXT)
    if u_gcs_md5.exists:
        u_gcs_md5.rm()
    u_md5 = HTTPURL(url_v6_txt + URIBase.MD5_FILE_EXT)

    assert not u_gcs_md5.exists
    assert not u_md5.exists
    u = HTTPURL(url_v6_txt)
    assert u.md5_from_file is None

    u.get_metadata(make_md5_file=True)
    # HTTPURL should not make md5 file even with make_md5_file=True
    assert not u_md5.exists
    assert u.md5_from_file is None
예제 #5
0
def test_gcsuri_md5_from_file(gcs_v6_txt, v6_txt_md5_hash):
    u_md5 = GCSURI(gcs_v6_txt + URIBase.MD5_FILE_EXT)
    if u_md5.exists:
        u_md5.rm()
    assert not u_md5.exists
    u = GCSURI(gcs_v6_txt)
    assert u.md5_from_file is None

    u.get_metadata(make_md5_file=True)
    # GCSURI should not make md5 file even with make_md5_file=True
    assert not u_md5.exists
    assert u.md5_from_file is None

    # nevertheless AutoURI should be able to read from gs://*.md5
    # make a temporary .md5 file
    u_md5.write(v6_txt_md5_hash)
    assert u.md5_from_file == v6_txt_md5_hash
    u_md5.rm()
예제 #6
0
def test_gcsuri_get_metadata(gcs_v6_txt, v6_txt_size, v6_txt_md5_hash):
    u = GCSURI(gcs_v6_txt)

    m1 = u.get_metadata()
    assert m1.md5 == v6_txt_md5_hash
    assert m1.size == v6_txt_size

    m2 = u.get_metadata(skip_md5=True)
    assert m2.md5 is None
    assert m2.size == v6_txt_size

    u_md5 = GCSURI(gcs_v6_txt + ".md5")
    if u_md5.exists:
        u_md5.rm()
    m3 = u.get_metadata(make_md5_file=True)
    assert m3.md5 == v6_txt_md5_hash
    assert m3.size == v6_txt_size
    # GCSURI should not make md5 file even with make_md5_file=True
    assert not u_md5.exists
예제 #7
0
def test_httpurl_mtime(gcs_v6_txt, url_v6_txt):
    """Write on GCS bucket which is open to public.
    Access to that file via URL.

    For URLs hosted on GCS, "last-modified" key in the header doesn't seem to be
    accurate for the following cases:
        - After writing on an existing bucket item. GCS object has a correct "update" time
        but corresponding URL's "last-modified" still points to creation time.
    """
    return

    u = GCSURI(gcs_v6_txt + ".tmp")
    if u.exists:
        # if we don't delete it, "last-modified" will be inaccurate (pointing ot creation time).
        # see the above comments in this function's docstring.
        u.rm()
    u.write("temp file for testing")
    u_url = HTTPURL(url_v6_txt + ".tmp")
    now = time.time()
    assert now - 10 < u_url.mtime < now + 10
    u.rm()
    assert not u.exists