From 8e612b565b403bbd82af3e04bfd0c9f09797696a Mon Sep 17 00:00:00 2001
From: Christophe Siraut <csiraut@entrouvert.com>
Date: Thu, 19 Sep 2019 16:21:07 +0200
Subject: [PATCH] use python3 urlparse namespace

---
 .../agent/common/management/commands/hobo_deploy.py |  2 +-
 hobo/environment/management/commands/cook.py        |  7 ++++---
 hobo/profile/models.py                              |  4 ++--
 tests/test_cook.py                                  |  8 +++++---
 tests/test_emails.py                                |  6 +++++-
 tests/test_health_api.py                            |  6 +++++-
 tests/test_hobo_deploy.py                           |  8 ++++++--
 tests/test_import_template.py                       |  6 +++++-
 tests/test_manager.py                               |  2 +-
 tests/test_matomo_utils.py                          |  6 +++++-
 tests/test_matomo_views.py                          |  6 +++++-
 tests_authentic/settings.py                         | 13 +++++++++----
 tests_multipublik/settings.py                       |  4 ++--
 tox.ini                                             |  6 +++---
 14 files changed, 58 insertions(+), 26 deletions(-)

diff --git a/hobo/agent/common/management/commands/hobo_deploy.py b/hobo/agent/common/management/commands/hobo_deploy.py
index 05b31f8..ae69210 100644
--- a/hobo/agent/common/management/commands/hobo_deploy.py
+++ b/hobo/agent/common/management/commands/hobo_deploy.py
@@ -6,11 +6,11 @@ import requests
 import subprocess
 import sys
 import tempfile
-import urlparse
 
 from django.conf import settings
 from django.core.management.base import BaseCommand, CommandError
 from django.core.management import call_command, get_commands
+from django.utils.six.moves.urllib import parse as urlparse
 
 from tenant_schemas.utils import tenant_context
 from hobo.multitenant.middleware import TenantMiddleware, TenantNotFound
diff --git a/hobo/environment/management/commands/cook.py b/hobo/environment/management/commands/cook.py
index 0776748..a4c6d3d 100644
--- a/hobo/environment/management/commands/cook.py
+++ b/hobo/environment/management/commands/cook.py
@@ -21,7 +21,6 @@ import string
 import sys
 import time
 import os
-import urlparse
 
 from django.contrib.auth.models import User
 from django.contrib.contenttypes.models import ContentType
@@ -31,6 +30,8 @@ from django.db import connection
 from django.db.models import Max
 from django.core.exceptions import ValidationError
 from django.utils.text import slugify
+from django.utils.six.moves.urllib import parse as urlparse
+from django.utils.six import string_types
 
 from hobo.agent.common.management.commands.hobo_deploy import (
         Command as HoboDeployCommand)
@@ -74,9 +75,9 @@ class Command(BaseCommand):
                 os.path.join(os.path.dirname(filename), recipe['load-variables-from']))))
         variables.update(recipe.get('variables', {}))
         for step in recipe.get('steps', []):
-            action, action_args = step.items()[0]
+            action, action_args = list(step.items())[0]
             for arg in action_args:
-                if not isinstance(action_args[arg], basestring):
+                if not isinstance(action_args[arg], string_types):
                     continue
                 action_args[arg] = string.Template(
                         action_args[arg]).substitute(variables)
diff --git a/hobo/profile/models.py b/hobo/profile/models.py
index 16a68e0..81d8318 100644
--- a/hobo/profile/models.py
+++ b/hobo/profile/models.py
@@ -17,7 +17,7 @@
 from django.core.validators import RegexValidator
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
-
+from django.utils.six import string_types
 
 validate_attribute_name = RegexValidator(
     r'^[a-z][a-z0-9_]*\Z',
@@ -68,7 +68,7 @@ class AttributeDefinition(models.Model):
 
     def as_dict(self):
         as_dict = dict([(x, y) for (x, y) in self.__dict__.items()
-                        if type(y) in (str, unicode, bool)])
+                        if type(y) in (string_types, bool)])
         return as_dict
 
     def get_real_kind_display(self):
diff --git a/tests/test_cook.py b/tests/test_cook.py
index fa0f43c..a9c4787 100644
--- a/tests/test_cook.py
+++ b/tests/test_cook.py
@@ -1,9 +1,11 @@
 import os
 import json
-import StringIO
-
+from django.utils import six
 import pytest
-from mock import call, mock_open, patch, Mock
+if six.PY3:
+    from unittest.mock import call, mock_open, patch, Mock
+else:
+    from mock import call, mock_open, patch, Mock
 
 from django.contrib.auth.models import User
 from django.contrib.contenttypes.models import ContentType
diff --git a/tests/test_emails.py b/tests/test_emails.py
index b922685..6ed33ae 100644
--- a/tests/test_emails.py
+++ b/tests/test_emails.py
@@ -4,7 +4,11 @@ import asyncore
 import dns.resolver
 from dns import name
 from dns.rdtypes.ANY import MX, TXT
-import mock
+from django.utils import six
+if six.PY3:
+    import unittest.mock
+else:
+    import mock
 import smtplib
 import smtpd
 import socket
diff --git a/tests/test_health_api.py b/tests/test_health_api.py
index 6d7a296..f51334d 100644
--- a/tests/test_health_api.py
+++ b/tests/test_health_api.py
@@ -1,5 +1,9 @@
 import json
-from mock import MagicMock
+from django.utils import six
+if six.PY3:
+    from unittest.mock import MagicMock
+else:
+    from mock import MagicMock
 import pytest
 import requests
 import socket
