Commit 74fb38b1 authored by Petar Horki's avatar Petar Horki

test: splitted test-omopRds.R into multiple files

parent c2d02208
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
context('WebAPI related test files\t')
#====================================================================
test_that("cohorts can be set from external file in folder", {
# read WebAPI url from config file
myFilePath = file.path("../..", "inst", "config.yml")
myWebApiParams <- config::get(file = myFilePath, "WebAPI")
baseUrl <- myWebApiParams$baseURL
jsonFilePath <- file.path("../..", "inst", "json", `_COHORT_TEST_FILE_NAME_`)
# upload json file directly from folder
post <- SetCohortDefinitionFromFile(jsonFilePath=jsonFilePath, baseUrl=baseUrl)
message <- httr::http_status(post)$message
# check http status if uploading was successfull
expect_that(message, equals("Success: (200) OK"))
})
#====================================================================
test_that("cohort can be set from variable", {
# read WebAPI url from config file
myFilePath = file.path("../..", "inst", "config.yml")
myWebApiParams <- config::get(file = myFilePath, "WebAPI")
baseUrl <- myWebApiParams$baseURL
jsonFilePath <- file.path("../..", "inst", "json", `_COHORT_TEST_FILE_NAME_`)
jsonFile <- jsonlite::fromJSON(jsonFilePath)
post <- SetCohortDefinitionFromVariable(jsonFile=jsonFile, baseUrl=baseUrl)
message <- httr::http_status(post)$message
expect_that(message, equals("Success: (200) OK"))
})
#====================================================================
test_that("Concept set can be set from external file in folder", {
myFilePath = file.path("../..", "inst", "config.yml")
myWebApiParams <- config::get(file = myFilePath, "WebAPI")
baseUrl <- myWebApiParams$baseURL
jsonFilePath <- file.path("../..", "inst", "json", `_CONCEPT_SET_TEST_FILE_NAME_`)
myPostJson <- SetConceptSetFromFile(jsonFilePath=jsonFilePath, baseUrl=baseUrl)
message <- httr::http_status(myPostJson)$message
expect_that(message, equals("Success: (200) OK"))
})
#====================================================================
test_that("Concept set can be set from variable", {
# read WebAPI url from config file
myFilePath = file.path("../..", "inst", "config.yml")
myWebApiParams <- config::get(file = myFilePath, "WebAPI")
baseUrl <- myWebApiParams$baseURL
jsonFilePath <- file.path("../..", "inst", "json", `_CONCEPT_SET_TEST_FILE_NAME_`)
jsonFile <- jsonlite::fromJSON(jsonFilePath)
post <- SetConceptSetFromVariable(jsonFile = jsonFile, baseUrl = baseUrl)
message <- httr::http_status(post)$message
expect_that(message, equals("Success: (200) OK"))
})
#====================================================================
test_that("Get concept set", {
myFilePath = file.path("../..", "inst", "config.yml")
myWebApiParams <- config::get(file = myFilePath, "WebAPI")
baseUrl <- myWebApiParams$baseURL
})
#====================================================================
test_that("Cohort definition can be deleted via ID", {
myFilePath = file.path("../..", "inst", "config.yml")
myWebApiParams <- config::get(file = myFilePath, "WebAPI")
baseUrl <- myWebApiParams$baseURL
# clear by deleting all concept sets
DeleteAllCohorts(baseUrl)
jsonFilePath <- file.path("../..", "inst", "json", `_COHORT_TEST_FILE_NAME_`)
jsonFile <- jsonlite::fromJSON(jsonFilePath)
jsonFileName <- jsonFile$name
myPostJson <- SetCohortDefinitionFromVariable(jsonFile = jsonFile, baseUrl = baseUrl)
#dim(GetAllConceptSets(baseUrl))[1]
cohorts <- GetAllCohortDefinitions(baseUrl = baseUrl)
cohortId <- GetIdFromCohortDefinitionName(cohorts = cohorts, name = jsonFileName)
DeleteCohortDefinition(id = cohortId, baseUrl = baseUrl)
countCohorts <- dim(GetAllCohortDefinitions(baseUrl = baseUrl))[1]
expect_that(countCohorts, equals(NULL))
})
#====================================================================
test_that("Concept set definition can be deleted via ID", {
myFilePath = file.path("../..", "inst", "config.yml")
myWebApiParams <- config::get(file = myFilePath, "WebAPI")
baseUrl <- myWebApiParams$baseURL
# clear by deleting all concept sets
DeleteAllConceptSets(baseUrl)
jsonFilePath <- file.path("../..", "inst", "json", `_CONCEPT_SET_TEST_FILE_NAME_`)
jsonFile <- jsonlite::fromJSON(jsonFilePath)
jsonFileName <- jsonFile$name
myPostJson <- SetConceptSetFromVariable(jsonFile = jsonFile, baseUrl = baseUrl)
#dim(GetAllConceptSets(baseUrl))[1]
conceptSets <- GetAllConceptSets(baseUrl = baseUrl)
conceptSetId <- GetIdFromConceptSetDefinitionName(conceptSets = conceptSets, name = jsonFileName)
DeleteConceptSetDefinition(id = conceptSetId, baseUrl = baseUrl)
countConceptSets <- dim(GetAllConceptSets(baseUrl = baseUrl))[1]
expect_that(countConceptSets, equals(NULL))
})
#====================================================================
test_that("All Concept sets can be retrieved at once via WebAPI", {
myFilePath = file.path("../..", "inst", "config.yml")
myWebApiParams <- config::get(file = myFilePath, "WebAPI")
baseUrl <- myWebApiParams$baseURL
# clear by deleting all concept sets
DeleteAllConceptSets(baseUrl)
jsonFilePath <- file.path("../..", "inst", "json", `_CONCEPT_SET_TEST_FILE_NAME_`)
jsonFile <- jsonlite::fromJSON(jsonFilePath)
numberRepetions <- 5
# post test json file multiply times to increase length
for (i in seq(numberRepetions)){
SetConceptSetFromVariable(jsonFile = jsonFile, baseUrl = baseUrl)
}
conceptSets <- GetAllConceptSets(baseUrl = baseUrl)
countConceptSets <- dim(GetAllConceptSets(baseUrl = baseUrl))[1]
expect_that(countConceptSets, equals(numberRepetions))
})
#====================================================================
test_that("All Cohort definitions can be retrieved at once via WebAPI", {
myFilePath = file.path("../..", "inst", "config.yml")
myWebApiParams <- config::get(file = myFilePath, "WebAPI")
baseUrl <- myWebApiParams$baseURL
# clear by deleting all concept sets
DeleteAllCohorts(baseUrl = baseUrl)
jsonFilePath <- file.path("../..", "inst", "json", `_COHORT_TEST_FILE_NAME_`)
jsonFile <- jsonlite::fromJSON(jsonFilePath)
numberRepetions <- 5
# post test json file multiply times to increase length
for (i in seq(numberRepetions)){
SetCohortDefinitionFromVariable(jsonFile = jsonFile, baseUrl = baseUrl)
}
countCohorts <- dim(GetAllCohortDefinitions(baseUrl = baseUrl))[1]
expect_that(countCohorts, equals(numberRepetions))
})
#====================================================================
# test_that("Single Cohort definitions can be retrieved by ID via WebAPI", {
#
# myFilePath = file.path("../..", "inst", "config.yml")
#
# myWebApiParams <- config::get(file = myFilePath, "WebAPI")
#
# baseUrl <- myWebApiParams$baseURL
#
# # clear by deleting all concept sets
# DeleteAllCohorts(baseUrl = baseUrl)
#
# jsonFilePath <- file.path("../..", "inst", "json", `_COHORT_TEST_FILE_NAME_`)
#
# jsonFile <- jsonlite::fromJSON(jsonFilePath)
#
# numberRepetions <- 5
#
# # post test json file multiply times to increase length
# for (i in seq(numberRepetions)){
# SetCohortDefinitionFromVariable(jsonFile = jsonFile, baseUrl = baseUrl)
# }
#
# cohortIds <- GetAllCohortDefinitions(baseUrl = baseUrl)$id
#
# randomId <- as.integer(as.character(sample(cohortIds, size = 1, replace = F)))
#
# cohort <- GetCohortDefinitionFromWebApi(id = randomId, baseUrl = baseUrl)
#
# expect_that(cohort$id, equals(randomId))
#
# expect_that(cohort$name, equals(`_COHORT_TEST_NAME_`))
# })
#====================================================================
test_that("Single concept set definition can be retrieved by ID via Webapi", {
myFilePath = file.path("../..", "inst", "config.yml")
myWebApiParams <- config::get(file = myFilePath, "WebAPI")
baseUrl <- myWebApiParams$baseURL
# clear by deleting all concept sets
DeleteAllCohorts(baseUrl = baseUrl)
jsonFilePath <- file.path("../..", "inst", "json", `_CONCEPT_SET_TEST_FILE_NAME_`)
jsonFile <- jsonlite::fromJSON(jsonFilePath)
numberRepetions <- 5
# post test json file multiply times to increase length
for (i in seq(numberRepetions)){
SetConceptSetFromVariable(jsonFile = jsonFile, baseUrl = baseUrl)
}
conceptSetIds <- GetAllConceptSets(baseUrl = baseUrl)$ID
randomId <- as.integer(as.character(sample(conceptSetIds, size = 1, replace = F)))
conceptSet <- GetConceptSetFromWebApi(id = randomId, baseUrl = baseUrl)
expect_that(conceptSet$id, equals(randomId))
expect_that(conceptSet$name, equals(`_CONCEPT_SET_TEST_NAME_`))
})
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