diff --git a/inst/constants.yml b/inst/constants.yml index 5d09bd8..e25bafd 100644 --- a/inst/constants.yml +++ b/inst/constants.yml @@ -1,4 +1,4 @@ server: "demo.dataverse.org" -api_token: "c7208dd2-6ec5-469a-bec5-f57e164888d4" -api_token_expiration: "2021-01-02" -api_token_name: "wibeasley-testing" +api_token: "47441bb5-061c-4a8d-8724-6a1e2fc4aa4d" # readonly +api_token_expiration: "2021-12-30" +api_token_username: "dataverse-client-r-readonly" diff --git a/inst/dataset-basketball/README.md b/inst/dataset-basketball/README.md new file mode 100644 index 0000000..53542b9 --- /dev/null +++ b/inst/dataset-basketball/README.md @@ -0,0 +1,5 @@ +Contents +======= + +* `roster-bulls-1996.csv` downloaded from https://www.basketball-reference.com/. +* `resources/vector-basketball.svg` downloaded from https://svgsilh.com/image/305775.html, licensed under CC-0. diff --git a/inst/dataset-basketball/expected-metadata.yml b/inst/dataset-basketball/expected-metadata.yml new file mode 100644 index 0000000..8957bac --- /dev/null +++ b/inst/dataset-basketball/expected-metadata.yml @@ -0,0 +1,48 @@ +roster: + description: 1734005. Roster of 1996 Bulls, originally in csv + label: roster-bulls-1996.tab + restricted: no + version: 3 + datasetVersionId: 182158 + dataFile: + id: 1734005 + persistentId: doi:10.70122/FK2/HXJVJU/SA3Z2V + pidURL: https://doi.org/10.70122/FK2/HXJVJU/SA3Z2V + filename: roster-bulls-1996.tab + contentType: text/tab-separated-values + filesize: 1138 + description: 1734005. Roster of 1996 Bulls, originally in csv + storageIdentifier: file://176b08c71f5-128de9eea65c + originalFileFormat: text/csv + originalFormatLabel: Comma Separated Values + originalFileSize: 1088 + originalFileName: roster-bulls-1996.csv + UNF: UNF:6:hrleySyT6vzwEih3+nhp8A== + rootDataFileId: -1 + md5: c6feabffac401627b80761c5a1de55f0 + checksum: + type: MD5 + value: c6feabffac401627b80761c5a1de55f0 + creationDate: '2020-12-29' +image: + description: 'ID: 1734006. A svg file' + label: vector-basketball.svg + restricted: no + directoryLabel: resources + version: 2 + datasetVersionId: 182158 + dataFile: + id: 1734006 + persistentId: doi:10.70122/FK2/HXJVJU/FHV8ZB + pidURL: https://doi.org/10.70122/FK2/HXJVJU/FHV8ZB + filename: vector-basketball.svg + contentType: image/svg+xml + filesize: 4055 + description: 'ID: 1734006. A svg file' + storageIdentifier: file://176b0bb8432-080255f28372 + rootDataFileId: -1 + md5: 8038c2efb57dd470e908ae2ad1ff70e0 + checksum: + type: MD5 + value: 8038c2efb57dd470e908ae2ad1ff70e0 + creationDate: '2020-12-29' diff --git a/inst/rosters/vector-basketball.svg b/inst/dataset-basketball/original/resources/vector-basketball.svg similarity index 100% rename from inst/rosters/vector-basketball.svg rename to inst/dataset-basketball/original/resources/vector-basketball.svg diff --git a/inst/rosters/roster-bulls-1996.csv b/inst/dataset-basketball/original/roster-bulls-1996.csv similarity index 100% rename from inst/rosters/roster-bulls-1996.csv rename to inst/dataset-basketball/original/roster-bulls-1996.csv diff --git a/inst/rosters/README.md b/inst/rosters/README.md deleted file mode 100644 index 784bc34..0000000 --- a/inst/rosters/README.md +++ /dev/null @@ -1,5 +0,0 @@ -Contents -======= - -* `roster-bulls-1996.csv` downloaded from https://www.basketball-reference.com/. -* `vector-basketball.svg` downloaded from https://svgsilh.com/image/305775.html, licensed under CC-0. diff --git a/tests/testthat/manual/seed/seed-yaml.R b/tests/testthat/manual/seed/seed-yaml.R new file mode 100644 index 0000000..678442a --- /dev/null +++ b/tests/testthat/manual/seed/seed-yaml.R @@ -0,0 +1,31 @@ +import::from("magrittr", "%>%") +dv <- get_dataverse("dataverse-client-r") +contents <- dataverse_contents(dv) +ds_1 <- dataset_files(contents[[1]]) + +ds_1 %>% + rlang::set_names(c("roster", "image")) %>% + yaml::write_yaml("inst/dataset-basketball/expected-metadata.yml") + +# retrieve-from-file ------------------------------------------------------ +y <- yaml::read_yaml(system.file("dataset-basketball/expected-metadata.yml", package = "dataverse")) + +y$roster + +# Reference: https://jennybc.github.io/purrr-tutorial/ls01_map-name-position-shortcuts.html +ds_expected <- + y %>% + purrr::map_dfr( + magrittr::extract, + c("label", "restricted", "version", "datasetVersionId") + ) + +# This way doesn't require a dplyr dependency +ds_expected <- + data.frame( + label = purrr::map_chr(y, "label"), + restricted = purrr::map_lgl(y, "restricted"), + version = purrr::map_int(y, "version"), + datasetVersionId = purrr::map_int(y, "datasetVersionId") + ) + diff --git a/tests/testthat/tests-dataset_files.R b/tests/testthat/tests-dataset_files.R index 5415c74..eebe9d0 100644 --- a/tests/testthat/tests-dataset_files.R +++ b/tests/testthat/tests-dataset_files.R @@ -5,10 +5,19 @@ test_that("download tab from DOI and filename", { dv <- get_dataverse("dataverse-client-r") contents <- dataverse_contents(dv) actual <- dataset_files(contents[[1]]) + yml <- yaml::read_yaml(system.file("dataset-basketball/expected-metadata.yml", package = "dataverse")) + + ds_expected <- + data.frame( + label = purrr::map_chr(yml, "label"), + restricted = purrr::map_lgl(yml, "restricted"), + version = purrr::map_int(yml, "version"), + datasetVersionId = purrr::map_int(yml, "datasetVersionId") + ) expect_length(actual, 2L) - expect_equal(purrr::map_chr(actual, "label") , c("roster-bulls-1996.tab", "vector-basketball.svg")) - expect_equal(purrr::map_lgl(actual, "restricted") , c(FALSE, FALSE)) - expect_equal(purrr::map_int(actual, "version") , c(3L, 2L)) - expect_equal(purrr::map_int(actual, "datasetVersionId") , c(182158L, 182158L)) + expect_equal(purrr::map_chr(actual, "label") , ds_expected$label) + expect_equal(purrr::map_lgl(actual, "restricted") , ds_expected$restricted) + expect_equal(purrr::map_int(actual, "version") , ds_expected$version) + expect_equal(purrr::map_int(actual, "datasetVersionId") , ds_expected$datasetVersionId) })