Fix tests for Python 3

The httplib module has been renamed to http.client in Python 3. So let's try to import HTTPConnection from both.

authorJérémy Bobbio <jeremy.bobbio@irq7.fr>
changeset48f01895be54
branchdefault
phasepublic
hiddenno
parent revision#32a67daf6edf Added tag 0.7.7, centos/0.7.7-1, debian/0.7.7-1 for changeset 75ef2bcdb798
child revision#e96b8e3e5e63 Update Debian packaging with support for Python 3
files modified by this revision
cubicweb_elasticsearch/testutils.py
# HG changeset patch
# User Jérémy Bobbio <jeremy.bobbio@irq7.fr>
# Date 1574416373 -3600
# Fri Nov 22 10:52:53 2019 +0100
# Node ID 48f01895be54f091c75706780854fd61f6df4ba8
# Parent 32a67daf6edf0730c3500031de8d82919a489006
Fix tests for Python 3

The httplib module has been renamed to http.client in Python 3.
So let's try to import HTTPConnection from both.

diff --git a/cubicweb_elasticsearch/testutils.py b/cubicweb_elasticsearch/testutils.py
@@ -1,7 +1,11 @@
1  import unittest
2 -import httplib
3 +
4 +try:
5 +    from http.client import HTTPConnection
6 +except ImportError:
7 +    from httplib import HTTPConnection
8 
9  from elasticsearch_dsl.connections import connections
10 
11  from cubicweb.predicates import is_instance
12 
@@ -32,11 +36,11 @@
13  class RealESTestMixin(object):
14 
15      @classmethod
16      def setUpClass(cls):
17          try:
18 -            httplib.HTTPConnection('localhost:9200').request('GET', '/')
19 +            HTTPConnection('localhost:9200').request('GET', '/')
20          except:  # noqa
21              raise unittest.SkipTest(
22                  'No ElasticSearch on localhost, skipping test')
23          super(RealESTestMixin, cls).setUpClass()
24