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"
1
5
2
- test_that( " api() returns endpoints " , {
6
+ skip_cloud_tests <- function () {
3
7
skip_on_cran()
4
- skip_if_not_master()
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
+
20
+ test_that(" api() returns endpoints" , {
21
+ skip_cloud_tests()
5
22
6
23
res <- api()
7
24
expect_true(length(res ) > 1 )
8
25
expect_true(all(c(" plots" , " grids" , " folders" ) %in% names(res )))
9
26
})
10
27
11
28
test_that(" Can search with white-space" , {
12
- skip_on_cran()
13
- skip_if_not_master()
29
+ skip_cloud_tests()
14
30
15
31
res <- api(" search?q=overdose drugs" )
16
32
expect_true(length(res ) > 1 )
@@ -27,8 +43,7 @@ test_that("Changing a filename works", {
27
43
28
44
29
45
test_that(" Downloading plots works" , {
30
- skip_on_cran()
31
- skip_if_not_master()
46
+ skip_cloud_tests()
32
47
33
48
# https://plot.ly/~cpsievert/200
34
49
p <- api_download_plot(200 , " cpsievert" )
@@ -46,8 +61,7 @@ test_that("Downloading plots works", {
46
61
47
62
48
63
test_that(" Downloading grids works" , {
49
- skip_on_cran()
50
- skip_if_not_master()
64
+ skip_cloud_tests()
51
65
52
66
g <- api_download_grid(14681 , " cpsievert" )
53
67
expect_is(g , " api_file" )
@@ -63,8 +77,7 @@ test_that("Downloading grids works", {
63
77
64
78
65
79
test_that(" Creating produces a new file by default" , {
66
- skip_on_cran()
67
- skip_if_not_master()
80
+ skip_cloud_tests()
68
81
69
82
expect_new <- function (obj ) {
70
83
old <- api(" folders/home?user=cpsievert" )
@@ -87,8 +100,7 @@ test_that("Creating produces a new file by default", {
87
100
88
101
89
102
test_that(" Can overwrite a grid" , {
90
- skip_on_cran()
91
- skip_if_not_master()
103
+ skip_cloud_tests()
92
104
93
105
id <- new_id()
94
106
m <- api_create(mtcars , id )
@@ -98,8 +110,7 @@ test_that("Can overwrite a grid", {
98
110
})
99
111
100
112
test_that(" Can overwrite a plot" , {
101
- skip_on_cran()
102
- skip_if_not_master()
113
+ skip_cloud_tests()
103
114
104
115
id <- new_id()
105
116
p <- plot_ly()
@@ -110,8 +121,7 @@ test_that("Can overwrite a plot", {
110
121
})
111
122
112
123
test_that(" Can create plots with non-trivial src attributes" , {
113
- skip_on_cran()
114
- skip_if_not_master()
124
+ skip_cloud_tests()
115
125
116
126
expect_srcified <- function (x ) {
117
127
expect_length(strsplit(x , " :" )[[1 ]], 3 )
@@ -147,3 +157,20 @@ test_that("Can create plots with non-trivial src attributes", {
147
157
expect_not_srcified(res $ figure $ layout $ xaxis $ tickvalssrc )
148
158
149
159
})
160
+
161
+
162
+ test_that(" filename supports names with paths included " , {
163
+ skip_cloud_tests()
164
+
165
+ p <- plot_ly(mtcars , x = ~ wt , y = ~ vs )
166
+ filename <- " directory/awesome"
167
+ # trash the file if it already exists
168
+ file <- api_lookup_file(filename )
169
+ if (is.file(file )) {
170
+ endpt <- sprintf(" files/%s/trash" , file $ fid )
171
+ res <- api(endpt , " POST" )
172
+ }
173
+ f <- api_create(p , filename = filename )
174
+ expect_match(f $ filename , " awesome" )
175
+ expect_true(f $ parented )
176
+ })
0 commit comments