From 8261d39fd2ebbfc9b6f42cb0717d81029af78cba Mon Sep 17 00:00:00 2001 From: Karim-Mane Date: Mon, 6 Nov 2023 19:20:18 +0000 Subject: [PATCH] update tests/testthat/test-read_from_dhis2_helpers.R --- R/read_from_fingertips-helpers.R | 49 +++---------------- R/read_servers.R | 4 +- R/read_servers_helpers.R | 10 ++-- tests/testthat/test-read_from_dhis2_helpers.R | 3 +- .../test-read_from_fingertips-helpers.R | 10 ++-- 5 files changed, 21 insertions(+), 55 deletions(-) diff --git a/R/read_from_fingertips-helpers.R b/R/read_from_fingertips-helpers.R index 985ebf87..1f45fd8e 100644 --- a/R/read_from_fingertips-helpers.R +++ b/R/read_from_fingertips-helpers.R @@ -43,13 +43,7 @@ get_fingertips_metadata <- function() { #' @keywords internal #' @noRd #' -get_ind_id_from_ind_name <- function(metadata = - list(indicator_profile_domain = - fingertipsR::indicators(), - indicator_ids_names = - fingertipsR::indicators_unique(), - area_type = - fingertipsR::area_types()), +get_ind_id_from_ind_name <- function(metadata, indicator_name = "Pupil absence") { checkmate::assert_list(metadata, len = 3L, null.ok = FALSE, @@ -110,13 +104,7 @@ get_ind_id_from_ind_name <- function(metadata = #' @keywords internal #' @noRd #' -get_ind_id_from_domain_id <- function(metadata = - list(indicator_profile_domain = - fingertipsR::indicators(), - indicator_ids_names = - fingertipsR::indicators_unique(), - area_type = - fingertipsR::area_types()), +get_ind_id_from_domain_id <- function(metadata, domain_id = 1000041L, indicator_name = NULL) { checkmate::assert_list(metadata, @@ -185,14 +173,7 @@ get_ind_id_from_domain_id <- function(metadata = #' @keywords internal #' @noRd #' -get_ind_id_from_domain_name <- function(metadata = - list(indicator_profile_domain = - fingertipsR::indicators(), - indicator_ids_names = - fingertipsR::indicators_unique(), # nolint: line_length_linter - fingertipsR::indicators_unique(), # nolint: line_length_linter - area_type = - fingertipsR::area_types()), +get_ind_id_from_domain_name <- function(metadata, domain_name = "B. Wider determinants of health", # nolint: line_length_linter indicator_name = NULL) { checkmate::assert_list(metadata, @@ -268,14 +249,8 @@ get_ind_id_from_domain_name <- function(metadata = #' } #' @keywords internal #' @noRd -get_profile_name <- function(metadata = - list(indicator_profile_domain = - fingertipsR::indicators(), - indicator_ids_names = - fingertipsR::indicators_unique(), - area_type = - fingertipsR::area_types()), - profile_id = 19L, +get_profile_name <- function(metadata, + profile_id = 19L, profile_name = "Public Health Outcomes Framework") { # nolint: line_length_linter checkmate::assert_list(metadata, len = 3L, null.ok = FALSE, @@ -333,13 +308,7 @@ get_profile_name <- function(metadata = #' } #' @keywords internal #' @noRd -get_ind_id_from_profile <- function(metadata = - list(indicator_profile_domain = - fingertipsR::indicators(), - indicator_ids_names = - fingertipsR::indicators_unique(), - area_type = - fingertipsR::area_types()), +get_ind_id_from_profile <- function(metadata, domain_id = NULL, domain_name = NULL, indicator_name = NULL, @@ -410,8 +379,7 @@ get_ind_id_from_profile <- function(metadata = #' } #' @keywords internal #' @noRd -fingertips_subset_rows <- function(data = readepi(profile_id = 19L, - area_type_id = 202L)[["data"]], # nolint: line_length_linter +fingertips_subset_rows <- function(data, records = c("E92000001", "E12000002", "E12000009"), id_col_name = "AreaCode") { @@ -459,8 +427,7 @@ fingertips_subset_rows <- function(data = readepi(profile_id = 19L, #' } #' @keywords internal #' @noRd -fingertips_subset_columns <- function(data = readepi(profile_id = 19L, - area_type_id = 202L)[["data"]], # nolint: line_length_linter +fingertips_subset_columns <- function(data, fields = c("IndicatorID", "AreaCode", "Age", "Value")) { checkmate::assert_data_frame(data, diff --git a/R/read_servers.R b/R/read_servers.R index 5987a83a..87522cc2 100644 --- a/R/read_servers.R +++ b/R/read_servers.R @@ -108,8 +108,8 @@ sql_server_read_data <- function(dbms = "MySQL", # separate the srcs attributes <- identify_tables_and_queries(src = src, tables = tables) - queries <- attributes[["queries"]] - src <- attributes[["tables"]] + queries <- attributes[["queries"]] + src <- attributes[["tables"]] # fetch data from queries if (length(queries) > 0L) { diff --git a/R/read_servers_helpers.R b/R/read_servers_helpers.R index caf7d637..dc88563e 100644 --- a/R/read_servers_helpers.R +++ b/R/read_servers_helpers.R @@ -64,7 +64,7 @@ connect_to_server <- function(dbms = "MySQL", #' @param query the SQL query #' @param tables the list of all tables from the database #' -#' @return a `character` with the identified tables name(s) from the SQL query +#' @return a `character` with the extracted table name(s) from the SQL query #' #' @examples #' \dontrun{ @@ -175,7 +175,7 @@ fetch_data_from_query <- function(src = "select author_id, name, last_ #' @param port the server port ID #' #' @return a `list` of 1 or more elements of type `data.frame` where every -#' element contains the subset of the data from the corresponding table. +#' element contains the subset of the data from the corresponding table #' @examples #' \dontrun{ #' result <- sql_select_data( @@ -273,7 +273,7 @@ sql_select_data <- function(table_names = "author", #' @param id_position the id position #' #' @returns a `list` of 2 elements of type `character` and `numeric` -#' corresponding to the ID column name and position. +#' corresponding to the ID column name and position #' @keywords internal #' @noRd get_id_column_name <- function(id_col_name = c("author_id", "rfam_acc"), @@ -313,7 +313,7 @@ get_id_column_name <- function(id_col_name = c("author_id", "rfam_acc"), #' @param port the server port ID #' #' @return an object of type `data.frame` with the entire dataset fetched from -#' the specified table. +#' the specified table #' #' @examples #' \dontrun{ @@ -447,7 +447,7 @@ sql_select_records_and_fields <- function(table = "author", #' @param from the table name #' @param driver_name the name of the MS driver #' -#' @return prints the first 5 rows of the specified table. +#' @return prints the first 5 rows of the specified table #' #' @examples #' \dontrun{ diff --git a/tests/testthat/test-read_from_dhis2_helpers.R b/tests/testthat/test-read_from_dhis2_helpers.R index 20a469a6..924feffa 100644 --- a/tests/testthat/test-read_from_dhis2_helpers.R +++ b/tests/testthat/test-read_from_dhis2_helpers.R @@ -17,7 +17,6 @@ httptest::with_mock_api({ test_that("dhis2_login fails as expected", { testthat::skip_on_cran() testthat::skip_if_offline() - testthat::skip_if_not_installed("httptest") expect_error( dhis2_login( base_url = file.path("test", "play.dhis2.org", "dev"), @@ -52,7 +51,7 @@ test_that("dhis2_subset_fields fails as expected", { testthat::skip_on_cran() testthat::skip_if_offline() data <- readepi( - credentials_file = system.file("extdata", "test.ini", package = "readepi"), + credentials_file = system.file("extdata", "test.ini", package = "readepi"), data_source = "https://play.dhis2.org/dev", dataset = "pBOMPrpg1QX,BfMAe6Itzgt", organisation_unit = "DiszpKrYNg8", diff --git a/tests/testthat/test-read_from_fingertips-helpers.R b/tests/testthat/test-read_from_fingertips-helpers.R index 47a60b1d..e90a124e 100644 --- a/tests/testthat/test-read_from_fingertips-helpers.R +++ b/tests/testthat/test-read_from_fingertips-helpers.R @@ -467,13 +467,13 @@ httptest::with_mock_api({ testthat::skip_on_cran() testthat::skip_if_offline() res <- get_profile_name( - profile_id = 19L, - profile_name = "Public Health Outcomes Framework", metadata = list( indicator_profile_domain = fingertipsR::indicators(), - indicator_ids_names = fingertipsR::indicators_unique(), - area_type = fingertipsR::area_types() - ) + indicator_ids_names = fingertipsR::indicators_unique(), + area_type = fingertipsR::area_types() + ), + profile_id = 19L, + profile_name = "Public Health Outcomes Framework" ) expect_type(res, "list") expect_length(res, 2L)