[Stacomir-commits] r594 - in pkg/stacomirtools/tests: . testthat

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 9 13:40:04 CET 2021


Author: briand
Date: 2021-11-09 13:40:04 +0100 (Tue, 09 Nov 2021)
New Revision: 594

Added:
   pkg/stacomirtools/tests/testthat/
   pkg/stacomirtools/tests/testthat/test-00-connectiondb.R
   pkg/stacomirtools/tests/testthat/test-01-connectionODBC.R
   pkg/stacomirtools/tests/testthat/test-02-requeteDB.R
   pkg/stacomirtools/tests/testthat/test-03-requeteODBC.R
   pkg/stacomirtools/tests/testthat/test-04-requeteODBCwhere.R
   pkg/stacomirtools/tests/testthat/test-05-requeteODBCwheredate.R
   pkg/stacomirtools/tests/testthat/test-06-requeteDBwhere.R
   pkg/stacomirtools/tests/testthat/test-07-requeteDBwheredate.R
Log:


Added: pkg/stacomirtools/tests/testthat/test-00-connectiondb.R
===================================================================
--- pkg/stacomirtools/tests/testthat/test-00-connectiondb.R	                        (rev 0)
+++ pkg/stacomirtools/tests/testthat/test-00-connectiondb.R	2021-11-09 12:40:04 UTC (rev 594)
@@ -0,0 +1,52 @@
+context("ConnectionDB")
+
+test_that("Test that ConnectionDB returns a pool object and closes ", {
+        skip_on_cran()
+				object<-new("ConnectionDB")
+				object at dbname <- "bd_contmig_nat"
+				object at host <- 		"localhost"
+				object at port <-		"5432"
+				object at user <-		"postgres"
+				object at password <-		"postgres"
+				object <- connect(object)
+				expect_true(pool::dbGetInfo(object at connection)$valid)
+ 				pool::poolClose(object at connection)
+				expect_error(pool::dbGetInfo(object at connection)$valid)				
+    })
+
+test_that("Test that ConnectionDB returns error when dbname length >1 ", {
+			skip_on_cran()
+			object <- new("ConnectionDB")
+			object at dbname <- c("bd_contmig_nat","test")
+			object at host <- 		"localhost"
+			object at port <-		"5432"
+			object at user <-		"postgres"
+			object at password <-		"postgres"	
+			expect_error(connect(object))				
+		})
+
+test_that("Test that RequeteDB returns a pool object", {
+			skip_on_cran()
+			# this requires an odbc link to be setup for test here a database bd_contmig_nat used for stacomir
+			# the odbc link is bd_contmig_nat and points to database bd_contmig_nat
+			object<-new("ConnectionDB")
+			object at dbname <- "bd_contmig_nat"
+			object at host <- 		"localhost"
+			object at port <-		"5432"
+			object at user <-		"postgres"
+			object at password <-		"postgres"	
+			object <- connect(object)
+			expect_that(object at connection,is_a("Pool"))
+			pool::poolClose(object at connection)
+		})
+
+test_that("Test that RequeteDB works when a base is passed to connect", {
+			skip_on_cran()
+			# this requires an odbc link to be setup for test here a database bd_contmig_nat used for stacomir
+			# the odbc link is bd_contmig_nat and points to database bd_contmig_nat
+			object<-new("ConnectionDB")
+			base <- c("bd_contmig_nat","localhost","5432","postgres","postgres")
+			object <- connect(object,base)
+			expect_that(object at connection,is_a("Pool"))
+			pool::poolClose(object at connection)
+		})
\ No newline at end of file

Added: pkg/stacomirtools/tests/testthat/test-01-connectionODBC.R
===================================================================
--- pkg/stacomirtools/tests/testthat/test-01-connectionODBC.R	                        (rev 0)
+++ pkg/stacomirtools/tests/testthat/test-01-connectionODBC.R	2021-11-09 12:40:04 UTC (rev 594)
@@ -0,0 +1,15 @@
+
+context("ConnectionODBC")
+
+test_that("Test that ConnectionODBC returns the sql string when envir_stacomi and showmerequest ", {
+      skip_on_cran()
+      envir_stacomi <- new.env()
+      assign("showmerequest",1,envir_stacomi)
+      object <- new("ConnectionODBC")
+			object at baseODBC <- c("bd_contmig_nat","postgres","postgres")  
+			object <- connect(object)
+			expect_that(object at connection,is_a("RODBC"))
+			odbcClose(object at connection)
+    })
+
+

