From 26dd217655bacb8bd340c914535624bc661a3327 Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Fri, 13 Mar 2020 16:41:55 +0100 Subject: [PATCH] python3: encoding correction on hobo_deploy.py (#40726) --- .../management/commands/hobo_deploy.py | 5 ++- tests/test_hobo_deploy.py | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/bijoe/hobo_agent/management/commands/hobo_deploy.py b/bijoe/hobo_agent/management/commands/hobo_deploy.py index c4f0c10..250710e 100644 --- a/bijoe/hobo_agent/management/commands/hobo_deploy.py +++ b/bijoe/hobo_agent/management/commands/hobo_deploy.py @@ -23,6 +23,7 @@ from tenant_schemas.utils import tenant_context from hobo.agent.common.management.commands import hobo_deploy from hobo.multitenant.settings_loaders import KnownServices +from django.utils.encoding import force_str from django.conf import settings @@ -89,8 +90,8 @@ class Command(hobo_deploy.Command): config.set(base_url, 'orig', orig) config.set(base_url, 'key', key) config.set(base_url, 'schema', schema) - config.set(base_url, 'cubes_label', service.get('title').encode('utf-8')) + config.set(base_url, 'cubes_label', force_str(service.get('title'))) if 'slug' in service: config.set(base_url, 'cubes_slug', service['slug']) with open(ini_file, 'w') as f: - config.write(f) + config.write(f) diff --git a/tests/test_hobo_deploy.py b/tests/test_hobo_deploy.py index b38c5b4..341621c 100644 --- a/tests/test_hobo_deploy.py +++ b/tests/test_hobo_deploy.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # bijoe - BI dashboard # Copyright (C) 2015 Entr'ouvert # @@ -76,3 +77,46 @@ def test_deploy_specifics(tmpdir, settings, monkeypatch): assert parsed_pg_dsn['user'] == 'hep' assert parsed_pg_dsn['password'] == 'a \'%fc' assert parsed_pg_dsn['port'] == '1234' + + bijoe_base_url = 'https://bijoe.example.net' + wcs_base_url = 'https://wcs.example.net' + hobo_environment = { + 'services': [ + { + 'this': True, + 'secret_key': 'xx', + 'service-id': 'bijoe', + 'base_url': bijoe_base_url, + }, + { + 'this': False, + 'secret_key': 'yy', + 'service-id': 'wcs', + 'base_url': wcs_base_url, + 'title': 'my läâàlel', + 'slug': 'my_slug', + }, + { + 'this': False, + 'secret_key': 'zz', + 'service-id': 'wcs', + 'base_url': 'https://wcs-2.example.net', + 'secondary': True, + }, + ], + } + command.deploy_specifics(hobo_environment, tenant) + with wcs_olap_ini_path.open() as fd: + config = ConfigParser.SafeConfigParser() + config.readfp(fd) + assert config.get(wcs_base_url, 'orig') == 'bijoe.example.net' + assert config.get(wcs_base_url, 'schema') == 'wcs_example_net' + assert config.get(wcs_base_url, 'cubes_label') == 'my läâàlel' + assert config.get(wcs_base_url, 'cubes_slug') == 'my_slug' + + hobo_environment['services'][0]['base_url'] = 'https://new-bijoe.example.net' + command.deploy_specifics(hobo_environment, tenant) + with wcs_olap_ini_path.open() as fd: + config = ConfigParser.SafeConfigParser() + config.readfp(fd) + assert config.get(wcs_base_url, 'orig') == 'new-bijoe.example.net'