Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 12-ajouter-warning-si-nom-de-table-postee-trop-long
  • dev
  • master
  • 0.0.0.9001
  • 0.0.0.9002
  • 0.0.0.9004
  • 0.0.0.9008
  • 0.0.0.9009
  • 0.0.0.9010
9 results

Target

Select target project
  • dreal-pdl/csd/datalibaba
1 result
Select Git revision
  • 12-ajouter-warning-si-nom-de-table-postee-trop-long
  • dev
  • master
  • 0.0.0.9001
  • 0.0.0.9002
  • 0.0.0.9004
  • 0.0.0.9008
  • 0.0.0.9009
  • 0.0.0.9010
9 results
Show changes
Showing
with 1453 additions and 1 deletion
......@@ -4,7 +4,7 @@
\alias{poster_data}
\title{Chargement d'un dataset sur le serveur avec rpostgis. Par rapport aux autres fonctions \code{post_data()}, \code{post_data_pg()} ouvre et ferme la connexion au SGBD, gere les dataframes spatiaux et les facteurs, et poste quelques metadonnees en commentaire de la table.}
\source{
{rpostgis} http://mablab.org/rpostgis/
\\{rpostgis}\\ http://mablab.org/rpostgis/
}
\usage{
poster_data(
......
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html
library(testthat)
library(datalibaba)
test_check("datalibaba")
# 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.
# get_db_comment works
Code
get_db_comment(db = "test_datalibaba", user = "test", server = Sys.getenv(
"server"))
Output
[1] nom_base commentaire
<0 rows> (or 0-length row.names)
# get_schema_comment works
Code
get_schema_comment(schema = "public", db = "test_datalibaba", user = "test",
server = Sys.getenv("server"))
Output
nom_schema commentaire
1 public le schema des tests qui restent !
# get_cols_comment works
Code
get_cols_comment(table = "test_iris", schema = "public", db = "test_datalibaba",
user = "test", server = Sys.getenv("server"))
Output
nom_schema nom_table nom_col commentaire
1 public test_iris species Commentlibaba !
# get_table_comments works
Code
get_table_comments(table = "retest_iris", schema = "public", db = "test_datalibaba",
user = "test", server = Sys.getenv("server"))
Output
nom_schema nom_table commentaire nom_col
1 public retest_iris <NA> <NA>
2 public retest_iris libellé de Sepal.Length cc Sepal.Length
3 public retest_iris libellé de Sepal.Width cc Sepal.Width
4 public retest_iris libellé de Petal.Length cc Petal.Length
5 public retest_iris libellé de Petal.Width cc Petal.Width
6 public retest_iris libellé de Species cc Species
# get_table_comment works
Code
get_table_comment(table = "retest_iris", schema = "public", db = "test_datalibaba",
user = "test", server = Sys.getenv("server"))
Output
nom_schema nom_table commentaire
1 public retest_iris <NA>
library(DBI)
library(odbc)
library(glue)
test_that("connect_to_db 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"))
expect_true(identical(class(connect_to_db(db = "test_datalibaba", user = "test", ecoSQL = FALSE))[[1]], "PostgreSQLConnection"))
con<- DBI::dbConnect(DBI::dbDriver("PostgreSQL"),
dbname="test_datalibaba",
host=Sys.getenv("server"),
port=Sys.getenv("port"),
user=Sys.getenv("user_test"),
password=Sys.getenv("pwd_test"))
expect_equal(
str(connect_to_db(db = "test_datalibaba", user = "test", ecoSQL = FALSE)),
str(con)
)
expect_true(identical(class(connect_to_db(db = "test_datalibaba", user = "test"))[[1]], "PqConnection"))
con<- DBI::dbConnect(RPostgres::Postgres(),
dbname="test_datalibaba",
host=Sys.getenv("server"),
port=Sys.getenv("port"),
user=Sys.getenv("user_test"),
password=Sys.getenv("pwd_test"))
expect_equal(
str(connect_to_db(db = "test_datalibaba", user = "test")),
str(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("connect_to_dbi works", {
listdriver<-odbc::odbcListDrivers()
print("test connect_to_dbi : list driver odbc")
print(listdriver)
Sys.setenv(port="5432")
Sys.setenv(server="127.0.0.1")
Sys.setenv(user_test="runner")
Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD"))
patterndriver <-"^Postgre.*UNICODE|Unicode.*"
drv_unicode_postgres <- listdriver$name[grep(patterndriver, listdriver$name)][1]
con_chaine <- glue::glue("Driver={",drv_unicode_postgres,"};Server=$Sys.getenv('server')$;Database=test_datalibaba;Uid=$Sys.getenv('user_test')$;Pwd=$Sys.getenv('pwd_test')$;Port=$Sys.getenv('port')$;",
.open = "$",
.close= "$")
if(DBI::dbCanConnect(odbc::odbc(), .connection_string = con_chaine, timeout = 10, encoding = "UTF-8")){
expect_error(connect_to_dbi(db = "test_datalibaba", user = "test", driver="Mysql"),
"The driver must be NULL or 'PostgreSQL'")
expect_error(connect_to_dbi(db = "test_datalibaba", user = "test", driver=NULL),
"alert: Pas de driver Postgresql pour ODBC")
expect_true(identical(class(connect_to_dbi(db = "test_datalibaba", user = "test"))[[1]], "PostgreSQL"))
con <- DBI::dbConnect(odbc::odbc(),
.connection_string = con_chaine,
timeout = 10,
encoding = "UTF-8")
expect_equal(
str(connect_to_dbi(db = "test_datalibaba", user = "test")),
str(con)
)
}else{
print(DBI::dbCanConnect(odbc::odbc(), .connection_string = con_chaine, timeout = 10, encoding = "UTF-8"))
print('warning: connect_to_dbi - local database postgresql doesnt work with odbc !')
expect_equal(1,1)
}
})
library(fs)
test_that("scoped_path_r works", {
expect_error(scoped_path_r(scope="other"),
"'arg' should be one of")
Sys.setenv(R_ENVIRON_USER="~")
res<-fs::path_expand("~")
expect_equal(scoped_path_r("user", envvar = "R_ENVIRON_USER"), res)
res<-fs::path(usethis::proj_get(), "README.md")
expect_equal(scoped_path_r("project", "README.md"),res)
})
test_that("check_server_renviron works", {
Sys.setenv(R_ENVIRON_USER="~/test-toto")
expect_message(check_server_renviron(),
paste0("x .Renviron : le fichier ",scoped_path_r("user", ".Renviron", envvar = "R_ENVIRON_USER")," n'existe pas"))
Sys.setenv(R_ENVIRON_USER="~")
if (.Platform$OS.type != "windows" & !file.exists(scoped_path_r("user", ".Renviron", envvar = "R_ENVIRON_USER"))) {
file.create(scoped_path_r("user", ".Renviron", envvar = "R_ENVIRON_USER"))
}
Sys.setenv(server="")
Sys.setenv(port="")
Sys.setenv(user_does="")
Sys.setenv(pwd_does="")
expect_message(check_server_renviron(), paste0("i v\u00e9rification de la configuration des variables syst\u00e8me \u00e0 l'adresse ",scoped_path_r("user", ".Renviron", envvar = "R_ENVIRON_USER"),"."))
expect_message(check_server_renviron(), "* .Renviron : la variable server n'est pas d\u00e9finie.")
expect_message(check_server_renviron(), "* .Renviron : la variable port n'est pas d\u00e9finie.")
expect_message(check_server_renviron(), "* .Renviron : la variable user_does n'est pas d\u00e9finie.")
expect_message(check_server_renviron(), "* .Renviron : la variable pwd_does n'est pas d\u00e9finie.")
Sys.setenv(server="127.0.0.1")
Sys.setenv(port="5432")
Sys.setenv(user_does="runner")
Sys.setenv(pwd_does=Sys.getenv("BDD_RUNNER_PWD"))
expect_message(check_server_renviron(), paste0("v .Renviron : la variable server est d\u00e9finie avec la valeur ",Sys.getenv('server')))
expect_message(check_server_renviron(), paste0("v .Renviron : la variable port est d\u00e9finie avec la valeur ",Sys.getenv('port')))
expect_message(check_server_renviron(), paste0("v .Renviron : la variable user_does est d\u00e9finie avec la valeur ",Sys.getenv('user_does')))
expect_message(check_server_renviron(), paste0("v .Renviron : la variable pwd_does est d\u00e9finie avec la valeur ",Sys.getenv('pwd_does')))
})
test_that("standard_var_pg works", {
expect_equal(standard_var_pg("%Nom@fichier$test8pour(standard_var_pg!"),
"_nom_fichier_test8pour_standard_var_pg_")
})
library(DBI)
library(magrittr)
library(tibble)
library(lubridate)
library(dplyr)
library(sf)
library(glue)
library(backports)
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"))
# 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",
pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"),
"'data' n\'est pas renseign\u00e9")
expect_error(poster_data(data=c(1,2,3), table = "test_iris", schema = "public", db = "test_datalibaba",
pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"),
"le dataframe 'data' n\'exsiste pas")
expect_error(poster_data(data = iris, table = "test_iris", schema = "public", db = "test_datalibaba",
pk = "Speciez", post_row_name = FALSE, overwrite = TRUE, user = "test"),
"mauvaise declaration de pk : doit etre 1 ou NULL ou un nom de variable de 'data' ou un vecteur de noms de variables de 'data'")
expect_error(poster_data(data = iris, table = "test_iris", db = "test_datalibaba",
pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"),
"schema n\'est pas renseign\u00e9")
expect_error(poster_data(data = iris, schema = "public", db = "test_datalibaba",
pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"),
"table n\'est pas renseign\u00e9")
# test création schema, post_row_name, ecoSQL, pk et overwrite
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"),
paste0("le schema ",schem," n\\'existe pas\\. Il va être créé sous test_datalibaba\\."))
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),
"\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"),
"\u00e9crit dans la table ")
expect_error(poster_data(data = iris, table = "test_iris", schema = schem, db = "test_datalibaba", pk = NULL, post_row_name = FALSE, overwrite = FALSE, user = "test"),
paste0("La table test_iris existe d\u00e9j\u00e0 sur le schema ",schem," et le param\u00e8tre overwrite est \u00e0 FALSE"))
# test geometry
nc <- st_read(system.file("shape/nc.shp", package="sf"))
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 ")
}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("post_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"))
expect_error(post_data(con=NULL, data = iris, schema = "public", table = "test_iris", overwrite = FALSE),
"con n\'est pas renseign\u00e9")
expect_error(post_data(con=connect_to_db(db = 'test_datalibaba', user = 'test'), data = iris, schema = "public", table = "test_iris", overwrite = FALSE),
"le connecteur con n\'existe pas dans l\'environnement")
con<<-connect_to_db(db = 'test_datalibaba', user = 'test')
expect_error(post_data(con=con, data = iris, schema = "public", table = "test_iris", overwrite = FALSE),
"veuillez utiliser une connexion avec ecoSQL=FALSE")
con<<-connect_to_db(db = 'test_datalibaba', user = 'test', ecoSQL = FALSE)
expect_error(post_data(con=con, schema = "public", table = "test_iris", overwrite = FALSE),
"data n\'est pas renseign\u00e9")
expect_error(post_data(con=con, data=c(1), schema = "public", table = "test_iris", overwrite = FALSE),
glue::glue("le dataframe 1 n\'exsiste pas"))
expect_error(post_data(con=con, data = iris, table = "test_iris", overwrite = FALSE),
"schema n\'est pas renseign\u00e9")
expect_error(post_data(con=con, data = iris, schema = "public", overwrite = FALSE),
"table n\'est pas renseign\u00e9")
expect_error(post_data(con=con, data = iris, schema = "titi-test", table = "test_iris", overwrite = FALSE),
glue::glue("le schema titi-test n\'existe pas"))
post_data(con, data = iris, schema = "public", table = "retest_iris", overwrite = TRUE)
expect_error(post_data(con, data = iris, schema = "public", table = "retest_iris", overwrite = FALSE),
paste0("La table retest_iris existe d\u00e9j\u00e0 sur le schema public et le param\u00e8 tre overwrite est \u00e0 FALSE"))
expect_message(post_data(con, data = iris, schema = "public", table = "retest_iris", overwrite = TRUE),
" est \u00e9cras\u00e9e sur le schema ")
}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("post_data_dbi 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"))
con<<-connect_to_db(db = 'test_datalibaba', user = 'test', ecoSQL = FALSE)
expect_message(suppressWarnings(post_data_dbi(con, data = iris, schema = "public", table = "retest_iris", overwrite = TRUE)),
" est \u00e9cras\u00e9e sur le schema ")
}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)
}
})
library(DBI)
library(magrittr)
library(tibble)
library(lubridate)
library(dplyr)
library(sf)
library(glue)
library(backports)
library(withr)
test_that("importer_data no geo 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"))
expect_error(importer_data(schema = "public", db = "test_datalibaba", user = "test"),
"l'argument table n'est pas renseign\u00e9")
expect_error(importer_data(table = "test_iris", db = "test_datalibaba", user = "test"),
"l'argument schema n'est pas renseign\u00e9")
expect_error(importer_data(table = "test_iris", schema = "public", db = NULL, user = "test"),
"l'argument db n'est pas renseign\u00e9")
expect_error(importer_data(table = "test_iris", schema = "public", db = "test_datalibaba", user = NULL),
"l'argument user n'est pas renseign\u00e9")
expect_error(importer_data(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", limit="d"),
"l'argument limit n'est pas num\u00e9rique")
expect_error(importer_data(table = "titi-test", schema = "public", db = "test_datalibaba", user = "test"),
paste0("La table 'public'.'titi-test' est introuvable."))
# test avec création schema sans table de propriétés
schem <- paste0("test_",sample.int(1000, 1),"_",sample.int(1000, 1))
suppressWarnings(poster_data(data = iris, table = "test_iris", schema = schem, db = "test_datalibaba", pk = NULL, post_row_name = FALSE, overwrite = TRUE, user = "test"))
condirect <- DBI::dbConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="test_datalibaba")
DBI::dbExecute(condirect, paste0("DELETE FROM ",schem,".zz_r_df_def;"))
expect_message(importer_data(table = "test_iris", schema = schem, db = "test_datalibaba", user = "test"),
paste0("Pas de renseignements trouv\u00e9 sur test_iris dans la table des propri\u00e9t\u00e9s des dataframes R, un import standard sera r\u00e9alis\u00e9. "))
DBI::dbExecute(condirect, paste0("DROP TABLE IF EXISTS ",schem,".zz_r_df_def CASCADE;"))
expect_message(importer_data(table = "test_iris", schema = schem, db = "test_datalibaba", user = "test"),
"La table de propri\u00e9t\u00e9s des dataframes R est introuvable, un import standard sera r\u00e9alis\u00e9. ")
# test basic
expect_snapshot(importer_data(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", limit = 4, ecoSQL = FALSE))
}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("importer_data geo works", {
withr::local_options(lifecycle_verbosity = "quiet")
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"))
# test geometry # pas pris en compte dans le coverage... pourquoi ??
expect_snapshot(importer_data(table = "nc", schema = "public", db = "test_datalibaba", user = "test"))
expect_snapshot(importer_data(table = "nc", schema = "public", db = "test_datalibaba", user = "test", limit = 4))
nc <- st_read(system.file("shape/nc.shp", package="sf"))
poster_data(data = nc, table = "test_nc_noid", schema = "public", db = "test_datalibaba", pk = "CNTY_ID", post_row_name = FALSE, overwrite = TRUE, user = "test")
expect_snapshot(importer_data(table = "test_nc_noid", schema = "public", db = "test_datalibaba", user = "test", limit = 4))
#A FINIR !!!
}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("get_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"))
expect_error(get_data(con=NULL, schema = "public", table = "test_iris"),
"con n\'est pas renseign\u00e9")
con<<-connect_to_db(db = 'test_datalibaba', user = 'test')
expect_error(get_data(con=con, schema = "public", table = "test_iris"),
"veuillez utiliser une connexion avec ecoSQL=FALSE")
con<<-connect_to_db(db = 'test_datalibaba', user = 'test', ecoSQL = FALSE)
expect_error(get_data(con=con, table = "test_iris"),
"schema n\'est pas renseign\u00e9")
expect_error(get_data(con=con, schema = "public"),
"table n\'est pas renseign\u00e9")
expect_snapshot(get_data(con=con, schema = "public", table = "test_iris"))
}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("get_data_dbi 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"))
expect_error(get_data_dbi(con=NULL, schema = "public", table = "test_iris"),
"con n\'est pas renseign\u00e9")
con<<-connect_to_db(db = 'test_datalibaba', user = 'test', ecoSQL = FALSE)
expect_error(get_data_dbi(con=con, schema = "public", table = "test_iris"),
"veuillez utiliser une connexion avec ecoSQL=TRUE")
con<<-connect_to_db(db = 'test_datalibaba', user = 'test')
expect_error(get_data_dbi(con=con, table = "test_iris"),
"schema n\'est pas renseign\u00e9")
expect_error(get_data_dbi(con=con, schema = "public"),
"table n\'est pas renseign\u00e9")
expect_snapshot(get_data_dbi(con=con, schema = "public", table = "test_iris"))
}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("get_db_comment 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"))
expect_snapshot(get_db_comment(db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
}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("commenter_schema 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"))
expect_error(commenter_schema(schema = "public", db = "test_datalibaba", user = "test"),
"L'argument comment n\'est pas renseign\u00e9. ")
expect_error(commenter_schema(comment = "un petit schema !", db = "test_datalibaba", user = "test"),
"L\'argument schema n\'est pas renseign\u00e9. ")
expect_null(commenter_schema(comment = "le schema des tests qui restent !", schema = "public", db = "test_datalibaba", user = "test"))
}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("get_schema_comment 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"))
expect_error(get_schema_comment(db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument schema n\'est pas renseign\u00e9. ")
expect_error(get_schema_comment(schema="titi-test", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"Il n\'y a pas de schema titi-test dans la base de donn\u00e9es. ")
expect_snapshot(get_schema_comment(schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
}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)
}
})
library(DBI)
library(magrittr)
library(tibble)
library(lubridate)
library(dplyr)
library(glue)
test_that("commenter_champs 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"))
expect_error(commenter_champs(var = "Species", table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"),
"L\'argument comment n\'est pas renseign\u00e9. ")
expect_error(commenter_champs(comment = "Commentlibaba !", table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"),
"L\'argument var n\'est pas renseign\u00e9. ")
expect_error(commenter_champs(comment = "Commentlibaba !", var = "Species", table = "test_iris", db = "test_datalibaba", user = "test"),
"L\'argument schema n\'est pas renseign\u00e9. ")
expect_error(commenter_champs(comment = "Commentlibaba !", var = "Species", schema = "public", db = "test_datalibaba", user = "test"),
"L\'argument table n\'est pas renseign\u00e9. ")
expect_error(commenter_champs(comment = "Commentlibaba !", var = "Species", table = "test_titi", schema = "public", db = "test_datalibaba", user = "test"),
"Il n\'y a pas de table test_titi dans le schema public. ")
expect_error(commenter_champs(comment = "Commentlibaba !", var = "titi", table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"),
"Il n\'y a pas de champ titi dans la table test_iris. ")
expect_null(commenter_champs(comment = "Commentlibaba !", var = "Species", table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"))
}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("post_dico_attr 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"))
dico_iris <- data.frame(VAR = names(iris), VAR_LIB = paste("libell\u00e9 de", names(iris), " cc"))
expect_error(post_dico_attr(dico = c(1), table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"),
"L\'argument dico ne correpond pas \u00e0 un dataframe. ")
expect_error(post_dico_attr(dico = data.frame(), table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"),
"L\'argument dico est vide. ")
expect_error(post_dico_attr(dico = dico_iris %>% mutate(otr="detrop"), table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"),
"L\'argument dico doit comprendre 2 champs : le 1er pour le nom des variables, le second pour leur explicitation. ")
expect_error(post_dico_attr(dico = dico_iris, table = "test_iris", db = "test_datalibaba", user = "test"),
"L\'argument schema n\'est pas renseign\u00e9. ")
expect_error(post_dico_attr(dico = dico_iris, schema = "public", db = "test_datalibaba", user = "test"),
"L\'argument table n\'est pas renseign\u00e9. ")
expect_error(post_dico_attr(dico = dico_iris, table = "titi_test", schema = "public", db = "test_datalibaba", user = "test"),
"Il n\'y a pas de table titi_test dans le schema public. ")
expect_error(post_dico_attr(dico = dico_iris, table = "nc", schema = "public", db = "test_datalibaba", user = "test"),
"Les champs list\u00e9s dans 'dico' ne se retrouvent pas tous dans la table nc. ")
expect_null(post_dico_attr(dico = dico_iris, table = "retest_iris", schema = "public", db = "test_datalibaba", user = "test"))
}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("get_cols_comment 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"))
expect_error(get_cols_comment(table = "test_iris", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument schema n\'est pas renseign\u00e9. ")
expect_error(get_cols_comment(schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument table n\'est pas renseign\u00e9. ")
expect_error(get_cols_comment(table = "titi_test", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"Il n\'y a pas de table titi_test dans le schema public. ")
expect_snapshot(get_cols_comment(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
}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("get_table_comments 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"))
expect_snapshot(get_table_comments(table = "retest_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
}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("get_table_comment 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"))
expect_error(get_table_comment(table = "test_iris", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument schema n\'est pas renseign\u00e9. ")
expect_error(get_table_comment(schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument table n\'est pas renseign\u00e9. ")
expect_error(get_table_comment(table = "titi_test", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"Il n\'y a pas de table titi_test dans le schema public. ")
expect_snapshot(get_table_comment(table = "retest_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
}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("transferer_table_comments 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"))
expect_null(transferer_table_comments(table_sce = "retest_iris", schema_sce = "public", db_sce = "test_datalibaba", table_dest = "test_iris", schema_dest = "public", db_dest = "test_datalibaba", user = "test", server = Sys.getenv("server")))
}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("exporter_table_comments 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"))
mon_dossier_temp_aleatoire <- tempfile(pattern = "test_exporter_table_comments")
dir.create(mon_dossier_temp_aleatoire)
fichier_temp <- file.path(mon_dossier_temp_aleatoire, "comment_iris.csv")
expect_message(exporter_table_comments(table = "retest_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server"), fichier = fichier_temp, import = TRUE),
"Export du dictionnaire des variables csv")
# On vérifie que le fichier a bien été écrit en sortie
expect_true(file.exists(fichier_temp))
# On vérifie que la taille du fichier est non nulle
expect_true(file.info(fichier_temp)$size > 0)
unlink(mon_dossier_temp_aleatoire, recursive = TRUE)
}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("commenter_table 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"))
expect_error(commenter_table(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"),
"L'argument comment n\'est pas renseign\u00e9. ")
expect_error(commenter_table(comment = "la table de test complete", table = "test_iris", db = "test_datalibaba", user = "test"),
"L\'argument schema n\'est pas renseign\u00e9. ")
expect_error(commenter_table(comment = "la table de test complete", schema = "public", db = "test_datalibaba", user = "test"),
"L\'argument table n\'est pas renseign\u00e9. ")
expect_error(commenter_table(comment = "la table de test complete", table = "titi_test", schema = "public", db = "test_datalibaba", user = "test"),
"Il n\'y a pas de table titi_test dans le schema public. ")
expect_message(commenter_table(comment = "la table de test complete", table = "test_iris", schema = "public", db = "test_datalibaba", user = "test"),
"COMMENT ON TABLE \"public\".\"test_iris\" IS 'la table de test complete")
}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("set_schema_rights 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"))
con<<-connect_to_db(db = 'test_datalibaba', user = 'test')
expect_error(set_schema_rights(schema = "public", table = "test_iris", db = NULL, user = NULL, server = Sys.getenv("server")),
"con, db et user ne sont pas renseign\u00e9s, merci de fournir les arguments necessaires a la connexion ")
expect_error(set_schema_rights(schema = "public", table = "test_iris", db = NULL, user = "test", server = Sys.getenv("server")),
"con et db ne sont pas renseign\u00e9s, merci de fournir les arguments necessaires a la connexion ")
expect_error(set_schema_rights(schema = "public", table = "test_iris", db = "test_datalibaba", user = NULL, server = Sys.getenv("server")),
"con et user ne sont pas renseign\u00e9s, merci de fournir les arguments necessaires a la connexion ")
expect_error(set_schema_rights(schema = NULL, table = "test_iris", con = con, db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"schema n'est pas renseign\u00e9. ")
expect_null(set_schema_rights(schema = "public", table = "test_iris", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
}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)
}
})