Ticket 733: Updated python client to work with python3 jenkins-baltrad-db-413
authorAnders Henja <anders@henjab.se>
Wed, 28 Mar 2018 16:12:03 +0000 (18:12 +0200)
committerAnders Henja <anders@henjab.se>
Wed, 28 Mar 2018 16:12:03 +0000 (18:12 +0200)
client/python/itest/__init__.py
client/python/itest/rest_test.py
client/python/setup.py
client/python/src/baltrad/bdbclient/db.py
client/python/src/baltrad/bdbclient/rest.py
client/python/test/db_test.py
client/python/test/main_test.py
client/python/test/rest_test.py
misc/hudsonbuild.sh

index d49f5a0..644631c 100644 (file)
@@ -1,10 +1,10 @@
+from baltrad.bdbclient import rest
 import os, errno, subprocess, time, string
 import jprops
-from baltrad.bdbclient import rest
-
 PIDFILE="./build/bdb.pid"
 LOGFILE="./build/bdb.log"
-
 def execute_command(cmd):
     """executes the specified command
     :param: a string defining the command to be run
@@ -13,7 +13,7 @@ def execute_command(cmd):
     code = subprocess.call(cmd, shell=True)
     if code != 0:
         raise Exception("Could not run command %s"%cmd)
-
+  
 def does_client_and_server_exist():
     """tests if the binaries baltrad-bdb-server and baltrad-bdb-client are on the path
     :return: True if both client and server exists, otherwise False 
@@ -25,7 +25,7 @@ def does_client_and_server_exist():
     if code != 0:
         return False
     return True
-
 def is_server_running(uri):
     """tests if the server is running by trying to send a list_sources command
     :param uri: the uri to the server 
@@ -35,20 +35,20 @@ def is_server_running(uri):
     if code != 0:
         return False
     return True
-
 def get_server_uri():
     """returns the server uri as defined in the BDB_PYCLIENT_ITEST_PROPERTYFILE
     :return: the server uri defined by the property baltrad.bdb.server.uri
     """    
     config = os.environ.get("BDB_PYCLIENT_ITEST_PROPERTYFILE", "")
-    
+     
     properties = None
-    
+     
     with open(config, 'rb') as fp:
         properties = jprops.load_properties(fp)
-        
+         
     return properties['baltrad.bdb.server.uri']
-
 def pid_exists(pid):
     """tests if the pid is a running process
     :param pid: the pid of the process to check for 
@@ -62,7 +62,7 @@ def pid_exists(pid):
         return e.errno == errno.EPERM
     else:
         return True
