jsonlite,
curl,
XML
+Suggests: testthat
stop("Please provide host name and authentification token or set
ARVADOS_API_HOST and ARVADOS_API_TOKEN environmental variables.")
- discoveryDocumentURL <- paste0("https://", host,
- "/discovery/v1/apis/arvados/v1/rest")
-
version <- "v1"
host <- paste0("https://", host, "/arvados/", version, "/")
private$httpParser <- HttpParser$new()
private$token <- token
private$host <- host
-
- headers <- list(Authorization = paste("OAuth2", private$token))
-
- serverResponse <- private$http$GET(discoveryDocumentURL, headers)
-
- discoveryDocument <- private$httpParser$parseJSONResponse(serverResponse)
- private$webDavHostName <- discoveryDocument$keepWebServiceUrl
-
- if(is.null(private$webDavHostName))
- stop("Unable to find WebDAV server.")
},
getToken = function() private$token,
getHostName = function() private$host,
- getWebDavHostName = function() private$webDavHostName,
+ getWebDavHostName = function()
+ {
+ if(is.null(private$webDavHostName))
+ {
+ discoveryDocumentURL <- paste0("https://", host,
+ "/discovery/v1/apis/arvados/v1/rest")
+
+ headers <- list(Authorization = paste("OAuth2", private$token))
+
+ serverResponse <- private$http$GET(discoveryDocumentURL, headers)
+
+ discoveryDocument <- private$httpParser$parseJSONResponse(serverResponse)
+ private$webDavHostName <- discoveryDocument$keepWebServiceUrl
+
+ if(is.null(private$webDavHostName))
+ stop("Unable to find WebDAV server.")
+ }
+
+ private$webDavHostName
+ },
getCollection = function(uuid)
{
--- /dev/null
+library(testthat)
+library(ArvadosR)
+
+test_check("ArvadosR")
--- /dev/null
+HttpRequest <- R6::R6Class(
+
+ "HttrRequestStub",
+
+ public = list(
+
+ validContentTypes = NULL,
+
+ content = NULL,
+
+ initialize = function(returnContent)
+ {
+ self$validContentTypes <- c("text", "raw")
+ self$content <- returnContent
+ },
+
+ GET = function(url, headers = NULL, queryFilters = NULL, limit = NULL, offset = NULL)
+ {
+ return self$content
+ },
+
+ PUT = function(url, headers = NULL, body = NULL,
+ queryFilters = NULL, limit = NULL, offset = NULL)
+ {
+ return self$content
+ },
+
+ POST = function(url, headers = NULL, body = NULL,
+ queryFilters = NULL, limit = NULL, offset = NULL)
+ {
+ return self$content
+ },
+
+ DELETE = function(url, headers = NULL, body = NULL,
+ queryFilters = NULL, limit = NULL, offset = NULL)
+ {
+ return self$content
+ },
+
+ PROPFIND = function(url, headers = NULL)
+ {
+ return self$content
+ },
+
+ MOVE = function(url, headers = NULL)
+ {
+ return self$content
+ }
+ ),
+
+ cloneable = FALSE
+)
--- /dev/null
+context("Arvados API")
+
+test_that("Arvados constructor will use environment variables if no parameters are passed to it", {
+
+ Sys.setenv(ARVADOS_API_HOST = "environment_api_host")
+ Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
+
+ arv <- Arvados$new()
+
+ Sys.unsetenv("ARVADOS_API_HOST")
+ Sys.unsetenv("ARVADOS_API_TOKEN")
+
+ expect_that("https://environment_api_host/arvados/v1/",
+ equals(arv$getHostName()))
+
+ expect_that("environment_api_token",
+ equals(arv$getToken()))
+})
+
+test_that("Arvados constructor preferes constructor fields over environment variables", {
+
+ Sys.setenv(ARVADOS_API_HOST = "environment_api_host")
+ Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
+
+ arv <- Arvados$new("constructor_api_token", "constructor_api_host")
+
+ Sys.unsetenv("ARVADOS_API_HOST")
+ Sys.unsetenv("ARVADOS_API_TOKEN")
+
+ expect_that("https://constructor_api_host/arvados/v1/",
+ equals(arv$getHostName()))
+
+ expect_that("constructor_api_token",
+ equals(arv$getToken()))
+})