Added: pkg/stacomirtools/tests/testthat/test-02-requeteDB.R
===================================================================
--- pkg/stacomirtools/tests/testthat/test-02-requeteDB.R	                        (rev 0)
+++ pkg/stacomirtools/tests/testthat/test-02-requeteDB.R	2021-11-09 12:40:04 UTC (rev 594)
@@ -0,0 +1,80 @@
+context("RequeteDB")
+test_that("Test that RequeteDB works on a database ", {
+			skip_on_cran()
+			object <-new("RequeteDB")
+			object at sql <- "select * from iav.t_lot_lot limit 10"
+			object at dbname <- "bd_contmig_nat"
+			object at host <- 		"localhost"
+			object at port <-		"5432"
+			object at user <-		"postgres"
+			object at password <-		"postgres"
+			object <- query(object)
+			expect_that(object at connection,is_a("Pool"))
+			expect_gt(nrow(object at query),0)
+		})
+
+test_that("Test that RequeteDB works when passed arguments base", {
+			skip_on_cran()
+			object <-new("RequeteDB")
+			base <-
+					c("bd_contmig_nat", "localhost", "5432", "postgres", "postgres")
+			object at sql <- "select * from iav.t_lot_lot limit 10"
+			object <- query(object, base)
+			expect_that(object at connection,is_a("Pool"))
+			expect_gt(nrow(object at query),0)
+		})
+
+test_that("Test that RequeteDB works when using options", {
+			skip_on_cran()
+			o <- options()
+			options(					
+							stacomiR.dbname = "bd_contmig_nat",
+							stacomiR.host ="localhost",
+							stacomiR.port = "5432",
+							stacomiR.user = "postgres",
+							stacomiR.password = "postgres"					
+					)	
+			object <-new("RequeteDB")
+			object at sql <- "select * from iav.t_lot_lot limit 10"
+			object <- query(object)
+
+			expect_that(object at connection,is_a("Pool"))
+			expect_gt(nrow(object at query),0)
+			options(o)
+		})
+
+
+test_that("Test that RequeteDB does not work when using wrong options and no base", {
+			skip_on_cran()
+			o <- options()
+			options(					
+					stacomiR.dbname = "bd_contmig_nat",
+					stacomiR.host ="localhost",
+					stacomiR.port = "5432",
+					stacomiR.user = "",
+					stacomiR.password = ""					
+			)	
+			object <-new("RequeteDB")
+			object at sql <- "select * from iav.t_lot_lot limit 10"
+			expect_error(object <- query(object))
+			options(o)
+		})
+
+
+test_that("Test that RequeteDB returns the sql string when options(stacomiR.printquery=TRUE) ", {
+			skip_on_cran()
+			options(					
+					stacomiR.printqueries = TRUE
+			)	
+			object <- new("RequeteDB")
+			object at sql <- "select * from iav.t_lot_lot limit 10"
+			object at dbname <- "bd_contmig_nat"
+			object at host <- 		"localhost"
+			object at port <-		"5432"
+			object at user <-		"postgres"
+			object at password <-		"postgres" 
+			expect_output(object<-query(object))
+			
+			
+		})
+

Added: pkg/stacomirtools/tests/testthat/test-03-requeteODBC.R
===================================================================
--- pkg/stacomirtools/tests/testthat/test-03-requeteODBC.R	                        (rev 0)
+++ pkg/stacomirtools/tests/testthat/test-03-requeteODBC.R	2021-11-09 12:40:04 UTC (rev 594)
@@ -0,0 +1,26 @@
+context("RequeteODBC")
+test_that("Test that RequeteODBC works on a database ", {
+			skip_on_cran()
+			# this requires an odbc link to be setup for test here a database bd_contmig_nat used for stacomir
+			# the odbc link is bd_contmig_nat and points to database bd_contmig_nat
+			# userlocal and passwordlocal are generated from Rprofile.site
+			object <-new("RequeteODBC")
+			object at baseODBC=c("bd_contmig_nat","postgres","postgres")
+			object at sql <- "select * from iav.t_lot_lot limit 10"
+			object <- connect(object)
+			expect_that(object at connection,is_a("RODBC"))
+		})
+
+
+
+test_that("Test that RequeteODBC returns the sql string when envir_stacomi and showmerequest ", {
+      skip_on_cran()
+			skip_if_not_installed ("stacomiR")
+			envir_stacomi <- new.env(parent=asNamespace("stacomiR"))
+      assign("showmerequest",1,envir_stacomi)
+      req<-new("RequeteODBC")
+      req at sql<-"select * from iav.t_lot_lot limit 10"
+      req at baseODBC <- c("bd_contmig_nat","postgres","postgres")   
+      expect_output(req<- connect(req))
+    })
+

