From d49e9def7255aaccf9618aae88304193e5eb2c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 20 Sep 2019 20:09:00 +0200 Subject: [PATCH] agent: adapt for python3 (#36273) --- hobo/agent/common/management/commands/hobo_deploy.py | 6 +++--- hobo/agent/common/management/commands/hobo_notify.py | 2 +- tests/test_hobo_deploy.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hobo/agent/common/management/commands/hobo_deploy.py b/hobo/agent/common/management/commands/hobo_deploy.py index 05b31f8..1ab1e26 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 @@ -65,7 +65,7 @@ class Command(BaseCommand): if json_filename == '-': hobo_environment = json.load(sys.stdin) else: - hobo_environment = json.load(file(json_filename)) + hobo_environment = json.load(open(json_filename)) self.deploy(base_url, hobo_environment, ignore_timestamp) def deploy(self, base_url, hobo_environment, ignore_timestamp): @@ -135,7 +135,7 @@ class Command(BaseCommand): continue tenant_idp_metadata = os.path.join(tenant.get_directory(), 'idp-metadata-%s.xml' % service.get('id')) - replace_file(tenant_idp_metadata, response.content) + replace_file(tenant_idp_metadata, response.text) # break now, only a single IdP is supported break diff --git a/hobo/agent/common/management/commands/hobo_notify.py b/hobo/agent/common/management/commands/hobo_notify.py index b5630c1..5835aa3 100644 --- a/hobo/agent/common/management/commands/hobo_notify.py +++ b/hobo/agent/common/management/commands/hobo_notify.py @@ -43,7 +43,7 @@ class Command(BaseCommand): # get environment definition from stdin return json.load(sys.stdin) else: - return json.load(file(notification)) + return json.load(open(notification)) def handle(self, notification, **kwargs): notification = self.load_notification(notification) diff --git a/tests/test_hobo_deploy.py b/tests/test_hobo_deploy.py index 00be16c..2b8fc95 100644 --- a/tests/test_hobo_deploy.py +++ b/tests/test_hobo_deploy.py @@ -86,7 +86,7 @@ def test_handle_from_scratch(): # handle from file command.deploy.reset_mock() - with patch('hobo.agent.common.management.commands.hobo_deploy.file') as mocked_open: + with patch('hobo.agent.common.management.commands.hobo_deploy.open') as mocked_open: mocked_open.side_effect = [StringIO.StringIO(CONTENT)] command.handle('https://combo.dev.publik.love/', 'envbof.json') assert command.deploy.mock_calls == EXPECTED @@ -101,7 +101,7 @@ def test_handle_from_scratch(): # JSON having syntax error command.deploy.reset_mock() - with patch('hobo.agent.common.management.commands.hobo_deploy.file') as mocked_open: + with patch('hobo.agent.common.management.commands.hobo_deploy.open') as mocked_open: mocked_open.side_effect = [StringIO.StringIO('malformated JSON')] with pytest.raises(ValueError, match='No JSON object could be decoded'): command.handle('https://combo.dev.publik.love/', 'env.json')