Merge branch 'master' into 7478-anm-spot-instances
[arvados.git] / sdk / R / tests / testthat / test-RESTService.R
index d4f3c2c1c0b809f48fa983cf55d504e6da42eadf..859b6180f3380c2d834b99e126aa0c7761155368 100644 (file)
@@ -1,3 +1,7 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+
 source("fakes/FakeArvados.R")
 source("fakes/FakeHttpRequest.R")
 source("fakes/FakeHttpParser.R")
@@ -31,264 +35,6 @@ test_that("getWebDavHostName returns webDAV host name properly", {
     expect_that("https://myWebDavServer.com", equals(REST$getWebDavHostName())) 
 }) 
 
-test_that("getResource calls REST service properly", {
-
-    serverResponse <- NULL
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    expectedURL    <- paste0("https://host/arvados/v1/collections/", resourceUUID)
-
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, FakeHttpParser$new(),
-                            0, "webDavHost")
-
-    REST$getResource("collections", resourceUUID)
-
-    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
-    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
-    expect_that(httpRequest$numberOfGETRequests, equals(1))
-}) 
-
-test_that("getResource parses server response", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    httpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(), httpParser,
-                            0, "webDavHost")
-
-    REST$getResource("collections", resourceUUID)
-
-    expect_that(httpParser$parserCallCount, equals(1))
-}) 
-
-test_that("getResource raises exception if response contains errors field", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    serverResponse <- list(errors = 404)
-
-    REST <- RESTService$new("token", "host",
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new(),
-                            0, "webDavHost")
-    
-    expect_that(REST$getResource("collections", resourceUUID), throws_error("404", fixed = TRUE))
-}) 
-
-test_that("listResources calls REST service properly", {
-
-    serverResponse <- NULL
-    expectedURL    <- paste0("https://host/arvados/v1/collections")
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, FakeHttpParser$new(),
-                            0, "webDavHost")
-
-    REST$listResources("collections")
-
-    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
-    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
-    expect_that(httpRequest$numberOfGETRequests, equals(1))
-}) 
-
-test_that("listResources parses server response", {
-
-    httpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(), httpParser,
-                            0, "webDavHost")
-
-    REST$listResources("collections")
-
-    expect_that(httpParser$parserCallCount, equals(1))
-}) 
-
-test_that("listResources raises exception if response contains errors field", {
-
-    serverResponse <- list(errors = 404)
-
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new(),
-                            0, "webDavHost")
-    
-    expect_that(REST$listResources("collections"), throws_error("404", fixed = TRUE))
-}) 
-
-test_that("fetchAllItems always returns all resource items from server", {
-
-    expectedURL <- NULL
-    serverResponse <- list(items_available = 8,
-                           items = list("collection1",
-                                        "collection2",
-                                        "collection3",
-                                        "collection4",
-                                        "collection5",
-                                        "collection6",
-                                        "collection7",
-                                        "collection8"))
-
-    httpParser <- FakeHttpParser$new()
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-    httpRequest$serverMaxElementsPerRequest <- 3
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, httpParser,
-                            0, "webDavHost")
-
-    result <- REST$fetchAllItems(NULL, NULL)
-
-    expect_that(length(result), equals(8))
-    expect_that(httpRequest$numberOfGETRequests, equals(3))
-    expect_that(httpParser$parserCallCount, equals(3))
-}) 
-
-test_that("deleteResource calls REST service properly", {
-
-    serverResponse <- NULL
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    expectedURL    <- paste0("https://host/arvados/v1/collections/", resourceUUID)
-
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, FakeHttpParser$new(),
-                            0, "webDavHost")
-
-    REST$deleteResource("collections", resourceUUID)
-
-    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
-    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
-    expect_that(httpRequest$numberOfDELETERequests, equals(1))
-}) 
-
-test_that("deleteCollection parses server response", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    httpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(), httpParser,
-                            0, "webDavHost")
-
-    REST$deleteResource("collections", resourceUUID)
-
-    expect_that(httpParser$parserCallCount, equals(1))
-}) 
-
-test_that("deleteCollection raises exception if response contains errors field", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    serverResponse <- list(errors = 404)
-
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new(),
-                            0, "webDavHost")
-    
-    expect_that(REST$deleteResource("collections", resourceUUID), throws_error("404", fixed = TRUE))
-}) 
-
-test_that("updateResource calls REST service properly", {
-
-    serverResponse <- NULL
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    expectedURL    <- paste0("https://host/arvados/v1/collections/", resourceUUID)
-    newResourceContent <- list(newName = "Brand new shiny name")
-
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, FakeHttpParser$new(),
-                            0, "webDavHost")
-
-    REST$updateResource("collections", resourceUUID, newResourceContent)
-
-    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
-    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
-    expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
-    expect_that(httpRequest$numberOfPUTRequests, equals(1))
-}) 
-
-test_that("updateResource parses server response", {
-
-    newResourceContent <- list(newName = "Brand new shiny name")
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    httpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(), httpParser,
-                            0, "webDavHost")
-
-    REST$updateResource("collections", resourceUUID, newResourceContent)
-
-    expect_that(httpParser$parserCallCount, equals(1))
-}) 
-
-test_that("updateResource raises exception if response contains errors field", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    serverResponse <- list(errors = 404)
-    newResourceContent <- list(newName = "Brand new shiny name")
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new(),
-                            0, "webDavHost")
-    
-    expect_that(REST$updateResource("collections", resourceUUID, newResourceContent),
-                throws_error("404", fixed = TRUE))
-}) 
-
-test_that("createResource calls REST service properly", {
-
-    resourceContent <- list(name = "My favorite collection")
-    serverResponse <- NULL
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    expectedURL <- "https://host/arvados/v1/collections"
-    newResourceContent <- list(newName = "Brand new shiny name")
-
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, FakeHttpParser$new(),
-                            0, "webDavHost")
-
-    REST$createResource("collections", resourceContent)
-
-    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
-    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
-    expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
-    expect_that(httpRequest$numberOfPOSTRequests, equals(1))
-}) 
-
-test_that("createResource parses server response", {
-
-    resourceContent <- list(newName = "Brand new shiny name")
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    httpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "host",
-                            FakeHttpRequest$new(), httpParser,
-                            0, "webDavHost")
-
-    REST$createResource("collections", resourceContent)
-
-    expect_that(httpParser$parserCallCount, equals(1))
-}) 
-
-test_that("createResource raises exception if response contains errors field", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    serverResponse <- list(errors = 404)
-    resourceContent <- list(newName = "Brand new shiny name")
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new(),
-                            0, "webDavHost")
-    
-    expect_that(REST$createResource("collections", resourceContent),
-                throws_error("404", fixed = TRUE))
-}) 
-
 test_that("create calls REST service properly", {
 
     uuid <- "aaaaa-j7d0g-ccccccccccccccc"