Skip to content

Commit ae6b073

Browse files
committed
add skip_on_pull_request()
1 parent 56230e4 commit ae6b073

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

tests/testthat.R

+11
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ if (report_diffs || build_table) {
5757
}
5858
}
5959

60+
# Some tests make plot.ly HTTP requests and require a valid user account
61+
# (see test-plotly-filename.R). For security reasons, these tests should be
62+
# skipped on pull requests (the .travis.yml file uses encrypted credentials
63+
# & encrypted environment vars cannot be accessed on pull request builds)
64+
skip_on_pull_request <- function() {
65+
if (!grepl("^[0-9]+$", Sys.getenv("TRAVIS_PULL_REQUEST"))) {
66+
return(invisible(TRUE))
67+
}
68+
skip("Can't test plot.ly API calls on a pull request")
69+
}
70+
6071
# This function is called within testthat/test-*.R files.
6172
# It takes a ggplot or plotly object as input, and it returns a figure
6273
# object (aka the data behind the plot).

tests/testthat/test-plotly-filename.R

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ context("Filename")
22

33
test_that("filepath with directories is returned as passed", {
44
skip_on_cran()
5+
skip_on_pull_request()
56
p <- plot_ly(mtcars, x = wt, y = vs)
67
f <- plotly_POST(p, filename = "directory/awesome")
78
expect_match(f$filename, "directory/awesome")

tests/testthat/test-plotly-getfigure.R

+6
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,31 @@ context("get_figure")
22

33
test_that("requests made by a user who doesn't exist error a 404", {
44
skip_on_cran()
5+
skip_on_pull_request()
56
expect_error({
67
get_figure("klmadslfjdfljdsf", 0)
78
}, ".*404.*")
89
})
910

1011
test_that("requests made to retrieve a figure that doesn't exist returns a 404", {
1112
skip_on_cran()
13+
skip_on_pull_request()
1214
expect_error({
1315
get_figure("get_test_user", 18324823)
1416
}, ".*404.*")
1517
})
1618

1719
test_that("requests made to retrieve some elses private file errors a 403", {
1820
skip_on_cran()
21+
skip_on_pull_request()
1922
expect_error({
2023
get_figure("get_test_user", 1)
2124
}, ".*403.*")
2225
})
2326

2427
test_that("retrieving a public figure ... works.", {
2528
skip_on_cran()
29+
skip_on_pull_request()
2630
fig <- get_figure("get_test_user", 0)
2731
# get the data behind the hash
2832
p <- plotly_build(fig)
@@ -31,6 +35,7 @@ test_that("retrieving a public figure ... works.", {
3135

3236
test_that("can add traces to a subplot figure", {
3337
skip_on_cran()
38+
skip_on_pull_request()
3439
fig <- get_figure('chelsea_lyn', 6366)
3540
p <- add_trace(fig, x=c(1, 2, 3), y=c(4, 2, 4))
3641
l <- plotly_build(p)
@@ -39,6 +44,7 @@ test_that("can add traces to a subplot figure", {
3944

4045
test_that("posting a hidden plot returns a secret key", {
4146
skip_on_cran()
47+
skip_on_pull_request()
4248
res <- plotly_POST(plot_ly(), sharing = "secret")
4349
key <- strsplit(res$url, "=")[[1]][2]
4450
expect_true(nchar(key) > 1)

0 commit comments

Comments
 (0)