3 source("fakes/FakeHttpRequest.R")
4 source("fakes/FakeHttpParser.R")
6 test_that("Constructor will use environment variables if no parameters are passed to it", {
8 Sys.setenv(ARVADOS_API_HOST = "environment_api_host")
9 Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
13 Sys.unsetenv("ARVADOS_API_HOST")
14 Sys.unsetenv("ARVADOS_API_TOKEN")
16 expect_that("https://environment_api_host/arvados/v1/",
17 equals(arv$getHostName()))
19 expect_that("environment_api_token",
20 equals(arv$getToken()))
23 test_that("Constructor preferes constructor fields over environment variables", {
25 Sys.setenv(ARVADOS_API_HOST = "environment_api_host")
26 Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
28 arv <- Arvados$new("constructor_api_token", "constructor_api_host")
30 Sys.unsetenv("ARVADOS_API_HOST")
31 Sys.unsetenv("ARVADOS_API_TOKEN")
33 expect_that("https://constructor_api_host/arvados/v1/",
34 equals(arv$getHostName()))
36 expect_that("constructor_api_token",
37 equals(arv$getToken()))
40 test_that("Constructor raises exception if fields and environment variables are not provided", {
42 expect_that(Arvados$new(),
43 throws_error(paste0("Please provide host name and authentification token",
44 " or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
45 " environment variables.")))
48 test_that("getWebDavHostName calls REST service properly", {
50 hostName <- "hostName"
52 arv <- Arvados$new(token, hostName)
54 serverResponse <- list(keepWebServiceUrl = "https://myWebDavServer.com")
55 expectedURL <- paste0("https://", hostName,
56 "/discovery/v1/apis/arvados/v1/rest")
58 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
59 arv$setHttpClient(httpRequest)
60 arv$setHttpParser(FakeHttpParser$new())
62 webDAVHostName <- arv$getWebDavHostName()
64 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
65 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
66 expect_that(httpRequest$numberOfGETRequests, equals(1))
69 test_that("getWebDavHostName returns webDAV host name properly", {
71 arv <- Arvados$new("token", "hostName")
73 serverResponse <- list(keepWebServiceUrl = "https://myWebDavServer.com")
75 httpRequest <- FakeHttpRequest$new(expectedURL = NULL, serverResponse)
76 arv$setHttpClient(httpRequest)
77 arv$setHttpParser(FakeHttpParser$new())
79 expect_that("https://myWebDavServer.com", equals(arv$getWebDavHostName()))
82 test_that("getCollection calls REST service properly", {
84 arv <- Arvados$new("token", "hostName")
86 serverResponse <- NULL
87 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
88 expectedURL <- paste0(arv$getHostName(), "collections/", collectionUUID)
90 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
91 arv$setHttpClient(httpRequest)
92 arv$setHttpParser(FakeHttpParser$new())
94 arv$getCollection(collectionUUID)
96 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
97 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
98 expect_that(httpRequest$numberOfGETRequests, equals(1))
101 test_that("getCollection parses server response", {
103 arv <- Arvados$new("token", "hostName")
105 httpParser <- FakeHttpParser$new()
106 arv$setHttpParser(httpParser)
107 arv$setHttpClient(FakeHttpRequest$new())
109 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
110 arv$getCollection(collectionUUID)
112 expect_that(httpParser$parserCallCount, equals(1))
115 test_that("getCollection raises exception if response contains errors field", {
117 arv <- Arvados$new("token", "hostName")
119 serverResponse <- list(errors = 404)
120 arv$setHttpClient(FakeHttpRequest$new(NULL, serverResponse))
121 arv$setHttpParser(FakeHttpParser$new())
123 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
125 expect_that(arv$getCollection(collectionUUID),
129 test_that("listCollections calls REST service properly", {
131 arv <- Arvados$new("token", "hostName")
133 serverResponse <- NULL
134 expectedURL <- paste0(arv$getHostName(), "collections")
136 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
137 arv$setHttpClient(httpRequest)
138 arv$setHttpParser(FakeHttpParser$new())
140 arv$listCollections()
142 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
143 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
144 expect_that(httpRequest$numberOfGETRequests, equals(1))
147 test_that("listCollections parses server response", {
149 arv <- Arvados$new("token", "hostName")
151 httpParser <- FakeHttpParser$new()
152 arv$setHttpParser(httpParser)
153 arv$setHttpClient(FakeHttpRequest$new())
155 arv$listCollections()
157 expect_that(httpParser$parserCallCount, equals(1))
160 test_that("listCollections raises exception if response contains errors field", {
162 arv <- Arvados$new("token", "hostName")
164 serverResponse <- list(errors = 404)
166 arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
167 arv$setHttpParser(FakeHttpParser$new())
169 expect_that(arv$listCollections(),
173 test_that("listAllCollections always returns all collections from server", {
175 arv <- Arvados$new("token", "hostName")
178 serverResponse <- list(items_available = 8,
179 items = list("collection1",
188 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
189 httpParser <- FakeHttpParser$new()
191 httpRequest$serverMaxElementsPerRequest <- 3
193 arv$setHttpClient(httpRequest)
194 arv$setHttpParser(httpParser)
196 result <- arv$listAllCollections()
198 expect_that(length(result), equals(8))
199 expect_that(httpRequest$numberOfGETRequests, equals(3))
200 expect_that(httpParser$parserCallCount, equals(3))
203 test_that("deleteCollection calls REST service properly", {
205 arv <- Arvados$new("token", "hostName")
207 serverResponse <- NULL
208 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
209 expectedURL <- paste0(arv$getHostName(), "collections/", collectionUUID)
211 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
212 arv$setHttpClient(httpRequest)
213 arv$setHttpParser(FakeHttpParser$new())
215 arv$deleteCollection(collectionUUID)
217 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
218 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
219 expect_that(httpRequest$numberOfDELETERequests, equals(1))
222 test_that("deleteCollection parses server response", {
224 arv <- Arvados$new("token", "hostName")
226 httpParser <- FakeHttpParser$new()
227 arv$setHttpParser(httpParser)
228 arv$setHttpClient(FakeHttpRequest$new())
230 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
231 arv$deleteCollection(collectionUUID)
233 expect_that(httpParser$parserCallCount, equals(1))
236 test_that("deleteCollection raises exception if response contains errors field", {
238 arv <- Arvados$new("token", "hostName")
240 serverResponse <- list(errors = 404)
241 arv$setHttpClient(FakeHttpRequest$new(NULL, serverResponse))
242 arv$setHttpParser(FakeHttpParser$new())
244 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
246 expect_that(arv$deleteCollection(collectionUUID),
250 test_that("updateCollection calls REST service properly", {
252 arv <- Arvados$new("token", "hostName")
254 newCollectionContent <- list(newName = "Brand new shiny name")
255 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
256 expectedURL <- paste0(arv$getHostName(), "collections/", collectionUUID)
257 serverResponse <- NULL
259 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
260 arv$setHttpClient(httpRequest)
261 arv$setHttpParser(FakeHttpParser$new())
263 arv$updateCollection(collectionUUID, newCollectionContent)
265 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
266 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
267 expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
268 expect_that(httpRequest$numberOfPUTRequests, equals(1))
271 test_that("updateCollection parses server response", {
273 arv <- Arvados$new("token", "hostName")
275 httpParser <- FakeHttpParser$new()
276 arv$setHttpParser(httpParser)
277 arv$setHttpClient(FakeHttpRequest$new())
279 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
280 newCollectionContent <- list(newName = "Brand new shiny name")
282 arv$updateCollection(collectionUUID, newCollectionContent)
284 expect_that(httpParser$parserCallCount, equals(1))
287 test_that("updateCollection raises exception if response contains errors field", {
289 arv <- Arvados$new("token", "hostName")
292 serverResponse <- list(errors = 404)
293 arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
294 arv$setHttpParser(FakeHttpParser$new())
296 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
297 newCollectionContent <- list(newName = "Brand new shiny name")
299 expect_that(arv$updateCollection(collectionUUID, newCollectionContent),
303 test_that("createCollection calls REST service properly", {
305 arv <- Arvados$new("token", "hostName")
307 collectionContent <- list(name = "My favorite collection")
308 expectedURL <- paste0(arv$getHostName(), "collections")
309 serverResponse <- NULL
311 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
312 arv$setHttpClient(httpRequest)
313 arv$setHttpParser(FakeHttpParser$new())
315 arv$createCollection(collectionContent)
317 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
318 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
319 expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
320 expect_that(httpRequest$numberOfPOSTRequests, equals(1))
323 test_that("createCollection parses server response", {
325 arv <- Arvados$new("token", "hostName")
327 httpParser <- FakeHttpParser$new()
328 arv$setHttpParser(httpParser)
329 arv$setHttpClient(FakeHttpRequest$new())
331 collectionContent <- list(name = "My favorite collection")
333 arv$createCollection(collectionContent)
335 expect_that(httpParser$parserCallCount, equals(1))
338 test_that("createCollection raises exception if response contains errors field", {
340 arv <- Arvados$new("token", "hostName")
343 serverResponse <- list(errors = 404)
344 arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
345 arv$setHttpParser(FakeHttpParser$new())
347 collectionContent <- list(name = "My favorite collection")
349 expect_that(arv$createCollection(collectionContent),
353 test_that("getProject calls REST service properly", {
355 arv <- Arvados$new("token", "hostName")
357 serverResponse <- NULL
358 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
359 expectedURL <- paste0(arv$getHostName(), "groups/", projectUUID)
361 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
362 arv$setHttpClient(httpRequest)
363 arv$setHttpParser(FakeHttpParser$new())
365 arv$getProject(projectUUID)
367 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
368 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
369 expect_that(httpRequest$numberOfGETRequests, equals(1))
372 test_that("getProject parses server response", {
374 arv <- Arvados$new("token", "hostName")
376 httpParser <- FakeHttpParser$new()
377 arv$setHttpParser(httpParser)
378 arv$setHttpClient(FakeHttpRequest$new())
380 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
381 arv$getProject(projectUUID)
383 expect_that(httpParser$parserCallCount, equals(1))
386 test_that("getProject raises exception if response contains errors field", {
388 arv <- Arvados$new("token", "hostName")
390 serverResponse <- list(errors = 404)
391 arv$setHttpClient(FakeHttpRequest$new(NULL, serverResponse))
392 arv$setHttpParser(FakeHttpParser$new())
394 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
396 expect_that(arv$getProject(projectUUID),
400 test_that("createProject calls REST service properly", {
402 arv <- Arvados$new("token", "hostName")
404 projectContent <- list(name = "My favorite project")
405 expectedURL <- paste0(arv$getHostName(), "groups")
406 serverResponse <- NULL
408 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
409 arv$setHttpClient(httpRequest)
410 arv$setHttpParser(FakeHttpParser$new())
412 arv$createProject(projectContent)
414 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
415 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
416 expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
417 expect_that(httpRequest$numberOfPOSTRequests, equals(1))
420 test_that("createProject parses server response", {
422 arv <- Arvados$new("token", "hostName")
424 httpParser <- FakeHttpParser$new()
425 arv$setHttpParser(httpParser)
426 arv$setHttpClient(FakeHttpRequest$new())
428 projectContent <- list(name = "My favorite project")
430 arv$createProject(projectContent)
432 expect_that(httpParser$parserCallCount, equals(1))
435 test_that("createProject raises exception if response contains errors field", {
437 arv <- Arvados$new("token", "hostName")
440 serverResponse <- list(errors = 404)
441 arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
442 arv$setHttpParser(FakeHttpParser$new())
444 projectContent <- list(name = "My favorite project")
446 expect_that(arv$createProject(projectContent),
450 test_that("updateProject calls REST service properly", {
452 arv <- Arvados$new("token", "hostName")
454 newProjectContent <- list(newName = "Brand new shiny name")
455 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
456 expectedURL <- paste0(arv$getHostName(), "groups/", projectUUID)
457 serverResponse <- NULL
459 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
460 arv$setHttpClient(httpRequest)
461 arv$setHttpParser(FakeHttpParser$new())
463 arv$updateProject(projectUUID, newProjectContent)
465 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
466 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
467 expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
468 expect_that(httpRequest$numberOfPUTRequests, equals(1))
471 test_that("updateProject parses server response", {
473 arv <- Arvados$new("token", "hostName")
475 httpParser <- FakeHttpParser$new()
476 arv$setHttpParser(httpParser)
477 arv$setHttpClient(FakeHttpRequest$new())
479 newProjectContent <- list(newName = "Brand new shiny name")
480 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
482 arv$updateProject(projectUUID, newProjectContent)
484 expect_that(httpParser$parserCallCount, equals(1))
487 test_that("updateProject raises exception if response contains errors field", {
489 arv <- Arvados$new("token", "hostName")
492 serverResponse <- list(errors = 404)
493 arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
494 arv$setHttpParser(FakeHttpParser$new())
496 newProjectContent <- list(newName = "Brand new shiny name")
497 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
499 expect_that(arv$updateProject(projectUUID, newProjectContent),
503 test_that("listProjects calls REST service properly", {
505 arv <- Arvados$new("token", "hostName")
507 serverResponse <- NULL
508 expectedURL <- paste0(arv$getHostName(), "groups")
509 expectedFilters <- list(list("name" = "My project"),
510 list("group_class", "=", "project"))
512 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse, expectedFilters)
513 arv$setHttpClient(httpRequest)
514 arv$setHttpParser(FakeHttpParser$new())
516 arv$listProjects(list(list("name" = "My project")))
518 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
519 expect_that(httpRequest$queryFiltersAreCorrect, is_true())
520 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
521 expect_that(httpRequest$numberOfGETRequests, equals(1))
524 test_that("listProjects parses server response", {
526 arv <- Arvados$new("token", "hostName")
528 httpParser <- FakeHttpParser$new()
529 arv$setHttpParser(httpParser)
530 arv$setHttpClient(FakeHttpRequest$new())
534 expect_that(httpParser$parserCallCount, equals(1))
537 test_that("listProjects raises exception if response contains errors field", {
539 arv <- Arvados$new("token", "hostName")
541 serverResponse <- list(errors = 404)
543 arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
544 arv$setHttpParser(FakeHttpParser$new())
546 expect_that(arv$listProjects(),
550 test_that("listAllProjects always returns all projects from server", {
552 arv <- Arvados$new("token", "hostName")
555 serverResponse <- list(items_available = 8,
556 items = list("project1",
565 expectedFilters <- list(list("name" = "My project"),
566 list("group_class", "=", "project"))
568 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse, expectedFilters)
569 httpParser <- FakeHttpParser$new()
571 httpRequest$serverMaxElementsPerRequest <- 3
573 arv$setHttpClient(httpRequest)
574 arv$setHttpParser(httpParser)
576 result <- arv$listAllProjects(list(list("name" = "My project")))
578 expect_that(length(result), equals(8))
579 expect_that(httpRequest$queryFiltersAreCorrect, is_true())
580 expect_that(httpRequest$numberOfGETRequests, equals(3))
581 expect_that(httpParser$parserCallCount, equals(3))
584 test_that("deleteProject calls REST service properly", {
586 arv <- Arvados$new("token", "hostName")
588 serverResponse <- NULL
589 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
590 expectedURL <- paste0(arv$getHostName(), "groups/", projectUUID)
592 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
593 arv$setHttpClient(httpRequest)
594 arv$setHttpParser(FakeHttpParser$new())
596 arv$deleteProject(projectUUID)
598 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
599 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
600 expect_that(httpRequest$numberOfDELETERequests, equals(1))
603 test_that("deleteProject parses server response", {
605 arv <- Arvados$new("token", "hostName")
607 httpParser <- FakeHttpParser$new()
608 arv$setHttpParser(httpParser)
609 arv$setHttpClient(FakeHttpRequest$new())
611 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
612 arv$deleteProject(projectUUID)
614 expect_that(httpParser$parserCallCount, equals(1))
617 test_that("deleteCollection raises exception if response contains errors field", {
619 arv <- Arvados$new("token", "hostName")
621 serverResponse <- list(errors = 404)
623 arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
624 arv$setHttpParser(FakeHttpParser$new())
626 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
628 expect_that(arv$deleteProject(projectUUID),