-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from CIAT-DAPA/develop
test
- Loading branch information
Showing
2 changed files
with
65 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
||
}) | ||
# }) |