Skip to content
Snippets Groups Projects
Commit fc3ad40f authored by MORIN Edouard's avatar MORIN Edouard
Browse files

feat: amelioration test. bon pour release.

parent 81526f0d
No related branches found
No related tags found
1 merge request!12Mise en place test + #31
Pipeline #528168 passed
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#' @param ... eventuels autres arguments de la fonction d'ouverture de connexion `connect_to_db` #' @param ... eventuels autres arguments de la fonction d'ouverture de connexion `connect_to_db`
#' @return Un vecteur de caractères avec les tables présentes sur le schéma schema du connecteur con. #' @return Un vecteur de caractères avec les tables présentes sur le schéma schema du connecteur con.
#' @importFrom attempt stop_if_all message_if_none stop_if stop_if_not #' @importFrom attempt stop_if_all message_if_none stop_if stop_if_not
#' @importFrom dplyr arrange select
#' @importFrom DBI dbGetQuery dbDisconnect #' @importFrom DBI dbGetQuery dbDisconnect
#' @importFrom glue glue #' @importFrom glue glue
#' @export #' @export
...@@ -39,8 +40,9 @@ list_tables <- function(con = NULL, schema = NULL, db = NULL, user = NULL, ...) ...@@ -39,8 +40,9 @@ list_tables <- function(con = NULL, schema = NULL, db = NULL, user = NULL, ...)
if(con_a_creer_fermer) { if(con_a_creer_fermer) {
DBI::dbDisconnect(connexion) DBI::dbDisconnect(connexion)
} }
res<- all_tables %>% arrange(table_name)
return(all_tables$table_name) res <- res$table_name
return(res)
} }
......
# poster_data works
Code
list_tables(schema = schem, db = "test_datalibaba", user = "test")
Output
character(0)
---
Code
list_tables(schema = schem, con = con)
Output
character(0)
This diff is collapsed.
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
get_table_comment(table = "test_iris", schema = "public", db = "test_datalibaba", get_table_comment(table = "test_iris", schema = "public", db = "test_datalibaba",
user = "test", server = Sys.getenv("server")) user = "test", server = Sys.getenv("server"))
Output Output
nom_schema nom_table commentaire nom_schema nom_table
1 public test_iris NA 1 public test_iris
commentaire
1 la table de test complete\nCommentaire posté le 27/02/2025, par edouard.morin.
# get_cols_comment works # get_cols_comment works
...@@ -13,12 +15,8 @@ ...@@ -13,12 +15,8 @@
get_cols_comment(table = "test_iris", schema = "public", db = "test_datalibaba", get_cols_comment(table = "test_iris", schema = "public", db = "test_datalibaba",
user = "test", server = Sys.getenv("server")) user = "test", server = Sys.getenv("server"))
Output Output
nom_schema nom_table nom_col commentaire nom_schema nom_table nom_col commentaire
1 public test_iris sepal_length libellé de Sepal.Length cc 1 public test_iris species Commentlibaba !
2 public test_iris sepal_width libellé de Sepal.Width cc
3 public test_iris petal_length libellé de Petal.Length cc
4 public test_iris petal_width libellé de Petal.Width cc
5 public test_iris species Commentlibaba !
# get_table_comments works # get_table_comments works
...@@ -26,11 +24,13 @@ ...@@ -26,11 +24,13 @@
get_table_comments(table = "test_iris", schema = "public", db = "test_datalibaba", get_table_comments(table = "test_iris", schema = "public", db = "test_datalibaba",
user = "test", server = Sys.getenv("server")) user = "test", server = Sys.getenv("server"))
Output Output
nom_schema nom_table commentaire nom_col nom_schema nom_table
1 public test_iris NA <NA> 1 public test_iris
2 public test_iris libellé de Sepal.Length cc sepal_length 2 public test_iris
3 public test_iris libellé de Sepal.Width cc sepal_width commentaire
4 public test_iris libellé de Petal.Length cc petal_length 1 la table de test complete\nCommentaire posté le 27/02/2025, par edouard.morin.
5 public test_iris libellé de Petal.Width cc petal_width 2 Commentlibaba !
6 public test_iris Commentlibaba ! species nom_col
1 <NA>
2 species
...@@ -5,6 +5,7 @@ library(lubridate) ...@@ -5,6 +5,7 @@ library(lubridate)
library(dplyr) library(dplyr)
library(sf) library(sf)
library(glue) library(glue)
library(backports)
test_that("poster_data works", { test_that("poster_data works", {
if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){ if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){
...@@ -13,6 +14,32 @@ test_that("poster_data works", { ...@@ -13,6 +14,32 @@ test_that("poster_data works", {
Sys.setenv(user_test="runner") Sys.setenv(user_test="runner")
Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD"))
# test list_tables (utilise dans poster_data)
schem <- paste0("test_listdata_",sample.int(1000, 1))
condirect <- DBI::dbConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="test_datalibaba")
DBI::dbExecute(condirect, paste0("CREATE SCHEMA ",schem," AUTHORIZATION runner;"))
DBI::dbExecute(condirect, paste0("GRANT ALL ON SCHEMA ",schem," TO runner WITH GRANT OPTION;"))
DBI::dbExecute(condirect, paste0("ALTER DEFAULT PRIVILEGES IN SCHEMA ",schem," GRANT ALL ON TABLES TO runner;"))
DBI::dbExecute(condirect, paste0("ALTER DEFAULT PRIVILEGES IN SCHEMA ",schem," GRANT ALL ON SEQUENCES TO runner;"))
expect_snapshot(list_tables(schema = schem, db = "test_datalibaba", user = "test"))
con<<-connect_to_db(db = 'test_datalibaba', user = 'test')
expect_snapshot(list_tables(schema = schem, con = con))
}else{
print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres"))
print('warning: connect_to_db - local database postgresql doesnt work !')
expect_equal(1,1)
}
})
test_that("poster_data works", {
if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){
Sys.setenv(port="5432")
Sys.setenv(server="localhost")
Sys.setenv(user_test="runner")
Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD"))
#tests poster_data
expect_error(poster_data(table = "test_iris", schema = "public", db = "test_datalibaba", expect_error(poster_data(table = "test_iris", schema = "public", db = "test_datalibaba",
pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"), pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"),
"'data' n\'est pas renseign\u00e9") "'data' n\'est pas renseign\u00e9")
...@@ -30,10 +57,14 @@ test_that("poster_data works", { ...@@ -30,10 +57,14 @@ test_that("poster_data works", {
"table n\'est pas renseign\u00e9") "table n\'est pas renseign\u00e9")
# test création schema, post_row_name, ecoSQL, pk et overwrite # test création schema, post_row_name, ecoSQL, pk et overwrite
schem <- paste0("test_",sample.int(1000, 1),"_",sample.int(1000, 1)) schem <- paste0("test_",sample.int(1000, 1),"_",sample.int(1000, 1))
expect_warning(poster_data(data = iris, table = "test_iris", schema = schem, db = "test_datalibaba", pk = NULL, post_row_name = TRUE, overwrite = TRUE, user = "test"), expect_warning(poster_data(data = iris, table = "test_iris", schema = schem, db = "test_datalibaba", pk = NULL, post_row_name = TRUE, overwrite = TRUE, user = "test"),
paste0("le schema ",schem," n\\'existe pas\\. Il va être créé sous test_datalibaba\\.")) paste0("le schema ",schem," n\\'existe pas\\. Il va être créé sous test_datalibaba\\."))
df<-iris %>% rownames_to_column("id") %>% mutate(todate = now(tzone = "UTC"))
df<-iris %>% rownames_to_column("id") %>% mutate(todate = parse_date_time("2025-02-27 14:29:32", "Ymd HMS"))
expect_message(poster_data(data = df, table = "test_iris", schema = "public", db = "test_datalibaba", pk = "id", post_row_name = TRUE, overwrite = TRUE, user = "test", ecoSQL = FALSE), expect_message(poster_data(data = df, table = "test_iris", schema = "public", db = "test_datalibaba", pk = "id", post_row_name = TRUE, overwrite = TRUE, user = "test", ecoSQL = FALSE),
"\u00e9crit dans la table ") "\u00e9crit dans la table ")
expect_message(poster_data(data = df, table = "test_iris", schema = "public", db = "test_datalibaba", pk = 1, post_row_name = TRUE, overwrite = TRUE, user = "test"), expect_message(poster_data(data = df, table = "test_iris", schema = "public", db = "test_datalibaba", pk = 1, post_row_name = TRUE, overwrite = TRUE, user = "test"),
...@@ -46,7 +77,6 @@ test_that("poster_data works", { ...@@ -46,7 +77,6 @@ test_that("poster_data works", {
expect_message(poster_data(data = nc, table = "nc", schema = "public", db = "test_datalibaba", pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"), expect_message(poster_data(data = nc, table = "nc", schema = "public", db = "test_datalibaba", pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"),
"\u00e9crit dans la table ") "\u00e9crit dans la table ")
}else{ }else{
print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres"))
print('warning: connect_to_db - local database postgresql doesnt work !') print('warning: connect_to_db - local database postgresql doesnt work !')
...@@ -100,7 +130,7 @@ test_that("post_data_dbi works", { ...@@ -100,7 +130,7 @@ test_that("post_data_dbi works", {
Sys.setenv(user_test="runner") Sys.setenv(user_test="runner")
Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD")) Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD"))
con<<-connect_to_db(db = 'test_datalibaba', user = 'test', ecoSQL = FALSE) con<<-connect_to_db(db = 'test_datalibaba', user = 'test', ecoSQL = FALSE)
expect_message(post_data_dbi(con, data = iris, schema = "public", table = "retest_iris", overwrite = TRUE), expect_message(suppressWarnings(post_data_dbi(con, data = iris, schema = "public", table = "retest_iris", overwrite = TRUE)),
" est \u00e9cras\u00e9e sur le schema ") " est \u00e9cras\u00e9e sur le schema ")
}else{ }else{
print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres"))
......
...@@ -48,9 +48,6 @@ test_that("importer_data works", { ...@@ -48,9 +48,6 @@ test_that("importer_data works", {
expect_snapshot(importer_data(table = "test_nc_noid", schema = "public", db = "test_datalibaba", user = "test", limit = 4)) expect_snapshot(importer_data(table = "test_nc_noid", schema = "public", db = "test_datalibaba", user = "test", limit = 4))
#A FINIR !!! #A FINIR !!!
#test list_tables
expect_snapshot(list_tables(schema = "public", db = "test_datalibaba", user = "test"))
}else{ }else{
print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")) print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres"))
print('warning: connect_to_db - local database postgresql doesnt work !') print('warning: connect_to_db - local database postgresql doesnt work !')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment