Commit 75094c44 authored by Pauline Maury Laribière's avatar Pauline Maury Laribière
Browse files

addind unittest

parent 47f4f161
Pipeline #272487 passed with stage
in 3 minutes and 1 second
......@@ -28,7 +28,7 @@ library("fso.metadata")
## Code list
```{r codelist, echo=FALSE}
get_codelist(identifier='CL_NOGA_SECTION')
get_codelist(identifier='CL_NOGA_SECTION', language='de')
```
......@@ -48,9 +48,14 @@ my_filters <- hash::hash(
```{r , echo=FALSE}
get_nomenclature_one_level(identifier='HCL_CH_ISCO_19_PROF', filters=my_filters, level_number=2)
res <- get_nomenclature_one_level(identifier='HCL_CH_ISCO_19_PROF', filters=my_filters, level_number=2, language='fr')
names(res)
```
```{r , echo=FALSE}
get_nomenclature_multiple_levels(identifier='HCL_CH_ISCO_19_PROF', filters=my_filters, level_from=2, level_to=5)
res <- get_nomenclature_multiple_levels(identifier='HCL_CH_ISCO_19_PROF', filters=my_filters, level_from=2, level_to=5, language='de')
res
```
......@@ -20,5 +20,6 @@ Imports:
httr,
jsonlite,
methods,
rsdmx
rsdmx,
testthat
RoxygenNote: 7.1.1
......@@ -10,7 +10,7 @@
#' @return response based on the export format
#' @export
get_codelist <- function(identifier,
language = "en",
language = "fr",
export_format = "SDMX-ML",
version_format = 2.1,
annotations = FALSE) {
......@@ -32,7 +32,7 @@ get_codelist <- function(identifier,
#'
#' @return data structure
#' @export
get_data_structure <- function(identifier, language = "en") {
get_data_structure <- function(identifier, language = "fr") {
api <- api_class(
api_type = "dcat_data_structure",
id = identifier,
......@@ -55,11 +55,16 @@ get_data_structure <- function(identifier, language = "en") {
#' (Code, Parent and Name in the selected language)
#' @export
get_nomenclature_one_level <- function(identifier,
filters,
filters=hash::hash(),
level_number = 1,
language = "en",
language = "fr",
annotations = FALSE) {
parameters <- glue::glue("language={language}&level={level_number}&annotations={tolower(annotations)}&{hash_to_string(filters)}")
parameters <- glue::glue(
"language={language}",
"&level={level_number}",
"&annotations={tolower(annotations)}",
"&{hash_to_string(filters)}"
)
print(parameters)
api <- api_class(
api_type = "nomenclature_one_level",
......@@ -85,12 +90,18 @@ get_nomenclature_one_level <- function(identifier,
#' from `level_from` to `level_to` codes
#' @export
get_nomenclature_multiple_levels <- function(identifier,
filters,
filters=hash::hash(),
level_from = 1,
level_to = 2,
language = "en",
language = "fr",
annotations = FALSE) {
parameters <- glue::glue("language={language}&levelFrom={level_from}&levelTo={level_to}&annotations={tolower(annotations)}&{hash_to_string(filters)}")
parameters <- glue::glue(
"language={language}",
"&levelFrom={level_from}",
"&levelTo={level_to}",
"&annotations={tolower(annotations)}",
"&{hash_to_string(filters)}"
)
api <- api_class(
api_type = "nomenclature_multiple_levels",
id = identifier,
......
......@@ -6,7 +6,7 @@
#' Available are CSV, XLSX, SDMX-ML and JSON
#' @field parameters character. Additional request parameters
#' @field id character. The identifier or id of the request's object
#' @field language character (default = "en"). The language of the response data.
#' @field language character (default = "en"). Language of the response data.
#' Available are 'fr', 'de', 'it', 'en'
#' @field version_format numeric (default = 2.1). The export format's version
#' (2.0 or 2.1 when format is SDMX-ML)
......
test_that("hash_to_string", {
expect_equal(
hash_to_string(hash::hash("a" = list("1"), "b" = list("2", "3"))),
"a=1&b=2&b=3"
)
})
test_that("nomenclature_one_level", {
expect_equal(
names(get_nomenclature_one_level(
identifier='HCL_CH_ISCO_19_PROF',
level_number=2,
language='fr')
),
c("Code", "Parent", "Name_fr")
)
})
test_that("nomenclature_multiple_levels", {
expect_equal(
names(
get_nomenclature_multiple_levels(
identifier='HCL_CH_ISCO_19_PROF',
level_from=1,
level_to=6,
language='en'
)
),
c(
"Major_groups",
"Sub.major_groups",
"Minor_groups",
"Unit_groups",
"Type",
"Occupations",
"Code",
"Name_en"
)
)
})
......@@ -10,5 +10,6 @@ library(httr)
library(jsonlite)
library(rsdmx)
# pkgload::load_all('my_package')
# styler::style_pkg('my_package')
\ No newline at end of file
# pkgload::load_all('fso.metadata')
# styler::style_pkg('fso.metadata')
# testthat::test_file("fso.metadata/tests/testthat.R")
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment