python3: encoding correction on hobo_deploy.py (#40726)

This commit is contained in:
Nicolas Roche 2020-03-13 16:41:55 +01:00
parent f4e12c2b6e
commit 26dd217655
2 changed files with 47 additions and 2 deletions

View File

@ -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)

View File

@ -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'