|
| 1 | +context("File metadata retrieval, content retrieval and timestamp-updating works") |
| 2 | +token <- readRDS("token_file.rds") |
| 3 | +test_that("Retrieving metadata for a list of un-simplified files works", { |
| 4 | + files <- list_files(token, max_results = 1) |
| 5 | + expect_true(exists("files")) #It worked? |
| 6 | + expect_equal(length(files$items), 1) #It respected the "only get one" element. |
| 7 | + expect_true(is.list(files$items[[1]]$labels)) #It didn't simplify things. |
| 8 | +}) |
| 9 | + |
| 10 | +test_that("Retrieving metadata for a list of simplified files works", { |
| 11 | + files <- list_files(token, max_results = 1, simplify = TRUE) |
| 12 | + expect_true(exists("files")) #It worked? |
| 13 | + expect_equal(length(files$items), 1) #It respected the "only get one" element. |
| 14 | + expect_false(is.list(files$items[[1]]$labels)) #It DID simplify things. |
| 15 | +}) |
| 16 | + |
| 17 | +test_that("Retrieving metadata for a single un-simplified file works", { |
| 18 | + file_id <- list_files(token, max_results = 1)$items[[1]]$id #Get file_id |
| 19 | + file <- file_metadata(token, file_id = file_id, simplify = FALSE) #Retrieve actual file |
| 20 | + expect_true(exists("file")) #It worked? |
| 21 | + expect_true(is.list(file$labels)) #It didn't simplify things. |
| 22 | +}) |
| 23 | + |
| 24 | +test_that("Retrieving metadata for a single simplified file works", { |
| 25 | + file_id <- list_files(token, max_results = 1)$items[[1]]$id #Get file_id |
| 26 | + file <- file_metadata(token, file_id = file_id, simplify = TRUE) #Retrieve actual file |
| 27 | + expect_true(exists("file")) #It worked? |
| 28 | + expect_false(is.list(file$labels)) #It didn't simplify things. |
| 29 | +}) |
| 30 | + |
| 31 | +test_that("File copying works", { |
| 32 | + file <- list_files(token, max_results = 1)$items[[1]] #Get the original file |
| 33 | + copy_result <- copy_file(token, file_id = file$id) #Copy! |
| 34 | + expect_that(paste0("Copy of ",file$title), equals(copy_result$title)) #Expect the title is "Copy of $FOO" |
| 35 | + expect_that(file$mimeType, equals(copy_result$mimeType)) #Expect they have matching MIME types. Copies, right? |
| 36 | +}) |
| 37 | + |
| 38 | +test_that("File trashing works", { |
| 39 | + file_id <- list_files(token, max_results = 1)$items[[1]]$id #Get file_id |
| 40 | + trash_result <- trash_file(token, file_id) #Trash |
| 41 | + expect_true(trash_result) #It worked? |
| 42 | + is_trashed <- list_files(token, max_results = 1)$items[[1]]$labels$trashed #Get trashed status |
| 43 | + expect_true(is_trashed) #Which should be true. |
| 44 | +}) |
| 45 | + |
| 46 | +test_that("File untrashing works", { |
| 47 | + file_id <- list_files(token, max_results = 1)$items[[1]]$id #Get file_id |
| 48 | + untrash_result <- untrash_file(token, file_id) #Untrash |
| 49 | + expect_true(untrash_result) #Untrashing /claims/ to have worked? |
| 50 | + is_trashed <- list_files(token, max_results = 1)$items[[1]]$labels$trashed #Get trashed status |
| 51 | + expect_false(is_trashed) #Which should be false. |
| 52 | +}) |
| 53 | + |
| 54 | +test_that("Modifying the metadata of an existing file works",{ |
| 55 | + file <- list_files(token, max_results = 1)$items[[1]] #Get the most recent file. |
| 56 | + file$title <- "This isn't the greatest file in the wo-orld, no. This is a tribute." |
| 57 | + result <- update_file_metadata(token, file) |
| 58 | + expect_equal(result$title, "This isn't the greatest file in the wo-orld, no. This is a tribute.") |
| 59 | +}) |
| 60 | + |
| 61 | +test_that("File deletion works",{ |
| 62 | + file <- list_files(token, max_results = 1)$items[[1]]$id #Get the most recent fileID. |
| 63 | + result <- delete_file(token, file) #Of course, we just created it with "File copying works", so deleting it is fine. |
| 64 | + expect_true(result) |
| 65 | +}) |
| 66 | + |
| 67 | +test_that("File uploading works",{ |
| 68 | + file <- upload_file(token = token, file_path = system.file("test.jpeg", package = "driver"), title = "This is a test") |
| 69 | + expect_equal(file$title, "This is a test") |
| 70 | + expect_equal(file$mimeType, "image/jpeg") |
| 71 | + result <- delete_file(token, file$id) |
| 72 | + expect_true(result) |
| 73 | +}) |
| 74 | + |
0 commit comments