diff --git a/tests/test_hobo_deploy.py b/tests/test_hobo_deploy.py
index 00be16c..650f1d6 100644
--- a/tests/test_hobo_deploy.py
+++ b/tests/test_hobo_deploy.py
@@ -1,12 +1,16 @@
 """ unit tests (mainly for code coverage)
 """
-import StringIO
+from django.utils.six.moves import StringIO
+from django.utils import six
 import os
 import sys
 
 import json
 import pytest
-from mock import call, patch, Mock
+if six.PY3:
+    from unittest.mock import call, patch, Mock
+else:
+    from mock import call, patch, Mock
 from requests import Response, exceptions
 
 from hobo.agent.common.management.commands.hobo_deploy import (
diff --git a/tests/test_import_template.py b/tests/test_import_template.py
index 48479e9..41c06eb 100644
--- a/tests/test_import_template.py
+++ b/tests/test_import_template.py
@@ -1,5 +1,9 @@
 import pytest
-import mock
+from django.utils import six
+if six.PY3:
+    from unittest import mock
+else:
+    import mock
 
 from django.conf import settings
 from django.core.management import load_command_class
diff --git a/tests/test_manager.py b/tests/test_manager.py
index e4e211a..c8d0639 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -1,6 +1,6 @@
 import base64
 import os
-import StringIO
+from django.utils.six.moves import StringIO
 
 from django.conf import settings
 from django.contrib.auth.models import User
diff --git a/tests/test_matomo_utils.py b/tests/test_matomo_utils.py
index b02c002..7dfd643 100644
--- a/tests/test_matomo_utils.py
+++ b/tests/test_matomo_utils.py
@@ -1,7 +1,11 @@
 # -*- coding: utf-8 -*-
 
 import json
-import mock
+from django.utils import six
+if six.PY3:
+    from unittest import mock
+else:
+    import mock
 import pytest
 from requests import Response
 
diff --git a/tests/test_matomo_views.py b/tests/test_matomo_views.py
index 04fd6f2..ef6f012 100644
--- a/tests/test_matomo_views.py
+++ b/tests/test_matomo_views.py
@@ -1,7 +1,11 @@
 # -*- coding: utf-8 -*-
 
 import json
-import mock
+from django.utils import six
+if six.PY3:
+    from unittest import mock
+else:
+    import mock
 import pytest
 import re
 from requests import Response
diff --git a/tests_authentic/settings.py b/tests_authentic/settings.py
index 4a8e4c3..b1311cf 100644
--- a/tests_authentic/settings.py
+++ b/tests_authentic/settings.py
@@ -1,6 +1,12 @@
 import os.path
-import __builtin__ as builtin
-from mock import mock_open, patch
+from django.utils.six.moves import builtins
+from django.utils import six
+if six.PY3:
+try:
+    from unittest.mock import mock_open, patch
+    from past.builtins import execfile
+else:
+    from mock import mock_open, patch
 import os
 
 # Debian defaults
@@ -8,8 +14,7 @@ DEBUG = False
 
 PROJECT_NAME = 'authentic2-multitenant'
 
-
-with patch.object(builtin, 'open', mock_open(read_data='xxx')):
+with patch.object(builtins, 'open', mock_open(read_data='xxx')):
     execfile(os.environ['DEBIAN_CONFIG_COMMON'])
 
 BRANCH_NAME = os.environ.get("BRANCH_NAME", "").replace('/', '-')
diff --git a/tests_multipublik/settings.py b/tests_multipublik/settings.py
index ce4c4de..ed5976a 100644
--- a/tests_multipublik/settings.py
+++ b/tests_multipublik/settings.py
@@ -1,5 +1,5 @@
 import os.path
-import __builtin__ as builtin
+from six.moves import builtins
 from mock import mock_open, patch
 
 from hobo.settings import *
@@ -8,7 +8,7 @@ LANGUAGE_CODE = 'en-us'
 
 PROJECT_NAME = 'multipublik'
 
-with patch.object(builtin, 'open', mock_open(read_data='xxx')):
+with patch.object(builtins, 'open', mock_open(read_data='xxx')):
     execfile(os.path.join(os.path.dirname(__file__), '../debian/debian_config_common.py'))
 
 BRANCH_NAME = os.environ.get("BRANCH_NAME", "").replace('/', '-')
diff --git a/tox.ini b/tox.ini
index f24abdd..c041331 100644
--- a/tox.ini
+++ b/tox.ini
@@ -4,10 +4,9 @@
 # and then run "tox" from this directory.
 [tox]
 toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/hobo
-envlist = coverage-{authentic,hobo,multipublik,multitenant,passerelle,schemas},
+envlist = {py2,py3}-coverage-hobo,py2-coverage-{authentic,multipublik,multitenant,passerelle,schemas},
 
 [testenv]
-basepython = python2
 whitelist_externals =
 	/bin/mv
 usedevelop = True
@@ -52,7 +51,8 @@ deps:
 	requests
 	pytest-freezegun
 commands =
-	./getlasso.sh
+	py2: ./getlasso.sh
+	py3: ./getlasso3.sh
 	hobo: py.test {env:COVERAGE:} {env:NOMIGRATIONS:} {posargs:tests/}
 	schemas: py.test {env:COVERAGE:} {env:NOMIGRATIONS:} {posargs:tests_schemas/}
 	multitenant: py.test {env:COVERAGE:} {env:NOMIGRATIONS:} {posargs:tests_multitenant/}
-- 
2.20.1

