context("Arvados API")
-source("fakes/FakeHttpRequest.R")
-source("fakes/FakeHttpParser.R")
+source("fakes/FakeRESTService.R")
test_that("Constructor will use environment variables if no parameters are passed to it", {
expect_that(Arvados$new(),
throws_error(paste0("Please provide host name and authentification token",
" or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
- " environmental variables.")))
+ " environment variables.")))
})
-test_that("getWebDavHostName calls REST service properly", {
-
- hostName <- "hostName"
- token <- "token"
- arv <- Arvados$new(token, hostName)
-
- serverResponse <- list(keepWebServiceUrl = "https://myWebDavServer.com")
- expectedURL <- paste0("https://", hostName,
- "/discovery/v1/apis/arvados/v1/rest")
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
-
- webDAVHostName <- arv$getWebDavHostName()
-
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$numberOfGETRequests, equals(1))
-})
-
-test_that("getWebDavHostName returns webDAV host name properly", {
-
- arv <- Arvados$new("token", "hostName")
-
- serverResponse <- list(keepWebServiceUrl = "https://myWebDavServer.com")
-
- httpRequest <- FakeHttpRequest$new(expectedURL = NULL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
-
- expect_that("https://myWebDavServer.com", equals(arv$getWebDavHostName()))
-})
-
-test_that("getCollection calls REST service properly", {
+test_that("getCollection delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
-
- serverResponse <- NULL
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- expectedURL <- paste0(arv$getHostName(), "collections/", collectionUUID)
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
arv$getCollection(collectionUUID)
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$numberOfGETRequests, equals(1))
+ expect_that(fakeREST$getResourceCallCount, equals(1))
})
-test_that("getCollection parses server response", {
+test_that("listCollections delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
-
- httpParser <- FakeHttpParser$new()
- arv$setHttpParser(httpParser)
- arv$setHttpClient(FakeHttpRequest$new())
-
- collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- arv$getCollection(collectionUUID)
-
- expect_that(httpParser$parserCallCount, equals(1))
-})
-
-test_that("getCollection raises exception if response contains errors field", {
-
- arv <- Arvados$new("token", "hostName")
-
- serverResponse <- list(errors = 404)
- arv$setHttpClient(FakeHttpRequest$new(NULL, serverResponse))
- arv$setHttpParser(FakeHttpParser$new())
-
- collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- expect_that(arv$getCollection(collectionUUID),
- throws_error(404))
-})
-
-test_that("listCollections calls REST service properly", {
-
- arv <- Arvados$new("token", "hostName")
-
- serverResponse <- NULL
- expectedURL <- paste0(arv$getHostName(), "collections")
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
arv$listCollections()
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$numberOfGETRequests, equals(1))
+ expect_that(fakeREST$listResourcesCallCount, equals(1))
})
-test_that("listCollections parses server response", {
+test_that("listCollections filter paramerter must be named 'collection'", {
+ filters <- list(list("name", "like", "MyCollection"))
+ names(filters) <- c("collection")
+ fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
arv <- Arvados$new("token", "hostName")
+ arv$setRESTService(fakeREST)
- httpParser <- FakeHttpParser$new()
- arv$setHttpParser(httpParser)
- arv$setHttpClient(FakeHttpRequest$new())
-
- arv$listCollections()
+ arv$listCollections(list(list("name", "like", "MyCollection")))
- expect_that(httpParser$parserCallCount, equals(1))
+ expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
})
-test_that("listCollections raises exception if response contains errors field", {
+test_that("listAllCollections delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
-
- serverResponse <- list(errors = 404)
- expectedURL <- NULL
- arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
- arv$setHttpParser(FakeHttpParser$new())
-
- expect_that(arv$listCollections(),
- throws_error(404))
-})
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
-test_that("listAllCollections always returns all collections from server", {
+ arv$listAllCollections()
- arv <- Arvados$new("token", "hostName")
-
- expectedURL <- NULL
- serverResponse <- list(items_available = 8,
- items = list("collection1",
- "collection2",
- "collection3",
- "collection4",
- "collection5",
- "collection6",
- "collection7",
- "collection8"))
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- httpParser <- FakeHttpParser$new()
-
- httpRequest$serverMaxElementsPerRequest <- 3
-
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(httpParser)
-
- result <- arv$listAllCollections()
-
- expect_that(length(result), equals(8))
- expect_that(httpRequest$numberOfGETRequests, equals(3))
- expect_that(httpParser$parserCallCount, equals(3))
+ expect_that(fakeREST$fetchAllItemsCallCount, equals(1))
})
-test_that("deleteCollection calls REST service properly", {
+test_that("listAllCollections filter paramerter must be named 'collection'", {
+ filters <- list(list("name", "like", "MyCollection"))
+ names(filters) <- c("collection")
+ fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
arv <- Arvados$new("token", "hostName")
+ arv$setRESTService(fakeREST)
- serverResponse <- NULL
- collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- expectedURL <- paste0(arv$getHostName(), "collections/", collectionUUID)
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
-
- arv$deleteCollection(collectionUUID)
+ arv$listAllCollections(list(list("name", "like", "MyCollection")))
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$numberOfDELETERequests, equals(1))
+ expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
})
-test_that("deleteCollection parses server response", {
+test_that("deleteCollection delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
-
- httpParser <- FakeHttpParser$new()
- arv$setHttpParser(httpParser)
- arv$setHttpClient(FakeHttpRequest$new())
-
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- arv$deleteCollection(collectionUUID)
- expect_that(httpParser$parserCallCount, equals(1))
-})
-
-test_that("deleteCollection raises exception if response contains errors field", {
-
- arv <- Arvados$new("token", "hostName")
-
- serverResponse <- list(errors = 404)
- arv$setHttpClient(FakeHttpRequest$new(NULL, serverResponse))
- arv$setHttpParser(FakeHttpParser$new())
+ arv$deleteCollection(collectionUUID)
- collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- expect_that(arv$deleteCollection(collectionUUID),
- throws_error(404))
+ expect_that(fakeREST$deleteResourceCallCount, equals(1))
})
-test_that("updateCollection calls REST service properly", {
+test_that("updateCollection delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
-
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
newCollectionContent <- list(newName = "Brand new shiny name")
collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- expectedURL <- paste0(arv$getHostName(), "collections/", collectionUUID)
- serverResponse <- NULL
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
arv$updateCollection(collectionUUID, newCollectionContent)
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
- expect_that(httpRequest$numberOfPUTRequests, equals(1))
+ expect_that(fakeREST$updateResourceCallCount, equals(1))
})
-test_that("updateCollection parses server response", {
-
- arv <- Arvados$new("token", "hostName")
-
- httpParser <- FakeHttpParser$new()
- arv$setHttpParser(httpParser)
- arv$setHttpClient(FakeHttpRequest$new())
+test_that("updateCollection adds content to request parameter named 'collection'", {
collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- newCollectionContent <- list(newName = "Brand new shiny name")
-
- arv$updateCollection(collectionUUID, newCollectionContent)
-
- expect_that(httpParser$parserCallCount, equals(1))
-})
-
-test_that("updateCollection raises exception if response contains errors field", {
-
+ body <- list(list())
+ names(body) <- c("collection")
+ body$collection <- list(name = "MyCollection", desc = "No description")
+ fakeREST <- FakeRESTService$new(returnContent = body)
arv <- Arvados$new("token", "hostName")
-
- expectedURL <- NULL
- serverResponse <- list(errors = 404)
- arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
- arv$setHttpParser(FakeHttpParser$new())
+ arv$setRESTService(fakeREST)
- collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- newCollectionContent <- list(newName = "Brand new shiny name")
-
- expect_that(arv$updateCollection(collectionUUID, newCollectionContent),
- throws_error(404))
+ arv$updateCollection(collectionUUID,
+ list(name = "MyCollection", desc = "No description"))
+
+ expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
})
-test_that("createCollection calls REST service properly", {
+test_that("createCollection delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
-
- collectionContent <- list(name = "My favorite collection")
- expectedURL <- paste0(arv$getHostName(), "collections")
- serverResponse <- NULL
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
+ collectionContent <- list(newName = "Brand new shiny name")
arv$createCollection(collectionContent)
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
- expect_that(httpRequest$numberOfPOSTRequests, equals(1))
+ expect_that(fakeREST$createResourceCallCount, equals(1))
})
-test_that("createCollection parses server response", {
+test_that("createCollection adds content to request parameter named 'collection'", {
+ body <- list(list())
+ names(body) <- c("collection")
+ body$collection <- list(name = "MyCollection", desc = "No description")
+ fakeREST <- FakeRESTService$new(returnContent = body)
arv <- Arvados$new("token", "hostName")
+ arv$setRESTService(fakeREST)
- httpParser <- FakeHttpParser$new()
- arv$setHttpParser(httpParser)
- arv$setHttpClient(FakeHttpRequest$new())
-
- collectionContent <- list(name = "My favorite collection")
-
- arv$createCollection(collectionContent)
-
- expect_that(httpParser$parserCallCount, equals(1))
-})
-
-test_that("createCollection raises exception if response contains errors field", {
+ arv$createCollection(list(name = "MyCollection", desc = "No description"))
- arv <- Arvados$new("token", "hostName")
-
- expectedURL <- NULL
- serverResponse <- list(errors = 404)
- arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
- arv$setHttpParser(FakeHttpParser$new())
-
- collectionContent <- list(name = "My favorite collection")
-
- expect_that(arv$createCollection(collectionContent),
- throws_error(404))
+ expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
})
-test_that("getProject calls REST service properly", {
+test_that("getProject delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
-
- serverResponse <- NULL
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- expectedURL <- paste0(arv$getHostName(), "groups/", projectUUID)
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
+ arv$getCollection(projectUUID)
- arv$getProject(projectUUID)
-
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$numberOfGETRequests, equals(1))
+ expect_that(fakeREST$getResourceCallCount, equals(1))
})
-test_that("getProject parses server response", {
+test_that("listProjects delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
- httpParser <- FakeHttpParser$new()
- arv$setHttpParser(httpParser)
- arv$setHttpClient(FakeHttpRequest$new())
-
- projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- arv$getProject(projectUUID)
+ arv$listCollections()
- expect_that(httpParser$parserCallCount, equals(1))
+ expect_that(fakeREST$listResourcesCallCount, equals(1))
})
-test_that("getProject raises exception if response contains errors field", {
+test_that("listProjects filter contains additional 'group_class' field by default", {
- arv <- Arvados$new("token", "hostName")
-
- serverResponse <- list(errors = 404)
- arv$setHttpClient(FakeHttpRequest$new(NULL, serverResponse))
- arv$setHttpParser(FakeHttpParser$new())
-
- projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- expect_that(arv$getProject(projectUUID),
- throws_error(404))
-})
-
-test_that("createProject calls REST service properly", {
+ filters <- list(list("name", "like", "MyProject"))
+ names(filters) <- c("groups")
+ filters[[length(filters) + 1]] <- list("group_class", "=", "project")
+ fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
arv <- Arvados$new("token", "hostName")
+ arv$setRESTService(fakeREST)
- projectContent <- list(name = "My favorite project")
- expectedURL <- paste0(arv$getHostName(), "groups")
- serverResponse <- NULL
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
+ arv$listProjects(list(list("name", "like", "MyProject")))
- arv$createProject(projectContent)
-
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
- expect_that(httpRequest$numberOfPOSTRequests, equals(1))
+ expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
})
-test_that("createProject parses server response", {
+test_that("listAllProjects delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
- httpParser <- FakeHttpParser$new()
- arv$setHttpParser(httpParser)
- arv$setHttpClient(FakeHttpRequest$new())
-
- projectContent <- list(name = "My favorite project")
+ arv$listAllProjects()
- arv$createProject(projectContent)
-
- expect_that(httpParser$parserCallCount, equals(1))
+ expect_that(fakeREST$fetchAllItemsCallCount, equals(1))
})
-test_that("createProject raises exception if response contains errors field", {
-
- arv <- Arvados$new("token", "hostName")
-
- expectedURL <- NULL
- serverResponse <- list(errors = 404)
- arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
- arv$setHttpParser(FakeHttpParser$new())
-
- projectContent <- list(name = "My favorite project")
-
- expect_that(arv$createProject(projectContent),
- throws_error(404))
-})
+test_that("listAllProjects filter contains additional 'group_class' field by default", {
-test_that("updateProject calls REST service properly", {
+ filters <- list(list("name", "like", "MyProject"))
+ names(filters) <- c("groups")
+ filters[[length(filters) + 1]] <- list("group_class", "=", "project")
+ fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
arv <- Arvados$new("token", "hostName")
+ arv$setRESTService(fakeREST)
- newProjectContent <- list(newName = "Brand new shiny name")
- projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- expectedURL <- paste0(arv$getHostName(), "groups/", projectUUID)
- serverResponse <- NULL
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
-
- arv$updateProject(projectUUID, newProjectContent)
+ arv$listAllProjects(list(list("name", "like", "MyProject")))
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
- expect_that(httpRequest$numberOfPUTRequests, equals(1))
+ expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
})
-test_that("updateProject parses server response", {
+test_that("deleteProject delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
-
- httpParser <- FakeHttpParser$new()
- arv$setHttpParser(httpParser)
- arv$setHttpClient(FakeHttpRequest$new())
-
- newProjectContent <- list(newName = "Brand new shiny name")
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- arv$updateProject(projectUUID, newProjectContent)
+ arv$deleteCollection(projectUUID)
- expect_that(httpParser$parserCallCount, equals(1))
+ expect_that(fakeREST$deleteResourceCallCount, equals(1))
})
-test_that("updateProject raises exception if response contains errors field", {
+test_that("updateProject delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
-
- expectedURL <- NULL
- serverResponse <- list(errors = 404)
- arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
- arv$setHttpParser(FakeHttpParser$new())
-
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
newProjectContent <- list(newName = "Brand new shiny name")
projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- expect_that(arv$updateProject(projectUUID, newProjectContent),
- throws_error(404))
-})
-
-test_that("listProjects calls REST service properly", {
-
- arv <- Arvados$new("token", "hostName")
- serverResponse <- NULL
- expectedURL <- paste0(arv$getHostName(), "groups")
- expectedFilters <- list(list("name" = "My project"),
- list("group_class", "=", "project"))
+ arv$updateCollection(projectUUID, newProjectContent)
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse, expectedFilters)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
-
- arv$listProjects(list(list("name" = "My project")))
-
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$queryFiltersAreCorrect, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$numberOfGETRequests, equals(1))
+ expect_that(fakeREST$updateResourceCallCount, equals(1))
})
-test_that("listProjects parses server response", {
-
- arv <- Arvados$new("token", "hostName")
-
- httpParser <- FakeHttpParser$new()
- arv$setHttpParser(httpParser)
- arv$setHttpClient(FakeHttpRequest$new())
-
- arv$listProjects()
-
- expect_that(httpParser$parserCallCount, equals(1))
-})
+test_that("updateProject adds content to request parameter named 'group'", {
-test_that("listProjects raises exception if response contains errors field", {
+ projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
+ body <- list(list())
+ names(body) <- c("group")
+ body$group <- list(name = "MyProject", desc = "No description")
+ fakeREST <- FakeRESTService$new(returnContent = body)
arv <- Arvados$new("token", "hostName")
-
- serverResponse <- list(errors = 404)
- expectedURL <- NULL
- arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
- arv$setHttpParser(FakeHttpParser$new())
-
- expect_that(arv$listProjects(),
- throws_error(404))
-})
+ arv$setRESTService(fakeREST)
-test_that("listAllProjects always returns all projects from server", {
+ arv$updateProject(projectUUID,
+ list(name = "MyProject", desc = "No description"))
- arv <- Arvados$new("token", "hostName")
-
- expectedURL <- NULL
- serverResponse <- list(items_available = 8,
- items = list("project1",
- "project2",
- "project3",
- "project4",
- "project5",
- "project6",
- "project7",
- "project8"))
-
- expectedFilters <- list(list("name" = "My project"),
- list("group_class", "=", "project"))
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse, expectedFilters)
- httpParser <- FakeHttpParser$new()
-
- httpRequest$serverMaxElementsPerRequest <- 3
-
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(httpParser)
-
- result <- arv$listAllProjects(list(list("name" = "My project")))
-
- expect_that(length(result), equals(8))
- expect_that(httpRequest$queryFiltersAreCorrect, is_true())
- expect_that(httpRequest$numberOfGETRequests, equals(3))
- expect_that(httpParser$parserCallCount, equals(3))
+ expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
})
-test_that("deleteProject calls REST service properly", {
+test_that("createProject delegates operation to RESTService class", {
arv <- Arvados$new("token", "hostName")
+ fakeREST <- FakeRESTService$new()
+ arv$setRESTService(fakeREST)
+ projectContent <- list(newName = "Brand new shiny name")
- serverResponse <- NULL
- projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- expectedURL <- paste0(arv$getHostName(), "groups/", projectUUID)
-
- httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
- arv$setHttpClient(httpRequest)
- arv$setHttpParser(FakeHttpParser$new())
-
- arv$deleteProject(projectUUID)
+ arv$createCollection(projectContent)
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
- expect_that(httpRequest$numberOfDELETERequests, equals(1))
+ expect_that(fakeREST$createResourceCallCount, equals(1))
})
-test_that("deleteProject parses server response", {
-
- arv <- Arvados$new("token", "hostName")
+test_that("createProject request body contains 'goup_class' filed", {
- httpParser <- FakeHttpParser$new()
- arv$setHttpParser(httpParser)
- arv$setHttpClient(FakeHttpRequest$new())
-
- projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
- arv$deleteProject(projectUUID)
-
- expect_that(httpParser$parserCallCount, equals(1))
-})
-
-test_that("deleteCollection raises exception if response contains errors field", {
+ body <- list(list())
+ names(body) <- c("group")
+ body$group <- c("group_class" = "project",
+ list(name = "MyProject", desc = "No description"))
+ fakeREST <- FakeRESTService$new(returnContent = body)
arv <- Arvados$new("token", "hostName")
-
- serverResponse <- list(errors = 404)
- expectedURL <- NULL
- arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
- arv$setHttpParser(FakeHttpParser$new())
+ arv$setRESTService(fakeREST)
- projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
- expect_that(arv$deleteProject(projectUUID),
- throws_error(404))
+ arv$createProject(list(name = "MyProject", desc = "No description"))
+
+ expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
})