Exemple #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
Exemple #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
Exemple #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
Exemple #4
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()
Exemple #5
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