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

Création des tests pour insert_into_table()

parent 056ac042
No related branches found
No related tags found
4 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()
Pipeline #537536 passed
...@@ -87,6 +87,7 @@ usethis::use_r("import_and_merge_tables") ...@@ -87,6 +87,7 @@ 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")
usethis::use_r("insert_into_table")
usethis::use_r("modify_column_type") usethis::use_r("modify_column_type")
usethis::use_r("remove_special_chars") usethis::use_r("remove_special_chars")
usethis::use_r("rename_field") usethis::use_r("rename_field")
...@@ -110,6 +111,7 @@ usethis::use_test("import_and_merge_tables") ...@@ -110,6 +111,7 @@ 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")
usethis::use_test("insert_into_table")
usethis::use_test("modify_column_type") usethis::use_test("modify_column_type")
usethis::use_test("remove_special_chars") usethis::use_test("remove_special_chars")
usethis::use_test("rename_field") usethis::use_test("rename_field")
......
test_that("insert_into_table works", {
Sys.setenv(user_runner="runner")
Sys.setenv(pwd_runner=Sys.getenv("BDD_RUNNER_PWD"))
# Création d'un dataframe fictif
source <- data.frame(
id = 6:10,
name = c("Alice", "Bob", "Charlie", "David", "Eve"),
birthdate = c("1990-01-15", "1985-06-22", "1992-09-10", "1988-03-05", "1995-12-30"),
value = rnorm(5)
)
# 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 = "1:5",
role = "runner")
expect_equal(object = insert_into_table(host = "localhost", database = "collectr",
schema = "public", table = "target",
dataframe = source, role = "runner"),
expected = 5)
expect_error(object = insert_into_table(host = "localhost", database = "collectr",
schema = "public", table = "ghost",
dataframe = source, role = "runner"),
regexp = "La table sp\u00e9cifi\u00e9e n\'existe pas dans la base de donn\u00e9es.")
# Création d'un dataframe avec une structure différente de la table
df <- data.frame(id = 1:5, name = letters[1:5], value = rnorm(5))
# 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 = "1:5",
role = "runner")
expect_false(insert_into_table(host = "localhost", database = "collectr",
schema = "public", table = "target",
dataframe = df, role = "runner"))
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment