[ARVADOS] updated: 1.1.2-110-g937c64f

Git user git at public.curoverse.com
Thu Jan 11 10:16:23 EST 2018


Summary of changes:
 sdk/R/R/Arvados.R                            |   1 +
 sdk/R/tests/testthat/fakes/FakeHttpRequest.R |  87 +++++-
 sdk/R/tests/testthat/test-Arvados.R          | 414 ++++++++++++++++++++++++++-
 3 files changed, 497 insertions(+), 5 deletions(-)

       via  937c64f38ff59f11616ea8932b24116530f2e60f (commit)
      from  ecb7d4501373a21ae69494beee8252f107ec1b56 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 937c64f38ff59f11616ea8932b24116530f2e60f
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Thu Jan 11 16:15:09 2018 +0100

    Added more unit tests to Arvados class
    
    Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>

diff --git a/sdk/R/R/Arvados.R b/sdk/R/R/Arvados.R
index 7cf75a9..0317266 100644
--- a/sdk/R/R/Arvados.R
+++ b/sdk/R/R/Arvados.R
@@ -137,6 +137,7 @@ Arvados <- R6::R6Class(
                             "Content-Type"  = "application/json")
 
             body <- list(list())
+            #test if this is needed
             names(body) <- c("collection")
             body$collection <- newContent
 
diff --git a/sdk/R/tests/testthat/fakes/FakeHttpRequest.R b/sdk/R/tests/testthat/fakes/FakeHttpRequest.R
index 612c80d..168e4ec 100644
--- a/sdk/R/tests/testthat/fakes/FakeHttpRequest.R
+++ b/sdk/R/tests/testthat/fakes/FakeHttpRequest.R
@@ -4,43 +4,75 @@ FakeHttpRequest <- R6::R6Class(
 
     public = list(
 
+        serverMaxElementsPerRequest = NULL,
+
         content                                 = NULL,
         expectedURL                             = NULL,
         URLIsProperlyConfigured                 = NULL,
+        expectedQueryFilters                    = NULL,
+        queryFiltersAreCorrect                  = NULL,
         requestHeaderContainsAuthorizationField = NULL,
+        JSONEncodedBodyIsProvided               = NULL,
 
-        numberOfGETRequests = NULL,
+        numberOfGETRequests    = NULL,
         numberOfDELETERequests = NULL,
+        numberOfPUTRequests    = NULL,
+        numberOfPOSTRequests   = NULL,
 
-        initialize = function(expectedURL = NULL, serverResponse = NULL)
+        initialize = function(expectedURL = NULL,
+                              serverResponse = NULL,
+                              expectedFilters = NULL)
         {
             self$content <- serverResponse
             self$expectedURL <- expectedURL
-            self$requestHeaderContainsAuthorizationField <- FALSE
             self$URLIsProperlyConfigured <- FALSE
+            self$expectedQueryFilters <- expectedFilters
+            self$queryFiltersAreCorrect <- FALSE
+            self$requestHeaderContainsAuthorizationField <- FALSE
+            self$JSONEncodedBodyIsProvided <- FALSE
 
             self$numberOfGETRequests <- 0
             self$numberOfDELETERequests <- 0
+            self$numberOfPUTRequests <- 0
+            self$numberOfPOSTRequests <- 0
+
+            self$serverMaxElementsPerRequest <- 5
         },
 
         GET = function(url, headers = NULL, queryFilters = NULL, limit = NULL, offset = NULL)
         {
             private$validateURL(url)
             private$validateHeaders(headers)
+            private$validateFilters(queryFilters)
             self$numberOfGETRequests <- self$numberOfGETRequests + 1
 
-            self$content
+            if(!is.null(self$content$items_available))
+            {
+                return(private$getElements(offset, limit))
+            }
+            else
+                return(self$content)
         },
 
         PUT = function(url, headers = NULL, body = NULL,
                        queryFilters = NULL, limit = NULL, offset = NULL)
         {
+            private$validateURL(url)
+            private$validateHeaders(headers)
+            private$validateBody(body)
+            self$numberOfPUTRequests <- self$numberOfPUTRequests + 1
+
             self$content
         },
 
         POST = function(url, headers = NULL, body = NULL,
                         queryFilters = NULL, limit = NULL, offset = NULL)
         {
+            private$validateURL(url)
+            private$validateHeaders(headers)
+            private$validateBody(body)
+            self$numberOfPOSTRequests <- self$numberOfPOSTRequests + 1
+
             self$content
         },
 
@@ -76,6 +108,53 @@ FakeHttpRequest <- R6::R6Class(
         {
             if(!is.null(headers$Authorization))
                 self$requestHeaderContainsAuthorizationField <- TRUE
+        },
+
+        validateBody = function(body)
+        {
+            if(!is.null(body) && class(body) == "json")           
+                self$JSONEncodedBodyIsProvided <- TRUE
+        },
+
+        validateFilters = function(filters)
+        {
+            if(!is.null(self$expectedQueryFilters) &&
+               !is.null(filters) &&
+               all.equal(unname(filters), self$expectedQueryFilters))
+            {
+                self$queryFiltersAreCorrect <- TRUE
+            }
+        },
+
+        getElements = function(offset, limit)
+        {
+            start <- 1
+            elementCount <- self$serverMaxElementsPerRequest
+
+            if(!is.null(offset))
+            {
+                if(offset > self$content$items_available)
+                    stop("Invalid offset")
+                
+                start <- offset + 1
+            }
+
+            if(!is.null(limit))
+                if(limit < self$serverMaxElementsPerRequest)
+                    elementCount <- limit - 1
+
+
+            serverResponse <- list()
+            serverResponse$items_available <- self$content$items_available
+            serverResponse$items <- self$content$items[start:(start + elementCount - 1)]
+
+            if(start + elementCount > self$content$items_available)
+            {
+                elementCount = self$content$items_available - start
+                serverResponse$items <- self$content$items[start:(start + elementCount)]
+            }
+
+            serverResponse
         }
     ),
 
diff --git a/sdk/R/tests/testthat/test-Arvados.R b/sdk/R/tests/testthat/test-Arvados.R
index 16b6798..950c545 100644
--- a/sdk/R/tests/testthat/test-Arvados.R
+++ b/sdk/R/tests/testthat/test-Arvados.R
@@ -170,6 +170,36 @@ test_that("listCollections raises exception if response contains errors field",
                 throws_error(404))
 }) 
 
+test_that("listAllCollections always returns all collections from server", {
+
+    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))
+}) 
+
 test_that("deleteCollection calls REST service properly", {
 
     arv <- Arvados$new("token", "hostName")
@@ -203,7 +233,7 @@ test_that("deleteCollection parses server response", {
     expect_that(httpParser$parserCallCount, equals(1))
 }) 
 
-test_that("getCollection raises exception if response contains errors field", {
+test_that("deleteCollection raises exception if response contains errors field", {
 
     arv <- Arvados$new("token", "hostName")
     
@@ -216,3 +246,385 @@ test_that("getCollection raises exception if response contains errors field", {
     expect_that(arv$deleteCollection(collectionUUID), 
                 throws_error(404))
 }) 
+
+test_that("updateCollection calls REST service properly", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    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))
+}) 
+
+test_that("updateCollection parses server response", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    httpParser <- FakeHttpParser$new()
+    arv$setHttpParser(httpParser)
+    arv$setHttpClient(FakeHttpRequest$new())
+
+    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", {
+
+    arv <- Arvados$new("token", "hostName")
+    
+    expectedURL <- NULL
+    serverResponse <- list(errors = 404)
+    arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
+    arv$setHttpParser(FakeHttpParser$new())
+
+    collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
+    newCollectionContent <- list(newName = "Brand new shiny name")
+    
+    expect_that(arv$updateCollection(collectionUUID, newCollectionContent), 
+                throws_error(404))
+}) 
+
+test_that("createCollection calls REST service properly", {
+
+    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())
+
+    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))
+}) 
+
+test_that("createCollection parses server response", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    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 <- 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))
+}) 
+
+test_that("getProject calls REST service properly", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    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$getProject(projectUUID)
+
+    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
+    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
+    expect_that(httpRequest$numberOfGETRequests, equals(1))
+}) 
+
+test_that("getProject parses server response", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    httpParser <- FakeHttpParser$new()
+    arv$setHttpParser(httpParser)
+    arv$setHttpClient(FakeHttpRequest$new())
+
+    projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
+    arv$getProject(projectUUID)
+
+    expect_that(httpParser$parserCallCount, equals(1))
+}) 
+
+test_that("getProject 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())
+
+    projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
+    
+    expect_that(arv$getProject(projectUUID), 
+                throws_error(404))
+}) 
+
+test_that("createProject calls REST service properly", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    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$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))
+}) 
+
+test_that("createProject parses server response", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    httpParser <- FakeHttpParser$new()
+    arv$setHttpParser(httpParser)
+    arv$setHttpClient(FakeHttpRequest$new())
+
+    projectContent <- list(name = "My favorite project")
+
+    arv$createProject(projectContent)
+
+    expect_that(httpParser$parserCallCount, 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("updateProject calls REST service properly", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    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)
+
+    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("updateProject parses server response", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    httpParser <- FakeHttpParser$new()
+    arv$setHttpParser(httpParser)
+    arv$setHttpClient(FakeHttpRequest$new())
+
+    newProjectContent <- list(newName = "Brand new shiny name")
+    projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
+
+    arv$updateProject(projectUUID, newProjectContent)
+
+    expect_that(httpParser$parserCallCount, equals(1))
+}) 
+
+test_that("updateProject 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())
+
+    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"))
+
+    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))
+}) 
+
+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("listProjects raises exception if response contains errors field", {
+
+    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))
+}) 
+
+test_that("listAllProjects always returns all projects from server", {
+
+    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))
+}) 
+
+test_that("deleteProject calls REST service properly", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    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)
+
+    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
+    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
+    expect_that(httpRequest$numberOfDELETERequests, equals(1))
+}) 
+
+test_that("deleteProject parses server response", {
+
+    arv <- Arvados$new("token", "hostName")
+
+    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", {
+
+    arv <- Arvados$new("token", "hostName")
+    
+    serverResponse <- list(errors = 404)
+    expectedURL <- NULL
+    arv$setHttpClient(FakeHttpRequest$new(expectedURL, serverResponse))
+    arv$setHttpParser(FakeHttpParser$new())
+
+    projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
+    
+    expect_that(arv$deleteProject(projectUUID), 
+                throws_error(404))
+}) 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list