Skip to content
Snippets Groups Projects
Commit f668a4fb authored by ronan.vignard's avatar ronan.vignard
Browse files

Création des tests pour import_and_merge_tables()

parent f9fa860e
No related branches found
No related tags found
5 merge requests!67Passage en version 0.1.6,!66Intégration de la fonction download_files_from_list(),!65Correction d'un bug + création des tests pour fix_encoding_variable(),!64Création des tests pour insert_into_table(),!63Ajout des tests pour import_and_merge_tables() + adaptation de create_dummy()
...@@ -83,6 +83,7 @@ usethis::use_r("download_and_extract_wfs") ...@@ -83,6 +83,7 @@ usethis::use_r("download_and_extract_wfs")
usethis::use_r("format_colnames") usethis::use_r("format_colnames")
usethis::use_r("format_filepath") usethis::use_r("format_filepath")
usethis::use_r("get_variable_completion_rate") usethis::use_r("get_variable_completion_rate")
usethis::use_r("import_and_merge_tables")
usethis::use_r("import_geopackage") usethis::use_r("import_geopackage")
usethis::use_r("import_shapefile") usethis::use_r("import_shapefile")
usethis::use_r("import_xlsx") usethis::use_r("import_xlsx")
...@@ -105,6 +106,7 @@ usethis::use_test("download_and_extract_wfs") ...@@ -105,6 +106,7 @@ usethis::use_test("download_and_extract_wfs")
usethis::use_test("format_colnames") usethis::use_test("format_colnames")
usethis::use_test("format_filepath") usethis::use_test("format_filepath")
usethis::use_test("get_variable_completion_rate") usethis::use_test("get_variable_completion_rate")
usethis::use_test("import_and_merge_tables")
usethis::use_test("import_geopackage") usethis::use_test("import_geopackage")
usethis::use_test("import_shapefile") usethis::use_test("import_shapefile")
usethis::use_test("import_xlsx") usethis::use_test("import_xlsx")
......
test_that("import_and_merge_tables works", {
Sys.setenv(user_runner="runner")
Sys.setenv(pwd_runner=Sys.getenv("BDD_RUNNER_PWD"))
# Créer une table source dans le schéma public de la base collectr
create_dummy(host = "localhost",
database = "collectr",
schema = "public",
table = "source",
pk = "id",
role = "runner")
# Créer une table target dans le schéma public de la base collectr
create_dummy(host = "localhost",
database = "collectr",
schema = "public",
table = "target",
pk = "id",
id_range = "6:10",
role = "runner")
expect_true(import_and_merge_tables(
host = "localhost",
database = "collectr",
source_table = "source",
source_schema = "public",
target_table = "target",
target_schema = "public",
role = "runner"
))
})
test_that("import_and_merge_tables fails", {
Sys.setenv(user_runner="runner")
Sys.setenv(pwd_runner=Sys.getenv("BDD_RUNNER_PWD"))
# Créer une table source dans le schéma public de la base collectr
create_dummy(host = "localhost",
database = "collectr",
schema = "public",
table = "source",
pk = "id",
role = "runner")
# Créer une table target dans le schéma public de la base collectr
create_dummy(host = "localhost",
database = "collectr",
schema = "public",
table = "target",
pk = "id",
id_range = "6:10",
role = "runner")
expect_error(import_and_merge_tables(
host = "localhost",
database = "collectr",
source_table = "ghost",
source_schema = "public",
target_table = "target",
target_schema = "public",
role = "runner"
), "La table source sp\u00e9cifi\u00e9e n\'existe pas dans la base de donn\u00e9es.")
expect_error(import_and_merge_tables(
host = "localhost",
database = "collectr",
source_table = "source",
source_schema = "public",
target_table = "ghost",
target_schema = "public",
role = "runner"
), "La table cible sp\u00e9cifi\u00e9e n\'existe pas dans la base de donn\u00e9es.")
skip_on_ci()
mockery::stub(import_and_merge_tables, "datalibaba::connect_to_db", function(...) "InvalidConnection")
expect_error(import_and_merge_tables(
host = "localhost",
database = "collectr",
source_table = "source",
source_schema = "public",
target_table = "target",
target_schema = "public",
role = "runner"
), "La connexion fournie n\'est pas une connexion PostgreSQL valide.")
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment