def test_should_be_able_to_delete_files(self, storage): file_name = "test_delete_file" upload_test_file(storage, file_name, "") storage.delete(file_name) # Should not raise an exception by google.cloud assert storage.delete("missing_file") is None
def test_should_work_with_utf8(self, storage): file_name = "test_utf8_file_陰陽" upload_test_file(storage, file_name, "") storage.exists(file_name) # Don't explode when trying to find a available name for existing files... upload_test_file(storage, file_name, "")
def test_changed_files_should_be_reuploaded(self, storage): file_name = "test_changed_file_reuploaded" file_content = "gcloud".encode("ascii") upload_test_file(storage, file_name, "") first_modified_time = storage.modified_time(file_name) local_tmpfile = storage.open(file_name) assert local_tmpfile.read() == "".encode("ascii") local_tmpfile.seek(0) local_tmpfile.write(file_content) local_tmpfile.close() assert storage.open(file_name).read() == file_content assert storage.modified_time(file_name) != first_modified_time
def test_should_be_able_to_list_dirs_and_files(self, storage): file_name = "test_listdir_file" subdir_file_pattern = "/subdir/%s.%d" for i in range(1, 11): upload_test_file(storage, subdir_file_pattern % (file_name, i), "") upload_test_file(storage, "/subdir/a/" + file_name, "") upload_test_file(storage, "/subdir/b/" + file_name, "") # Make sure paths prefixed with a slash are normalized assert storage.listdir("") == storage.listdir("/") assert storage.listdir("subdir") == storage.listdir("/subdir") subdir_list_dir = storage.listdir("subdir/") assert len(subdir_list_dir[0]) == 2 and len(subdir_list_dir[1]) == 10 assert subdir_list_dir[0] == ["a", "b"] assert subdir_list_dir[1][0] == "%s.%d" % (file_name, 1)
def test_file(storage): path = upload_test_file(storage, TEST_FILE_PATH, TEST_FILE_CONTENT) yield path storage.delete(path)
def test_correctly_detect_mimetype(self, storage): file_name = "test.jpg" upload_test_file(storage, file_name, "") assert "image/jpeg" == urlopen( storage.url(file_name)).info().get("Content-Type")
def test_should_not_overwrite_files_on_save(self, storage, test_file): duplicate_file = upload_test_file(storage, test_file, "") assert duplicate_file != test_file