bijoe/tests/test_hobo_deploy.py

79 lines
2.3 KiB
Python

# bijoe - BI dashboard
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from contextlib import contextmanager
from psycopg2.extensions import parse_dsn
from django.utils.six.moves import configparser as ConfigParser
from bijoe.hobo_agent.management.commands import hobo_deploy
@contextmanager
def donothing(tenant):
yield
class FakeTenant(object):
domain_url = 'fake.tenant.com'
def __init__(self, directory):
self.directory = directory
def get_directory(self):
return self.directory
def test_deploy_specifics(tmpdir, settings, monkeypatch):
monkeypatch.setattr(hobo_deploy, 'tenant_context', donothing)
settings.DATABASES = {
'default': {
'NAME': 'coucou',
'HOST': 'hostname.zob.org',
'USER': 'hep',
'PASSWORD': 'a \'%fc',
'PORT': 1234,
}
}
hobo_environment = {
'services': [
{
'this': True,
'secret_key': 'xx',
}
],
}
command = hobo_deploy.Command()
tenant_dir = tmpdir.mkdir('tenant')
tenant = FakeTenant(str(tenant_dir))
command.deploy_specifics(hobo_environment, tenant)
wcs_olap_ini_path = tenant_dir / 'wcs-olap.ini'
assert wcs_olap_ini_path.exists()
with wcs_olap_ini_path.open() as fd:
config = ConfigParser.SafeConfigParser()
config.readfp(fd)
pg_dsn = config.get('wcs-olap', 'pg_dsn')
parsed_pg_dsn = parse_dsn(pg_dsn)
assert parsed_pg_dsn['dbname'] == 'coucou'
assert parsed_pg_dsn['host'] == 'hostname.zob.org'
assert parsed_pg_dsn['user'] == 'hep'
assert parsed_pg_dsn['password'] == 'a \'%fc'
assert parsed_pg_dsn['port'] == '1234'