Skip to content

Commit

Permalink
update tests/testthat/test-read_from_dhis2_helpers.R
Browse files Browse the repository at this point in the history
  • Loading branch information
Karim-Mane committed Nov 6, 2023
1 parent 527e39d commit 8261d39
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 55 deletions.
49 changes: 8 additions & 41 deletions R/read_from_fingertips-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions R/read_servers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions R/read_servers_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-read_from_dhis2_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-read_from_fingertips-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8261d39

Please sign in to comment.