[Greater-commits] r325 - trunk/GREAT-ER-DB/impl/postgresql/test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jun 30 12:41:51 CEST 2011


Author: bricks
Date: 2011-06-30 12:41:51 +0200 (Thu, 30 Jun 2011)
New Revision: 325

Modified:
   trunk/GREAT-ER-DB/impl/postgresql/test/test_pg_d_connect.py
Log:
Improve da_db_connect tests


Modified: trunk/GREAT-ER-DB/impl/postgresql/test/test_pg_d_connect.py
===================================================================
--- trunk/GREAT-ER-DB/impl/postgresql/test/test_pg_d_connect.py	2011-06-30 10:41:12 UTC (rev 324)
+++ trunk/GREAT-ER-DB/impl/postgresql/test/test_pg_d_connect.py	2011-06-30 10:41:51 UTC (rev 325)
@@ -32,6 +32,8 @@
 from GreaterDB.interface import da_db_rollback
 from GreaterDB.interface import da_get_version
 
+from GreaterDB.interface import DA_S_user
+from GreaterDB.interface import da_insert_user
 
 class Test_da_db_connect(unittest.TestCase):
 
@@ -43,33 +45,79 @@
         self.server = postgressupport.get_test_server()
         self.connection_target = self.server.known_dbs["static_db"].get_connection_target()
 
+    def tearDown(self):
+        da_db_disconnect();
+
     def test_db_user(self):
-    	try:
-		self.res = da_db_connect("anonym", "123", self.connection_target)
-		da_db_disconnect()
-        	self.assertEquals(self.res,None)
-	except RuntimeError:
-		print "Connection failed!"
+        da_db_connect("anonym", "123", self.connection_target)
+        da_db_disconnect();
+        da_db_connect("AnoNym", "123", self.connection_target)
 
     def test_db_greater(self):
-      	try:
-	        self.res = da_db_connect("GREATER200", "", self.connection_target)
-		da_db_disconnect()
-        	self.assertEquals(self.res,None)
-	except RuntimeError:
-		print "Connection failed!"
+        da_db_connect("GREATER200", "", self.connection_target)
 
     def test_db_user_und_greater(self):
-    	try:
-	    	self.res = da_db_connect("anonym_greater", "hallo", self.connection_target)
-		da_db_disconnect()
-		self.assertEquals(self.res,None)
-	except RuntimeError:
-		print "Connection failed!"
+        da_db_connect("anonym_greater", "hallo", self.connection_target)
 
+    def test_db_users(self):
+        try:
+            db_db_connect("anonym", "", self.connection_target)
+            self.fail("It should not be possible to connect with an empty"\
+                      " password")
+        except:
+             pass
+
+        # creater new testuser
+        da_db_connect("anonym", "123", self.connection_target)
+        user_record = DA_S_user({'user_id':'john_doe',
+                                 'cre_date':'30-11-2003',
+                                 'mod_date':'29-11-2003',
+                                 'group_id':101,
+                                 'status':'VALID',
+                                 'remark':'Standard User!'})
+        da_insert_user(user_record, "hallo")
+        da_db_commit()
+        da_db_disconnect()
+
+        da_db_connect("john_doe", "hallo", self.connection_target)
+        da_db_disconnect()
+
+        da_db_connect("JOHN_DOE", "hallo", self.connection_target);
+        da_db_disconnect()
+        
+        da_db_connect("JoHN_DoE", "hallo", self.connection_target);
+        da_db_disconnect()
+
+        try:
+            da_db_connect("john_doe", "Hallo", self.connection_target);
+            self.fail("It should not be possible to connect user with "\
+                      "mixedcase password")
+        except:
+            pass
+
+        try:
+            da_db_connect("john_doe", "HALLO", self.connection_target);
+            self.fail("It should not be possible to connect user with "\
+                      "uppercase password")
+        except:
+            pass
+
+        try:
+            da_db_connect("john doe", "hallo", self.connection_target);
+            self.fail("It should not be possible to connect username with "\
+                      "spaces")
+        except:
+            pass
+
+    def test_db_disconnect(self):
+        # test several disconnects in a row
+        # there should be no error
+        da_db_disconnect()
+        da_db_disconnect()
+
     def test_db_version(self):
-	self.res =  da_get_version()
-	print self.res
+        res =  da_get_version()
+        self.assertNotEquals(res, None)
 
 if __name__ == "__main__":
     support.run_tests()



More information about the Greater-commits mailing list