Skip to content
This repository was archived by the owner on May 10, 2023. It is now read-only.

Commit cc0fa40

Browse files
author
ironholds
committed
switch to testthat part 1
1 parent dff2544 commit cc0fa40

7 files changed

+99
-1
lines changed

.Rbuildignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
^\.Rproj\.user$
33
^\.httr-oauth$
44
^\.travis\.yml$
5-
manual_tests/*
5+
tests/testthat/token_file.rds.enc

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.Rhistory
33
.RData
44
.httr-oauth
5+
tests/testthat/token_file.rds

.travis.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: c
2+
before_install:
3+
- openssl aes-256-cbc -K $encrypted_5e6beae96b20_key -iv $encrypted_5e6beae96b20_iv
4+
-in tests/testthat/token_file.rds.enc -out tests/testthat/token_file.rds -d
5+
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh
6+
- chmod 755 ./travis-tool.sh
7+
- ./travis-tool.sh bootstrap
8+
install:
9+
- ./travis-tool.sh install_deps
10+
script: ./travis-tool.sh run_tests
11+
after_failure:
12+
- ./travis-tool.sh dump_logs
13+
env:
14+
- NOT_CRAN="true"
15+
- WARNINGS_ARE_ERRORS=1
16+
notifications:
17+
email:
18+
on_success: change
19+
on_failure: change

DESCRIPTION

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Description: A client library for the Google Drive API; download and upload file
1010
License: MIT + file LICENSE
1111
Depends: httr
1212
Imports: XML, stringi, rmarkdown
13+
Suggests: testthat

tests/testthat.R

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
library(testthat)
2+
library(driver)
3+
test_check("driver")

tests/testthat/test_files.R

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+

tests/testthat/token_file.rds.enc

1.67 KB
Binary file not shown.

0 commit comments

Comments
 (0)