-
 def stop_server(uri, removepid=False):
     """stops the server running with the specified uri
     :param uri: the uri to the server 
@@ -75,42 +75,42 @@ def stop_server(uri, removepid=False):
                     os.kill(pid, 15) # TERM
             except:
                 pass
-
     if removepid and os.path.exists(PIDFILE):
         os.unlink(PIDFILE)
-        
-
+         
 def setup():
     """executed by the nose tests before running the test suite
     """
     if os.path.exists(LOGFILE):
         os.unlink(LOGFILE)
-    
+     
     if not does_client_and_server_exist():
         raise Exception("Couldn't find client and server binaries")
-
     config = os.environ.get("BDB_PYCLIENT_ITEST_PROPERTYFILE", "")
-    
+     
     uri = get_server_uri()
-    
+     
     stop_server(uri, True)
-    
+     
     execute_command("baltrad-bdb-drop --conf=%s"%config)
     execute_command("baltrad-bdb-create --conf=%s"%config)
     execute_command("baltrad-bdb-server --conf=%s --pidfile=%s --logfile=%s"%(config, PIDFILE, LOGFILE))
-    
+     
     for i in range(3):
         if is_server_running(uri):
             break
         time.sleep(1)
-
     execute_command("baltrad-bdb-client import_sources --url=%s ./etc/itest_sources.xml"%uri)
-
 def teardown():
     """executed by the nose tests after the test suite has been executed
     """    
     stop_server(get_server_uri())
-    
+     
 def get_database():
     auth = rest.NoAuth()
     uri = get_server_uri()
index 46673ef..4f5b667 100644 (file)
@@ -14,7 +14,6 @@
 #
 # You should have received a copy of the GNU Lesser General Public License
 # along with baltrad-db. If not, see <http://www.gnu.org/licenses/>.
-
 import os
 
 from keyczar import errors as kzerrors
@@ -27,6 +26,8 @@ from baltrad.bdbcommon import oh5
 from . import get_database
 
 class TestKeyczarAuth(object):
+    pass
+    
     @raises(kzerrors.KeyczarError)
     def test_ctor_nx_key(self):
         rest.KeyczarAuth("/path/to/nxkey")
@@ -92,7 +93,7 @@ class TestRestfulDatabase(object):
     def test_get_source(self):
         #<se CCCC="ESWI" org="82" cty="643">
         source = self.database.get_source("se")
-        print `source`
+        print(str(source))
         eq_('se', source.name)
         eq_('ESWI', source['CCCC'])
         eq_('82', source['ORG'])
@@ -171,5 +172,5 @@ class TestRestfulDatabase(object):
         eq_("Arlanda", source["PLC"])
         eq_("SE46", source["RAD"])
         eq_("02451", source["WMO"])
-        
+
  
index fbc97c7..1a3925b 100755 (executable)
@@ -1,13 +1,29 @@
 #!/usr/bin/env python
 from ez_setup import use_setuptools
-use_setuptools(version="24.0.2")
+use_setuptools(version="38.4.0")
 
 import setuptools
+import sys
+
+REQUIRED_PACKAGES= [
+    "baltrad.bdbcommon",
+    "pyasn1",
+    "pycrypto >= 2.4",
+    "python-keyczar >= 0.7b",
+]
+if sys.version_info > (3,):
+    REQUIRED_PACKAGES= [
+    "baltrad.bdbcommon",
+    "pyasn1",
+    "pycrypto >= 2.4",
+    "python3-keyczar >= 0.71rc0",
+]
 
 setuptools.setup(name="baltrad.bdbclient",
     version="0.1-dev",
     namespace_packages=["baltrad"],
     setup_requires=['nose>=1.0'],
+    zip_safe=False,
     packages=setuptools.find_packages(
         "src",
         exclude=["*.tests.*", "*.tests"],
@@ -15,12 +31,7 @@ setuptools.setup(name="baltrad.bdbclient",
     package_dir={
         "": "src"
     },
-    install_requires=[
-        "baltrad.bdbcommon",
-        "pyasn1",
-        "pycrypto >= 2.4",
-        "python-keyczar >= 0.7b",
-    ],
+    install_requires=REQUIRED_PACKAGES,
     entry_points = {
         "baltrad.bdbclient.commands": [
             "import = baltrad.bdbclient.cmd:ImportFile",
@@ -39,6 +50,6 @@ setuptools.setup(name="baltrad.bdbclient",
     test_suite="nose.collector",
     tests_require=[
         "mock >= 0.7",
-        "jprops >= 0.1"
+        "jprops >= 2.0.2"
     ],
 )
index 072699a..68465e4 100644 (file)
@@ -235,7 +235,7 @@ class AttributeQuery(object):
     def to_json(self):
         json_repr = {}
         fetch = {}
-        for key, xpr in self._fetch.iteritems():
+        for key, xpr in self._fetch.items():
             fetch[key] = expr.wrap_json(xpr)
         json_repr["fetch"] = fetch
         if self.filter:
index 12cdb4f..6dd84f7 100644 (file)
@@ -176,11 +176,11 @@ class RestfulDatabase(db.Database):
         response = self.execute_request(request)
 
         if response.status == httplibclient.OK:
-            data = json.loads(response.read())
+            data = json.loads(response.read().decode('utf-8'))
             result = []
             for src in data["sources"]:
                 parent = None
-                if src.has_key("parent"):
+                if "parent" in src:
                     parent = src["parent"]
                 result.append(oh5.Source(src["name"], values=src["values"], parent=parent))
             return result
@@ -197,9 +197,9 @@ class RestfulDatabase(db.Database):
         response = self.execute_request(request)
 
         if response.status == httplibclient.OK:
-            data = json.loads(response.read())
+            data = json.loads(response.read().decode('utf-8'))
             src = data["source"]
-            if src.has_key("parent"):
+            if "parent" in src:
                 parent = src["parent"]
             result = oh5.Source(src["name"], values=src["values"], parent=parent)
             return result
@@ -278,11 +278,11 @@ class RestfulDatabase(db.Database):
         response = self.execute_request(request)
 
         if response.status == httplibclient.OK:
-            data = json.loads(response.read())
+            data = json.loads(response.read().decode('utf-8'))
             result = []
             for src in data["sources"]:
                 parent = None
-                if src.has_key("parent"):
+                if "parent" in src:
                     parent = src["parent"]
                 result.append(oh5.Source(src["name"], values=src["values"], parent=parent))
             return result
@@ -299,11 +299,11 @@ class RestfulDatabase(db.Database):
         response = self.execute_request(request)
 
         if response.status == httplibclient.OK:
-            data = json.loads(response.read())
+            data = json.loads(response.read().decode('utf-8'))
             result = []
             for src in data["sources"]:
                 parent = None
-                if src.has_key("parent"):
+                if "parent" in src:
                     parent = src["parent"]
                 result.append(oh5.Source(src["name"], values=src["values"], parent=parent))
             return result
@@ -453,7 +453,7 @@ def create_signable_string(req):
     """
     fragments = [req.method, req.path]
     for key in ("content-md5", "content-type", "date"):
