3 source("fakes/FakeRESTService.R")
5 test_that("Constructor will use environment variables if no parameters are passed to it", {
7 Sys.setenv(ARVADOS_API_HOST = "environment_api_host")
8 Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
12 Sys.unsetenv("ARVADOS_API_HOST")
13 Sys.unsetenv("ARVADOS_API_TOKEN")
15 expect_that("https://environment_api_host/arvados/v1/",
16 equals(arv$getHostName()))
18 expect_that("environment_api_token",
19 equals(arv$getToken()))
22 test_that("Constructor preferes constructor fields over environment variables", {
24 Sys.setenv(ARVADOS_API_HOST = "environment_api_host")
25 Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
27 arv <- Arvados$new("constructor_api_token", "constructor_api_host")
29 Sys.unsetenv("ARVADOS_API_HOST")
30 Sys.unsetenv("ARVADOS_API_TOKEN")
32 expect_that("https://constructor_api_host/arvados/v1/",
33 equals(arv$getHostName()))
35 expect_that("constructor_api_token",
36 equals(arv$getToken()))
39 test_that("Constructor raises exception if fields and environment variables are not provided", {
41 expect_that(Arvados$new(),
42 throws_error(paste0("Please provide host name and authentification token",
43 " or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
44 " environment variables.")))
47 test_that("getCollection delegates operation to RESTService class", {
49 arv <- Arvados$new("token", "hostName")
50 fakeREST <- FakeRESTService$new()
51 arv$setRESTService(fakeREST)
52 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
54 arv$getCollection(collectionUUID)
56 expect_that(fakeREST$getResourceCallCount, equals(1))
59 test_that("listCollections delegates operation to RESTService class", {
61 arv <- Arvados$new("token", "hostName")
62 fakeREST <- FakeRESTService$new()
63 arv$setRESTService(fakeREST)
67 expect_that(fakeREST$listResourcesCallCount, equals(1))
70 test_that("listCollections filter paramerter must be named 'collection'", {
72 filters <- list(list("name", "like", "MyCollection"))
73 names(filters) <- c("collection")
74 fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
75 arv <- Arvados$new("token", "hostName")
76 arv$setRESTService(fakeREST)
78 arv$listCollections(list(list("name", "like", "MyCollection")))
80 expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
83 test_that("listAllCollections delegates operation to RESTService class", {
85 arv <- Arvados$new("token", "hostName")
86 fakeREST <- FakeRESTService$new()
87 arv$setRESTService(fakeREST)
89 arv$listAllCollections()
91 expect_that(fakeREST$fetchAllItemsCallCount, equals(1))
94 test_that("listAllCollections filter paramerter must be named 'collection'", {
96 filters <- list(list("name", "like", "MyCollection"))
97 names(filters) <- c("collection")
98 fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
99 arv <- Arvados$new("token", "hostName")
100 arv$setRESTService(fakeREST)
102 arv$listAllCollections(list(list("name", "like", "MyCollection")))
104 expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
107 test_that("deleteCollection delegates operation to RESTService class", {
109 arv <- Arvados$new("token", "hostName")
110 fakeREST <- FakeRESTService$new()
111 arv$setRESTService(fakeREST)
112 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
114 arv$deleteCollection(collectionUUID)
116 expect_that(fakeREST$deleteResourceCallCount, equals(1))
119 test_that("updateCollection delegates operation to RESTService class", {
121 arv <- Arvados$new("token", "hostName")
122 fakeREST <- FakeRESTService$new()
123 arv$setRESTService(fakeREST)
124 newCollectionContent <- list(newName = "Brand new shiny name")
125 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
127 arv$updateCollection(collectionUUID, newCollectionContent)
129 expect_that(fakeREST$updateResourceCallCount, equals(1))
132 test_that("updateCollection adds content to request parameter named 'collection'", {
134 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
136 names(body) <- c("collection")
137 body$collection <- list(name = "MyCollection", desc = "No description")
138 fakeREST <- FakeRESTService$new(returnContent = body)
139 arv <- Arvados$new("token", "hostName")
140 arv$setRESTService(fakeREST)
142 arv$updateCollection(collectionUUID,
143 list(name = "MyCollection", desc = "No description"))
145 expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
148 test_that("createCollection delegates operation to RESTService class", {
150 arv <- Arvados$new("token", "hostName")
151 fakeREST <- FakeRESTService$new()
152 arv$setRESTService(fakeREST)
153 collectionContent <- list(newName = "Brand new shiny name")
155 arv$createCollection(collectionContent)
157 expect_that(fakeREST$createResourceCallCount, equals(1))
160 test_that("createCollection adds content to request parameter named 'collection'", {
163 names(body) <- c("collection")
164 body$collection <- list(name = "MyCollection", desc = "No description")
165 fakeREST <- FakeRESTService$new(returnContent = body)
166 arv <- Arvados$new("token", "hostName")
167 arv$setRESTService(fakeREST)
169 arv$createCollection(list(name = "MyCollection", desc = "No description"))
171 expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
174 test_that("getProject delegates operation to RESTService class", {
176 arv <- Arvados$new("token", "hostName")
177 fakeREST <- FakeRESTService$new()
178 arv$setRESTService(fakeREST)
179 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
181 arv$getCollection(projectUUID)
183 expect_that(fakeREST$getResourceCallCount, equals(1))
186 test_that("listProjects delegates operation to RESTService class", {
188 arv <- Arvados$new("token", "hostName")
189 fakeREST <- FakeRESTService$new()
190 arv$setRESTService(fakeREST)
192 arv$listCollections()
194 expect_that(fakeREST$listResourcesCallCount, equals(1))
197 test_that("listProjects filter contains additional 'group_class' field by default", {
199 filters <- list(list("name", "like", "MyProject"))
200 names(filters) <- c("groups")
201 filters[[length(filters) + 1]] <- list("group_class", "=", "project")
203 fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
204 arv <- Arvados$new("token", "hostName")
205 arv$setRESTService(fakeREST)
207 arv$listProjects(list(list("name", "like", "MyProject")))
209 expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
212 test_that("listAllProjects delegates operation to RESTService class", {
214 arv <- Arvados$new("token", "hostName")
215 fakeREST <- FakeRESTService$new()
216 arv$setRESTService(fakeREST)
218 arv$listAllProjects()
220 expect_that(fakeREST$fetchAllItemsCallCount, equals(1))
223 test_that("listAllProjects filter contains additional 'group_class' field by default", {
225 filters <- list(list("name", "like", "MyProject"))
226 names(filters) <- c("groups")
227 filters[[length(filters) + 1]] <- list("group_class", "=", "project")
229 fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
230 arv <- Arvados$new("token", "hostName")
231 arv$setRESTService(fakeREST)
233 arv$listAllProjects(list(list("name", "like", "MyProject")))
235 expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
238 test_that("deleteProject delegates operation to RESTService class", {
240 arv <- Arvados$new("token", "hostName")
241 fakeREST <- FakeRESTService$new()
242 arv$setRESTService(fakeREST)
243 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
245 arv$deleteCollection(projectUUID)
247 expect_that(fakeREST$deleteResourceCallCount, equals(1))
250 test_that("updateProject delegates operation to RESTService class", {
252 arv <- Arvados$new("token", "hostName")
253 fakeREST <- FakeRESTService$new()
254 arv$setRESTService(fakeREST)
255 newProjectContent <- list(newName = "Brand new shiny name")
256 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
258 arv$updateCollection(projectUUID, newProjectContent)
260 expect_that(fakeREST$updateResourceCallCount, equals(1))
263 test_that("updateProject adds content to request parameter named 'group'", {
265 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
267 names(body) <- c("group")
268 body$group <- list(name = "MyProject", desc = "No description")
270 fakeREST <- FakeRESTService$new(returnContent = body)
271 arv <- Arvados$new("token", "hostName")
272 arv$setRESTService(fakeREST)
274 arv$updateProject(projectUUID,
275 list(name = "MyProject", desc = "No description"))
277 expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
280 test_that("createProject delegates operation to RESTService class", {
282 arv <- Arvados$new("token", "hostName")
283 fakeREST <- FakeRESTService$new()
284 arv$setRESTService(fakeREST)
285 projectContent <- list(newName = "Brand new shiny name")
287 arv$createCollection(projectContent)
289 expect_that(fakeREST$createResourceCallCount, equals(1))
292 test_that("createProject request body contains 'goup_class' filed", {
295 names(body) <- c("group")
296 body$group <- c("group_class" = "project",
297 list(name = "MyProject", desc = "No description"))
299 fakeREST <- FakeRESTService$new(returnContent = body)
300 arv <- Arvados$new("token", "hostName")
301 arv$setRESTService(fakeREST)
303 arv$createProject(list(name = "MyProject", desc = "No description"))
305 expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())