Skip to content

Commit d964b6f

Browse files
committed
zenodo workflows integration tests
1 parent a6af849 commit d964b6f

5 files changed

+22
-23
lines changed

inst/extdata/workflows/config_metadata_zenodo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"parameters": {
2727
"url": "https://sandbox.zenodo.org/api",
2828
"token": "{{ ZENODO_SANDBOX_TOKEN }}",
29-
"logger": "DEBUG"
29+
"logger": "INFO"
3030
}
3131
}
3232
],

inst/extdata/workflows/config_metadata_zenodo_with_options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"entities": [
1414
{
1515
"handler": "zenodo",
16-
"source": ["10.5281/zenodo.2547036"],
16+
"source": ["10.5281/zenodo.7552287"],
1717
"options": {
1818
"resource_type": "record",
1919
"source_type": "doi"

inst/metadata/entity/entity_handler_zenodo.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
handle_entities_zenodo <- function(handler, source, config, handle = TRUE){
33

44
if(!requireNamespace("zen4R", quietly = TRUE)){
5-
stop("The Dataverse handler requires the 'zen4R' package")
5+
stop("The ZENODo handler requires the 'zen4R' package")
66
}
77

88
ZENODO <- config$software$input$zenodo
@@ -65,20 +65,21 @@ handle_entities_zenodo <- function(handler, source, config, handle = TRUE){
6565

6666
entities <- lapply(1:length(results), function(i){
6767
result <- results[[i]]
68-
result_doi = result$pids$doi$identifier
68+
print(result)
69+
result_doi = result$getDOI()
6970
config$logger.info(sprintf("Creating entity (%s out of %s) from Zenodo deposit/record with DOI '%s'", i, length(results), result_doi))
7071

7172
#create entity
7273
entity <- geoflow::geoflow_entity$new()
7374
#entity Identifier
7475
entity$setIdentifier("doi", result_doi)
7576
#semantic identifier
76-
identifiers = result$metadata$related_identifiers[sapply(result$metadata$related_identifiers, function(x){x$scheme == "urn" && x$relation == "isIdenticalTo"})]
77+
identifiers = result$metadata$related_identifiers[sapply(result$metadata$related_identifiers, function(x){x$scheme == "other" && x$relation_type$id == "isidenticalto"})]
7778
if(length(identifiers)>0){
7879
identifier = identifiers[[1]]$identifier
7980
entity$setIdentifier("id", substr(identifier, 5,nchar(identifier)))
8081
}else{
81-
entity$setIdentifier("id", gsub("/", "_", result_doi))
82+
entity$setIdentifier("id", gsub("/", "_", result$getDOI()))
8283
}
8384

8485
#entity Date

tests/testthat/test_config_metadata_zenodo.R

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
require(geoflow, quietly = TRUE)
77
require(testthat)
88

9+
cfg_file = system.file("extdata/workflows/config_metadata_zenodo.json", package = "geoflow")
10+
911
#init
1012
test_that("init",{
1113
testthat::skip_on_cran()
12-
cfg_file = system.file("extdata/workflows/config_metadata_zenodo.json", package = "geoflow")
1314
CFG <- geoflow::initWorkflow(cfg_file)
1415
expect_is(CFG$metadata$content, "list")
1516
expect_equal(length(CFG$metadata$content), 1L)
@@ -27,7 +28,6 @@ test_that("init",{
2728
#debug
2829
test_that("debug",{
2930
testthat::skip_on_cran()
30-
cfg_file = system.file("extdata/workflows/config_metadata_zenodo.json", package = "geoflow")
3131
DEBUG <- geoflow::debugWorkflow(cfg_file, entityIndex = 1, dir = ".")
3232
expect_equal(names(DEBUG), c("config", "entity"))
3333
expect_is(DEBUG$config, "list")
@@ -36,11 +36,10 @@ test_that("debug",{
3636

3737
#execute
3838
test_that("execute",{
39-
#testthat::skip_on_cran()
40-
#cfg_file = system.file("extdata/workflows/config_metadata_zenodo.json", package = "geoflow")
39+
testthat::skip_on_cran()
4140
#execution
42-
#EXEC <- geoflow::executeWorkflow(cfg_file, dir = ".")
43-
#expect_true(dir.exists(EXEC))
44-
#expect_true(file.exists(file.path(EXEC, "job.json")))
45-
#expect_true(file.exists(file.path(EXEC, "job-logs.txt")))
41+
EXEC <- geoflow::executeWorkflow(cfg_file, dir = ".")
42+
expect_true(dir.exists(EXEC))
43+
expect_true(file.exists(file.path(EXEC, "job.json")))
44+
expect_true(file.exists(file.path(EXEC, "job-logs.txt")))
4645
})

tests/testthat/test_config_metadata_zenodo_with_options.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
require(geoflow, quietly = TRUE)
77
require(testthat)
88

9+
cfg_file = system.file("extdata/workflows/config_metadata_zenodo_with_options.json", package = "geoflow")
10+
911
#init
1012
test_that("init",{
1113
testthat::skip_on_cran()
12-
cfg_file = system.file("extdata/workflows/config_metadata_zenodo_with_options.json", package = "geoflow")
1314
CFG <- geoflow::initWorkflow(cfg_file)
1415
expect_is(CFG$metadata$content, "list")
1516
expect_equal(length(CFG$metadata$content), 1L)
@@ -27,21 +28,19 @@ test_that("init",{
2728
#debug
2829
test_that("debug",{
2930
testthat::skip_on_cran()
30-
cfg_file = system.file("extdata/workflows/config_metadata_zenodo_with_options.json", package = "geoflow")
3131
DEBUG <- geoflow::debugWorkflow(cfg_file, entityIndex = 1, dir = ".")
3232
expect_equal(names(DEBUG), c("config", "entity"))
3333
expect_is(DEBUG$config, "list")
3434
expect_is(DEBUG$entity, "geoflow_entity")
35-
expect_equal(DEBUG$entity$identifiers$doi, "10.5281/zenodo.3378733")
35+
expect_equal(DEBUG$entity$identifiers$doi, "10.5281/zenodo.7552287")
3636
})
3737

3838
#execute
3939
test_that("execute",{
40-
#testthat::skip_on_cran()
41-
#cfg_file = system.file("extdata/workflows/config_metadata_zenodo_with_options.json", package = "geoflow")
40+
testthat::skip_on_cran()
4241
#execution
43-
#EXEC <- geoflow::executeWorkflow(cfg_file, dir = ".")
44-
#expect_true(dir.exists(EXEC))
45-
#expect_true(file.exists(file.path(EXEC, "job.json")))
46-
#expect_true(file.exists(file.path(EXEC, "job-logs.txt")))
42+
EXEC <- geoflow::executeWorkflow(cfg_file, dir = ".")
43+
expect_true(dir.exists(EXEC))
44+
expect_true(file.exists(file.path(EXEC, "job.json")))
45+
expect_true(file.exists(file.path(EXEC, "job-logs.txt")))
4746
})

0 commit comments

Comments
 (0)