-        if req.headers.has_key(key):
+        if key in req.headers:
             value = req.headers[key].strip()
             if value:
                 fragments.append(value)
index 43fa5b7..a6a045b 100644 (file)
@@ -14,7 +14,6 @@
 #
 # You should have received a copy of the GNU Lesser General Public License
 # along with baltrad-db. If not, see <http://www.gnu.org/licenses/>.
-
 from nose.tools import eq_, ok_, raises
 import mock
 
index 98723b0..2b11673 100644 (file)
@@ -19,6 +19,7 @@ from nose.tools import eq_
 
 from baltrad.bdbclient.main import extract_command
 
+
 def test_extract_command():
     cmd, args = extract_command(["-v", "cmd", "arg", "--help"])
     eq_("cmd", cmd)
index 054f28b..cb167a8 100644 (file)
 # along with baltrad-db. If not, see <http://www.gnu.org/licenses/>.
 
 import sys
+patch_httpexception="httplib.HTTPConnection"
 if sys.version_info < (3,):
     import httplib as httplibclient
     import urlparse
+    patch_httpexception="httplib.HTTPConnection"    
 else:
     from http import client as httplibclient
     from urllib.parse import urlparse
+    patch_httpexception="http.client.HTTPConnection"    
     
 from nose.tools import eq_, ok_, raises
 import mock
 
 from baltrad.bdbclient import db, rest
 
+
 def test_create_signable_string():
     expected = "\n".join((
         "GET",
@@ -253,7 +257,7 @@ class TestRestfulDatabase(object):
         ok_(isinstance(result, rest.RestfulAttributeResult))
         eq_(2, result.size())
     
-    @mock.patch("httplib.HTTPConnection")
+    @mock.patch(patch_httpexception) #"httplib.HTTPConnection")
     def test_execute_request(self, conn_ctor):
         self.db = rest.RestfulDatabase("http://www.example.com", self.auth)
         req = mock.Mock(spec=rest.Request)
index 2c5ce59..d54768b 100644 (file)
@@ -33,7 +33,7 @@ init_test_env() {
   $envpath/bin/pip install "nose >= 1.1" --trusted-host pypi.python.org
   $envpath/bin/pip install "sphinx >= 1.1" --trusted-host pypi.python.org
   $envpath/bin/pip install "mock >= 0.7" --trusted-host pypi.python.org
-  $envpath/bin/pip install "cherrypy == 3.2.2" --trusted-host pypi.python.org
+  $envpath/bin/pip install "cherrypy == 8.9.1" --trusted-host pypi.python.org
 }
 
 install_python_package() {