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 " environmental 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("deleteCollection calls REST service properly", {
175 arv <- Arvados$new("token", "hostName")
177 serverResponse <- NULL
178 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
179 expectedURL <- paste0(arv$getHostName(), "collections/", collectionUUID)
181 httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
182 arv$setHttpClient(httpRequest)
183 arv$setHttpParser(FakeHttpParser$new())
185 arv$deleteCollection(collectionUUID)
187 expect_that(httpRequest$URLIsProperlyConfigured, is_true())
188 expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
189 expect_that(httpRequest$numberOfDELETERequests, equals(1))
192 test_that("deleteCollection parses server response", {
194 arv <- Arvados$new("token", "hostName")
196 httpParser <- FakeHttpParser$new()
197 arv$setHttpParser(httpParser)
198 arv$setHttpClient(FakeHttpRequest$new())
200 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
201 arv$deleteCollection(collectionUUID)
203 expect_that(httpParser$parserCallCount, equals(1))
206 test_that("getCollection raises exception if response contains errors field", {
208 arv <- Arvados$new("token", "hostName")
210 serverResponse <- list(errors = 404)
211 arv$setHttpClient(FakeHttpRequest$new(NULL, serverResponse))
212 arv$setHttpParser(FakeHttpParser$new())
214 collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
216 expect_that(arv$deleteCollection(collectionUUID),