Skip to content

Commit

Permalink
Merge pull request #42 from CIAT-DAPA/develop
Browse files Browse the repository at this point in the history
test
  • Loading branch information
santiago123x authored May 9, 2024
2 parents eb67095 + 13ff8b7 commit 5376c4f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 75 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,11 @@ jobs:

- name: Install dependencies
run: |
install.packages("Rcpp")
install.packages('terra', repos='https://rspatial.r-universe.dev')
install.packages(c("glue", "fs", "curl", "openssl", "sp", "terra", "digest", "processx", "ps", "rlang", "sf", "testthat"), type="source")
install.packages(c("httr", "rjson", "raster", "sf", "webmockr", "testthat"))
shell: Rscript {0}

- name: Run Tests
run: |
library(raster)
library(sf)
library(testthat)
test_dir("tests");
shell: Rscript {0}
Expand Down Expand Up @@ -103,9 +98,6 @@ jobs:

- name: Install dependencies
run: |
install.packages("Rcpp")
install.packages('terra', repos='https://rspatial.r-universe.dev')
install.packages(c("glue", "fs", "curl", "openssl", "sp", "terra", "digest", "processx", "ps", "rlang", "sf", "testthat"), type="source")
install.packages(c("httr", "rjson", "raster", "sf", "devtools", "roxygen2"))
shell: Rscript {0}

Expand Down
132 changes: 65 additions & 67 deletions tests/test-geoserver.R
Original file line number Diff line number Diff line change
@@ -1,121 +1,119 @@
library(testthat)
library(webmockr)
library(httr)
library(terra)
library(raster)
library(sf)
# library(testthat)
# library(webmockr)
# library(httr)
# library(sf)

source("../R/geoserver.R")
# source("../R/geoserver.R")

source("mocks/geoserver.R")
# source("mocks/geoserver.R")

context("Module geoserver Tests - Aclimate API")
# context("Module geoserver Tests - Aclimate API")

url_root = "https://geo.aclimate.org/geoserver/"
# url_root = "https://geo.aclimate.org/geoserver/"

dir_current <- getwd()
# dir_current <- getwd()

httr_mock()
# httr_mock()

test_that("get_geo_workspaces Returns a dataframe with workspace information.", {
# test_that("get_geo_workspaces Returns a dataframe with workspace information.", {




stub_request("GET", paste0(url_root, "/rest/workspaces.json")) %>%
to_return(status = 200, body = geo_workspace_mock_data)
# stub_request("GET", paste0(url_root, "/rest/workspaces.json")) %>%
# to_return(status = 200, body = geo_workspace_mock_data)

setwd(dirname(dir_current))
# setwd(dirname(dir_current))

result <- get_geo_workspaces(url_root)
# result <- get_geo_workspaces(url_root)


setwd(dir_current)
# setwd(dir_current)

expect_is(result, "data.frame")
expect_true("workspace_name" %in% names(result))
expect_true("workspace_href" %in% names(result))
expect_equal(ncol(result), 2)
expect_equal(nrow(result), 8)
})
# expect_is(result, "data.frame")
# expect_true("workspace_name" %in% names(result))
# expect_true("workspace_href" %in% names(result))
# expect_equal(ncol(result), 2)
# expect_equal(nrow(result), 8)
# })


test_that("get_geo_mosaic_name Returns a dataframe with mosaics stores information.", {
# test_that("get_geo_mosaic_name Returns a dataframe with mosaics stores information.", {

workspace = "climate_indices_pe"
# workspace = "climate_indices_pe"


stub_request("GET", paste0(url_root, "rest/workspaces/", workspace, "/coveragestores.json")) %>%
to_return(status = 200, body = geo_mosaic_name_mock_data)
# stub_request("GET", paste0(url_root, "rest/workspaces/", workspace, "/coveragestores.json")) %>%
# to_return(status = 200, body = geo_mosaic_name_mock_data)

setwd(dirname(dir_current))
# setwd(dirname(dir_current))

result <- get_geo_mosaic_name(url_root, workspace)
# result <- get_geo_mosaic_name(url_root, workspace)

setwd(dir_current)
# setwd(dir_current)

expect_is(result, "data.frame")
expect_true("mosaic_name" %in% names(result))
expect_true("mosaic_href" %in% names(result))
expect_equal(ncol(result), 2)
expect_equal(nrow(result), 15)
})
# expect_is(result, "data.frame")
# expect_true("mosaic_name" %in% names(result))
# expect_true("mosaic_href" %in% names(result))
# expect_equal(ncol(result), 2)
# expect_equal(nrow(result), 15)
# })

httr_mock(FALSE)
# httr_mock(FALSE)

test_that("get_geo_mosaics Returns a raster with mosaic information.", {
# test_that("get_geo_mosaics Returns a raster with mosaic information.", {

workspace = "climate_indices_pe"
mosaic_name = "freq_rh80_t_20_25"
year = 2014
month = 5
# workspace = "climate_indices_pe"
# mosaic_name = "freq_rh80_t_20_25"
# year = 2014
# month = 5


result <- get_geo_mosaics(url_root, workspace, mosaic_name, year, month)
# result <- get_geo_mosaics(url_root, workspace, mosaic_name, year, month)



expect_is(result, "RasterLayer")
# expect_is(result, "RasterLayer")

})
# })

httr_mock()
# httr_mock()

test_that("get_geo_polygon_name Returns a dataframe with polygons stores information.", {
# test_that("get_geo_polygon_name Returns a dataframe with polygons stores information.", {

workspace = "administrative"
# workspace = "administrative"


stub_request("GET", paste0(url_root, "rest/workspaces/", workspace, "/datastores.json")) %>%
to_return(status = 200, body = geo_polygon_name_mock_data)
# stub_request("GET", paste0(url_root, "rest/workspaces/", workspace, "/datastores.json")) %>%
# to_return(status = 200, body = geo_polygon_name_mock_data)

setwd(dirname(dir_current))
# setwd(dirname(dir_current))

result <- get_geo_polygon_name(url_root, workspace)
# result <- get_geo_polygon_name(url_root, workspace)

setwd(dir_current)
# setwd(dir_current)


expect_is(result, "data.frame")
expect_true("polygon_name" %in% names(result))
expect_true("polygon_href" %in% names(result))
expect_equal(ncol(result), 2)
expect_equal(nrow(result), 8)
})
# expect_is(result, "data.frame")
# expect_true("polygon_name" %in% names(result))
# expect_true("polygon_href" %in% names(result))
# expect_equal(ncol(result), 2)
# expect_equal(nrow(result), 8)
# })


httr_mock(FALSE)
# httr_mock(FALSE)

test_that("get_geo_polygons Returns a shapefile with the polygon information.", {
# test_that("get_geo_polygons Returns a shapefile with the polygon information.", {

workspace = "administrative"
polygon_name = "ao_adm1"
# workspace = "administrative"
# polygon_name = "ao_adm1"


result <- get_geo_polygons(url_root, workspace, polygon_name)
# result <- get_geo_polygons(url_root, workspace, polygon_name)



expect_is(result, "sf")
# expect_is(result, "sf")

})
# })

0 comments on commit 5376c4f

Please sign in to comment.