Skip to content

Commit

Permalink
tests, pkg date
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed May 14, 2024
1 parent b91b0ad commit 36f7ea1
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 84 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: zen4R
Version: 1.0
Date: 2024-03-11
Version: 0.10
Date: 2024-05-14
Title: Interface to 'Zenodo' REST API
Authors@R: c(
person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com", comment = c(ORCID = "0000-0002-5870-5762")),
Expand All @@ -20,6 +20,6 @@ License: MIT + file LICENSE
URL: https://github.com/eblondel/zen4R
BugReports: https://github.com/eblondel/zen4R/issues
LazyLoad: yes
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Encoding: UTF-8
VignetteBuilder: knitr
170 changes: 89 additions & 81 deletions tests/testthat/test_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,85 +11,75 @@ context("records")
test_that("create empty record - with pre-reserved DOI",{
newRec <- ZENODO$createEmptyRecord()
expect_is(newRec, "ZenodoRecord")
expect_is(newRec$metadata$prereserve_doi, "list")
expect_true(nchar(newRec$metadata$prereserve_doi$doi)>0)
expect_true(newRec$metadata$prereserve_doi$recid>0)

#expect_is(newRec$metadata$prereserve_doi, "list")
#expect_true(nchar(newRec$metadata$prereserve_doi$doi)>0)
#expect_true(!is.null(newRec$recid))
Sys.sleep(5)
})

test_that("create and deposit record",{
myrec <- ZenodoRecord$new()
myrec$setTitle("My publication title")
myrec$setDescription("A description of my publication")
myrec$setUploadType("publication")
myrec$setPublicationType("article")
myrec$addCreator(firstname = "John", lastname = "Doe", affiliation = "Independent")
myrec$setLicense("MIT", sandbox = TRUE)
expect_true(myrec$addCommunity("ecfunded", sandbox = TRUE))
expect_false(myrec$addCommunity("ecfunded", sandbox = TRUE))
myrec$setTitle("zen4R")
myrec$setDescription("Interface to 'Zenodo' REST API")
myrec$setPublicationDate(Sys.Date())
myrec$setResourceType("software")
myrec$addCreator(firstname = "Emmanuel", lastname = "Blondel", role = "datamanager", orcid = "0000-0002-5870-5762")
myrec$addContributor(firstname = "Peter", lastname = "Lead", role = "workpackageleader")
myrec$addContributor(firstname = "Frank", "Super", role = "supervisor")
myrec$setLicense("mit", sandbox = TRUE)
#expect_true(myrec$addCommunity("openfair", sandbox = TRUE))
#expect_false(myrec$addCommunity("openfair", sandbox = TRUE))
myrec$setKeywords(c("R","package","software"))
myrec$addReference("Author et al., 2019. Title")
myrec$addReference("Fulano et al., 2018. Título")
myrec$addGrant("675680", sandbox = TRUE)
myrec$setJournalTitle("Journal title")
myrec$setJournalVolume("1")
myrec$setJournalIssue("Issue 1")
myrec$setJournalPages("19")
myrec$setConferenceTitle("Roots Rock Reggae International Conference")
myrec$setConferenceAcronym("RRR-IC-VIBES")
myrec$setConferenceDates("June 2019")
myrec$setConferencePlace("Kingston, Jamaica")
myrec$setConferenceSession("I")
myrec$setConferenceSessionPart("1")
myrec$setConferenceUrl("http://www.google.com")
myrec$setImprintPublisher("The Publisher")
myrec$setImprintISBN("isbn")
myrec$setImprintPlace("location")
myrec$setPartofTitle("Book title")
myrec$setPartofPages("1-30")
expect_true(myrec$addRelatedIdentifier("hasPart", "https://github.com/eblondel/zen4R/wiki#41-how-to-install-zen4r-in-r"))
expect_false(myrec$addRelatedIdentifier("hasPart", "https://github.com/eblondel/zen4R/wiki#41-how-to-install-zen4r-in-r"))
expect_true(myrec$addRelatedIdentifier("hasPart", "https://github.com/eblondel/zen4R/wiki#42-connect-to-zenodo-rest-api"))
expect_true(myrec$addRelatedIdentifier("hasPart", "https://github.com/eblondel/zen4R/wiki#43-query-zenodo-deposited-records"))
expect_true(myrec$addRelatedIdentifier("hasPart", "https://github.com/eblondel/zen4R/wiki#44-manage-zenodo-record-depositions"))
expect_true(myrec$addRelatedIdentifier("hasPart", "https://github.com/eblondel/zen4R/wiki#45-manage-zenodo-record-deposition-files"))
expect_true(myrec$addRelatedIdentifier("hasPart", "https://github.com/eblondel/zen4R/wiki#46-export-zenodo-record-metadata"))
expect_true(myrec$addRelatedIdentifier("hasPart", "https://github.com/eblondel/zen4R/wiki#47-browse-zenodo-controlled-vocabularies"))
expect_true(myrec$addRelatedIdentifier("hasPart", "https://github.com/eblondel/zen4R/wiki#48-query-zenodo-published-records"))
expect_true(myrec$addRelatedIdentifier("hasPart", "https://github.com/eblondel/zen4R/wiki#49-download-files-from-zenodo-records"))
expect_true(myrec$addRelatedIdentifier("isPartOf", "https://github.com/eblondel/zen4R/wiki#user_guide", "book"))
expect_false(myrec$addRelatedIdentifier("isPartOf", "https://github.com/eblondel/zen4R/wiki#user_guide", "book"))
myrec$setPublisher("CRAN")
#myrec$addGrant("675680", sandbox = TRUE)
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#41-how-to-install-zen4r-in-r", scheme = "url", relation_type = "haspart"))
expect_false(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#41-how-to-install-zen4r-in-r", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#42-connect-to-zenodo-rest-api", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#43-query-zenodo-deposited-records", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#44-manage-zenodo-record-depositions", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#45-manage-zenodo-record-deposition-files", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#46-export-zenodo-record-metadata", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#47-browse-zenodo-controlled-vocabularies", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#48-query-zenodo-published-records", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#49-download-files-from-zenodo-records", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#user_guide", scheme = "url", "ispartof", "publication-book"))
expect_false(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#user_guide", scheme = "url", "ispartof", "publication-book"))
for(i in 1:10){
expect_true(myrec$addRelatedIdentifier("hasPart", paste("http://chapter", i)))
expect_true(myrec$addRelatedIdentifier(paste("http://chapter", i), scheme = "url", "haspart"))
}
myrec$addContributor(firstname = "Peter", lastname = "Lead", type = "WorkPackageLeader")
myrec$addContributor(firstname = "Frank", "Super", type = "Supervisor")

expect_equal(myrec$metadata$title, "My publication title")
expect_equal(myrec$metadata$description, "A description of my publication")
expect_equal(myrec$metadata$upload_type, "publication")
expect_equal(myrec$metadata$publication_type, "article")
expect_is(myrec$metadata$creator, "list")
expect_equal(length(myrec$metadata$creator), 1L)
expect_equal(myrec$metadata$creator[[1]]$name, "Doe, John")
expect_equal(myrec$metadata$creator[[1]]$affiliation, "Independent")
expect_true(myrec$metadata$prereserve_doi)
expect_equal(myrec$metadata$title, "zen4R")
expect_equal(myrec$metadata$description, "Interface to 'Zenodo' REST API")
expect_equal(myrec$metadata$resource_type$id, "software")
expect_is(myrec$metadata$creators, "list")
expect_equal(length(myrec$metadata$creators), 1L)
expect_is(myrec$metadata$contributors, "list")
expect_equal(length(myrec$metadata$contributors), 2L)
expect_equal(myrec$metadata$creator[[1]]$person_or_org$name, "Blondel, Emmanuel")
expect_equal(myrec$metadata$creator[[1]]$person_or_org$identifiers[[1]]$scheme, "orcid")
expect_equal(myrec$metadata$creator[[1]]$person_or_org$identifiers[[1]]$identifier, "0000-0002-5870-5762")

#add locations
myrec$addLocation("Greenwich", description = "Well you know!", lon = -0.001545, lat = 51.477928)
#myrec$addLocation("Greenwich", description = "Well you know!", lon = -0.001545, lat = 51.477928)

#deposit
deposit = ZENODO$depositRecord(myrec)
expect_is(deposit, "ZenodoRecord")
Sys.sleep(5)

#update metadata
myrec$addCommunity("fisheries")
ZENODO$depositRecord(myrec)
deposit$addCreator(firstname = "John",lastname = "Doe", role = "supervisor")
deposit$addContributor(firstname = "Dark", "API", role = "supervisor")
deposit = ZENODO$depositRecord(deposit)
expect_equal(length(deposit$metadata$creators), 2L)
expect_equal(length(deposit$metadata$contributors), 3L)

#add files
writeLines("This is a dummy file for testing zen4R", "README.md")
ZENODO$uploadFile("README.md", record = deposit)
ZENODO$uploadFile("NEWS.md", record = deposit)
Sys.sleep(5)

#delete record
Expand All @@ -100,41 +90,59 @@ test_that("create and deposit record",{

test_that("create, deposit and publish record",{
myrec <- ZenodoRecord$new()
myrec$setTitle(paste("My publication title -", Sys.time()))
myrec$setDescription("A description of my publication")
myrec$setUploadType("publication")
myrec$setPublicationType("article")
myrec$addCreator(firstname = "John", lastname = "Doe", affiliation = "Independent")
myrec$addCreator(name = "Doe2, John2", affiliation = "Independent")
myrec$setTitle("zen4R")
myrec$setDescription("Interface to 'Zenodo' REST API")
myrec$setPublicationDate(Sys.Date())
myrec$setResourceType("software")
myrec$addCreator(firstname = "Emmanuel", lastname = "Blondel", role = "datamanager", orcid = "0000-0002-5870-5762")
myrec$addContributor(firstname = "Peter", lastname = "Lead", role = "workpackageleader")
myrec$addContributor(firstname = "Frank", "Super", role = "supervisor")
myrec$setLicense("mit", sandbox = TRUE)
myrec$addCommunity("ecfunded", sandbox = TRUE)
#expect_true(myrec$addCommunity("openfair", sandbox = TRUE))
#expect_false(myrec$addCommunity("openfair", sandbox = TRUE))
myrec$setKeywords(c("R","package","software"))
myrec$addReference("Author et al., 2019. Title")
myrec$addReference("Fulano et al., 2018. Título")
myrec$setPublisher("CRAN")
#myrec$addGrant("675680", sandbox = TRUE)
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#41-how-to-install-zen4r-in-r", scheme = "url", relation_type = "haspart"))
expect_false(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#41-how-to-install-zen4r-in-r", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#42-connect-to-zenodo-rest-api", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#43-query-zenodo-deposited-records", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#44-manage-zenodo-record-depositions", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#45-manage-zenodo-record-deposition-files", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#46-export-zenodo-record-metadata", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#47-browse-zenodo-controlled-vocabularies", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#48-query-zenodo-published-records", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#49-download-files-from-zenodo-records", scheme = "url", relation_type = "haspart"))
expect_true(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#user_guide", scheme = "url", "ispartof", "publication-book"))
expect_false(myrec$addRelatedIdentifier("https://github.com/eblondel/zen4R/wiki#user_guide", scheme = "url", "ispartof", "publication-book"))
for(i in 1:10){
expect_true(myrec$addRelatedIdentifier(paste("http://chapter", i), scheme = "url", "haspart"))
}

expect_true(startsWith(myrec$metadata$title, "My publication title"))
expect_equal(myrec$metadata$description, "A description of my publication")
expect_equal(myrec$metadata$upload_type, "publication")
expect_equal(myrec$metadata$publication_type, "article")
expect_is(myrec$metadata$creator, "list")
expect_equal(length(myrec$metadata$creator), 2L)
expect_equal(myrec$metadata$creator[[1]]$name, "Doe, John")
expect_equal(myrec$metadata$creator[[1]]$affiliation, "Independent")
expect_equal(myrec$metadata$creators[[2]]$name, "Doe2, John2")
expect_true(myrec$metadata$prereserve_doi)
expect_equal(myrec$metadata$title, "zen4R")
expect_equal(myrec$metadata$description, "Interface to 'Zenodo' REST API")
expect_equal(myrec$metadata$resource_type$id, "software")
expect_is(myrec$metadata$creators, "list")
expect_equal(length(myrec$metadata$creators), 1L)
expect_is(myrec$metadata$contributors, "list")
expect_equal(length(myrec$metadata$contributors), 2L)
expect_equal(myrec$metadata$creator[[1]]$person_or_org$name, "Blondel, Emmanuel")
expect_equal(myrec$metadata$creator[[1]]$person_or_org$identifiers[[1]]$scheme, "orcid")
expect_equal(myrec$metadata$creator[[1]]$person_or_org$identifiers[[1]]$identifier, "0000-0002-5870-5762")

#deposit
deposit = ZENODO$depositRecord(myrec)
expect_is(deposit, "ZenodoRecord")

#update metadata
myrec$addCommunity("fisheries")
ZENODO$depositRecord(myrec)
deposit$addCommunity("fisheries")
deposit = ZENODO$depositRecord(deposit)

#add files
writeLines("This is a dummy file for testing zen4R", "README.md")
ZENODO$uploadFile("README.md", record = deposit)
unlink("README.md")
ZENODO$uploadFile("NEWS.md", record = deposit)
Sys.sleep(5)

#publish record
Expand All @@ -148,16 +156,16 @@ test_that("create, deposit and publish record",{
})

test_that("get by concept DOI",{
rec <- ZENODO$getDepositionByConceptDOI("10.5072/zenodo.523362")
rec <- ZENODO$getDepositionByConceptDOI("10.5072/zenodo.54893")
expect_is(rec, "ZenodoRecord")
expect_equal(rec$conceptdoi, "10.5072/zenodo.523362")
expect_equal(rec$getConceptDOI(), "10.5072/zenodo.54893")
Sys.sleep(5)
})

test_that("get by record DOI",{
rec <- ZENODO$getDepositionByDOI("10.5072/zenodo.523363")
rec <- ZENODO$getDepositionByDOI("10.5072/zenodo.54894")
expect_is(rec, "ZenodoRecord")
expect_equal(rec$conceptdoi, "10.5072/zenodo.523362")
expect_equal(rec$getConceptDOI(), "10.5072/zenodo.54893")
Sys.sleep(5)
})

Expand Down

0 comments on commit 36f7ea1

Please sign in to comment.