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("listCollection 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("listAllCollection delegates operation to RESTService class", {
72 arv <- Arvados$new("token", "hostName")
73 fakeREST <- FakeRESTService$new()
74 arv$setRESTService(fakeREST)
76 arv$listAllCollections()
78 expect_that(fakeREST$fetchAllItemsCallCount, equals(1))
81 test_that("deleteCollection delegates operation to RESTService class", {
83 arv <- Arvados$new("token", "hostName")
84 fakeREST <- FakeRESTService$new()
85 arv$setRESTService(fakeREST)
86 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
88 arv$deleteCollection(collectionUUID)
90 expect_that(fakeREST$deleteResourceCallCount, equals(1))
93 test_that("updateCollection delegates operation to RESTService class", {
95 arv <- Arvados$new("token", "hostName")
96 fakeREST <- FakeRESTService$new()
97 arv$setRESTService(fakeREST)
98 newCollectionContent <- list(newName = "Brand new shiny name")
99 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
101 arv$updateCollection(collectionUUID, newCollectionContent)
103 expect_that(fakeREST$updateResourceCallCount, equals(1))
106 test_that("createCollection delegates operation to RESTService class", {
108 arv <- Arvados$new("token", "hostName")
109 fakeREST <- FakeRESTService$new()
110 arv$setRESTService(fakeREST)
111 collectionContent <- list(newName = "Brand new shiny name")
113 arv$createCollection(collectionContent)
115 expect_that(fakeREST$createResourceCallCount, equals(1))
118 test_that("getProject delegates operation to RESTService class", {
120 arv <- Arvados$new("token", "hostName")
121 fakeREST <- FakeRESTService$new()
122 arv$setRESTService(fakeREST)
123 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
125 arv$getCollection(projectUUID)
127 expect_that(fakeREST$getResourceCallCount, equals(1))
130 test_that("listProjects delegates operation to RESTService class", {
132 arv <- Arvados$new("token", "hostName")
133 fakeREST <- FakeRESTService$new()
134 arv$setRESTService(fakeREST)
136 arv$listCollections()
138 expect_that(fakeREST$listResourcesCallCount, equals(1))
141 test_that("listAllProjects delegates operation to RESTService class", {
143 arv <- Arvados$new("token", "hostName")
144 fakeREST <- FakeRESTService$new()
145 arv$setRESTService(fakeREST)
147 arv$listAllProjects()
149 expect_that(fakeREST$fetchAllItemsCallCount, equals(1))
152 test_that("deleteProject delegates operation to RESTService class", {
154 arv <- Arvados$new("token", "hostName")
155 fakeREST <- FakeRESTService$new()
156 arv$setRESTService(fakeREST)
157 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
159 arv$deleteCollection(projectUUID)
161 expect_that(fakeREST$deleteResourceCallCount, equals(1))
164 test_that("updateProject delegates operation to RESTService class", {
166 arv <- Arvados$new("token", "hostName")
167 fakeREST <- FakeRESTService$new()
168 arv$setRESTService(fakeREST)
169 newProjectContent <- list(newName = "Brand new shiny name")
170 projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
172 arv$updateCollection(projectUUID, newProjectContent)
174 expect_that(fakeREST$updateResourceCallCount, equals(1))
177 test_that("createProject delegates operation to RESTService class", {
179 arv <- Arvados$new("token", "hostName")
180 fakeREST <- FakeRESTService$new()
181 arv$setRESTService(fakeREST)
182 projectContent <- list(newName = "Brand new shiny name")
184 arv$createCollection(projectContent)
186 expect_that(fakeREST$createResourceCallCount, equals(1))