Skip to content

Commit db48488

Browse files
committed
finish migrating cloud skip logic
1 parent f6e2b5c commit db48488

File tree

3 files changed

+70
-83
lines changed

3 files changed

+70
-83
lines changed

tests/testthat/helper-skip.R

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
# Some tests make plot.ly HTTP requests and require a valid user account
2-
# (see test-plotly-filename.R). For security reasons, these tests should be
3-
# skipped on pull requests (the .travis.yml file uses encrypted credentials
4-
# & encrypted environment vars cannot be accessed on pull request builds)
5-
skip_if_not_master <- function() {
1+
r_version <- paste(R.version$major, R.version$minor, sep = ".")
2+
r_release <- rversions::r_release()$version
3+
is_release <- isTRUE(r_release == r_version)
4+
is_win <- .Platform$OS.type == "windows"
5+
6+
skip_cloud_tests <- function() {
7+
skip_on_cran()
68
if (is.na(Sys.getenv("plotly_username", NA))) {
7-
return(skip("Testing plot.ly API calls requires a plotly account"))
9+
skip("Cloud testing requires a plotly account (plotly_username)")
10+
}
11+
if (is.na(Sys.getenv("plotly_api_key", NA))) {
12+
skip("Cloud testing requires a plotly account (plotly_api_key)")
13+
}
14+
if (!is_release || !is_win) {
15+
skip("Cloud testing is only run on Windows with the current release of R")
816
}
9-
is_pr <- grepl("^[0-9]+$", Sys.getenv("TRAVIS_PULL_REQUEST"))
10-
is_r_release <- Sys.getenv("TRAVIS_R_VERSION_STRING", "release") == "release"
11-
if (!is_pr && is_r_release) return(invisible(TRUE))
12-
skip("plot.ly API calls are only tested on the master build on r-release")
1317
}

tests/testthat/test-api.R

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
r_version <- paste(R.version$major, R.version$minor, sep = ".")
2-
r_release <- rversions::r_release()$version
3-
is_release <- isTRUE(r_release == r_version)
4-
is_win <- .Platform$OS.type == "windows"
5-
6-
skip_cloud_tests <- function() {
7-
skip_on_cran()
8-
if (is.na(Sys.getenv("plotly_username", NA))) {
9-
skip("Cloud testing requires a plotly account (plotly_username)")
10-
}
11-
if (is.na(Sys.getenv("plotly_api_key", NA))) {
12-
skip("Cloud testing requires a plotly account (plotly_api_key)")
13-
}
14-
if (!is_release || !is_win) {
15-
skip("Cloud testing is only run on Windows with the current release of R")
16-
}
17-
}
18-
19-
201
test_that("api() returns endpoints", {
212
skip_cloud_tests()
223

@@ -33,8 +14,7 @@ test_that("Can search with white-space", {
3314
})
3415

3516
test_that("Changing a filename works", {
36-
skip_on_cran()
37-
skip_if_not_master()
17+
skip_cloud_tests()
3818

3919
id <- plotly:::new_id()
4020
f <- api("files/cpsievert:14680", "PATCH", list(filename = id))
@@ -174,3 +154,58 @@ test_that("filename supports names with paths included ", {
174154
expect_match(f$filename, "awesome")
175155
expect_true(f$parented)
176156
})
157+
158+
159+
160+
161+
test_that("requests made by a user who doesn't exist error a 404", {
162+
skip_cloud_tests()
163+
164+
expect_error({
165+
get_figure("klmadslfjdfljdsf", 0)
166+
}, ".*404.*")
167+
})
168+
169+
test_that("requests made to retrieve a figure that doesn't exist returns a 404", {
170+
skip_cloud_tests()
171+
172+
expect_error({
173+
get_figure("get_test_user", 18324823)
174+
}, ".*404.*")
175+
})
176+
177+
test_that("requests made to retrieve some elses private file errors", {
178+
skip_cloud_tests()
179+
180+
expect_error(get_figure("get_test_user", 1))
181+
})
182+
183+
test_that("retrieving a public figure ... works.", {
184+
skip_cloud_tests()
185+
186+
fig <- get_figure("get_test_user", 0)
187+
# get the data behind the hash
188+
p <- plotly_build(fig)$x
189+
expect_equivalent(p$data[[1]]$x, c("1", "2", "3"))
190+
})
191+
192+
test_that("can add traces to a subplot figure", {
193+
skip_cloud_tests()
194+
195+
fig <- get_figure('chelsea_lyn', 6366)
196+
p <- add_lines(fig, x = c(1, 2, 3), y = c(4, 2, 4))
197+
expect_equivalent(
198+
length(plotly_build(fig)$x$data) + 1,
199+
length(plotly_build(p)$x$data)
200+
)
201+
})
202+
203+
test_that("posting a hidden plot returns a secret key", {
204+
skip_cloud_tests()
205+
206+
res <- api_create(plot_ly(), sharing = "secret")
207+
expect_true(res$share_key_enabled)
208+
expect_true(nchar(res$share_key) > 1)
209+
})
210+
211+

tests/testthat/test-plotly-getfigure.R

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)