Added: pkg/stacomirtools/tests/testthat/test-04-requeteODBCwhere.R
===================================================================
--- pkg/stacomirtools/tests/testthat/test-04-requeteODBCwhere.R	                        (rev 0)
+++ pkg/stacomirtools/tests/testthat/test-04-requeteODBCwhere.R	2021-11-09 12:40:04 UTC (rev 594)
@@ -0,0 +1,18 @@
+context("RequeteODBCwhere")
+test_that("Test that RequeteODBCwhere returns rows", {
+			skip_on_cran()
+			# this requires an odbc link to be setup for test here a database bd_contmig_nat used for stacomir
+			# the odbc link is bd_contmig_nat and points to database bd_contmig_nat
+			# userlocal and passwordlocal are generated from Rprofile.site
+			object <-new("RequeteODBCwhere")
+			object at select<- "select * from iav.t_lot_lot"
+			object at where <- "WHERE lot_tax_code='2038'"
+			object at and<-c("AND lot_std_code='CIV'","AND lot_ope_identifiant<1000")
+			object at order_by<-"ORDER BY lot_identifiant limit 10"
+			object at baseODBC=c("bd_contmig_nat","postgres","postgres")
+			object <- connect(object)
+			expect_gt(nrow(object at query),0)
+		})
+
+
+

Added: pkg/stacomirtools/tests/testthat/test-05-requeteODBCwheredate.R
===================================================================
--- pkg/stacomirtools/tests/testthat/test-05-requeteODBCwheredate.R	                        (rev 0)
+++ pkg/stacomirtools/tests/testthat/test-05-requeteODBCwheredate.R	2021-11-09 12:40:04 UTC (rev 594)
@@ -0,0 +1,18 @@
+context("RequeteODBCwheredate")
+test_that("Test that RequeteODBCwheredate returns rows", {
+			skip_on_cran()
+			# this requires an odbc link to be setup for test here a database bd_contmig_nat used for stacomir
+			# the odbc link is bd_contmig_nat and points to database bd_contmig_nat
+			# userlocal and passwordlocal are generated from Rprofile.site
+			object <-new("RequeteODBCwheredate")
+			object at datedebut <- strptime("2012-01-01 00:00:00", format="%Y-%m-%d %H:%M:%S")
+			object at datefin <-  strptime("2013-01-01 00:00:00", format="%Y-%m-%d %H:%M:%S")
+			object at colonnedebut="ope_date_debut" 
+			object at colonnefin="ope_date_fin"			
+			object at select<- "select * from iav.t_operation_ope"
+			object at where <- "WHERE ope_dic_identifiant=5"
+			object at order_by<-"limit 10"
+			object at baseODBC=c("bd_contmig_nat","postgres","postgres")
+			object <- connect(object)
+			expect_gt(nrow(object at query),0)
+		})

Added: pkg/stacomirtools/tests/testthat/test-06-requeteDBwhere.R
===================================================================
--- pkg/stacomirtools/tests/testthat/test-06-requeteDBwhere.R	                        (rev 0)
+++ pkg/stacomirtools/tests/testthat/test-06-requeteDBwhere.R	2021-11-09 12:40:04 UTC (rev 594)
@@ -0,0 +1,12 @@
+context("RequeteDBwhere")
+test_that("Test that RequeteDBwhere returns rows", {
+			skip_on_cran()
+			object <-new("RequeteDBwhere")
+			base=c("bd_contmig_nat","localhost","5432","postgres", "postgres")
+			object at select<- "select * from iav.t_lot_lot"
+			object at where <- "WHERE lot_tax_code='2038'"
+			object at and<-c("AND lot_std_code='CIV'")
+			object at order_by<-"ORDER BY lot_identifiant limit 10"
+			object <- query(object, base)
+			expect_gt(nrow(object at query),0)
+		})

Added: pkg/stacomirtools/tests/testthat/test-07-requeteDBwheredate.R
===================================================================
--- pkg/stacomirtools/tests/testthat/test-07-requeteDBwheredate.R	                        (rev 0)
+++ pkg/stacomirtools/tests/testthat/test-07-requeteDBwheredate.R	2021-11-09 12:40:04 UTC (rev 594)
@@ -0,0 +1,21 @@
+context("RequeteDBwheredate")
+test_that("Test that RequeteDBwheredate works on a database ", {
+			skip_on_cran()
+			object <-new("RequeteDBwheredate")
+			base=c("bd_contmig_nat","localhost","5432","postgres", "postgres")
+			object at datedebut <- strptime("2012-01-01 00:00:00", format="%Y-%m-%d %H:%M:%S")
+			object at datefin <-  strptime("2013-01-01 00:00:00", format="%Y-%m-%d %H:%M:%S")
+			object at colonnedebut="ope_date_debut" 
+			object at colonnefin="ope_date_fin"	
+			object at select<- "select * from iav.t_operation_ope JOIN iav.t_lot_lot on lot_ope_identifiant=ope_identifiant"
+			object at where <- "WHERE lot_tax_code='2038'"
+			object at and<-c("AND lot_std_code='CIV'")
+			object at order_by<-"ORDER BY lot_identifiant limit 10"
+			object <- query(object, base)
+			expect_gt(nrow(object at query),0)
+		})
+
+
+
+
+



More information about the Stacomir-commits mailing list