Sfoglia il codice sorgente

Connect to postgresql with user name and password

oz123 10 anni fa
parent
commit
302469fe99

+ 2 - 2
pwman/data/drivers/postgresql.py

@@ -45,11 +45,11 @@ class PostgresqlDatabase(Database):
     """
 
     @classmethod
-    def check_db_version(cls, user, dbname='pwman'):  # pragma: no cover
+    def check_db_version(cls, dburi):
         """
         Check the database version
         """
-        con = pg.connect("dbname=pwman user=%s" % user)
+        con = pg.connect(dburi.geturl())
         cur = con.cursor()
         try:
             cur.execute("SELECT VERSION from DBVERSION")

+ 2 - 1
pwman/data/factory.py

@@ -40,6 +40,7 @@ import os
 
 from pwman.data.database import DatabaseException
 from pwman.data.drivers import sqlite
+from pwman.data.drivers import postgresql
 
 
 def check_db_version(dburi):
@@ -54,7 +55,7 @@ def check_db_version(dburi):
             return 0.3
     # TODO: implement version checks for other supported DBs.
     if dbtype == "postgresql":
-        ver = sqlite.PostgresqlDatabase.check_db_version(dburi)
+        ver = postgresql.PostgresqlDatabase.check_db_version(dburi)
 
 
 def createdb(dburi, version):

+ 3 - 0
pwman/tests/test_postgresql.py

@@ -37,7 +37,10 @@ class TestPostGresql(unittest.TestCase):
 
     @classmethod
     def setUpClass(self):
+        # no password required, for testing in travis
         u = "postgresql:///pwman"
+        # password required, for all other hosts
+        #u = "postgresql://<user>:<pass>@localhost/pwman"
         self.db = PostgresqlDatabase(u)
         self.db._open()