Skip to content

Commit

Permalink
[config] Make it possible to create ili2db config objects from a base…
Browse files Browse the repository at this point in the history
… (Ili2DbCommandConfiguration) object to ease initialization of specialized configs
  • Loading branch information
gacarrillor committed Sep 28, 2024
1 parent 8726f53 commit 5a4cbbb
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 37 deletions.
78 changes: 41 additions & 37 deletions modelbaker/iliwrapper/ili2dbconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,35 @@ def ilidata_directories(self):


class Ili2DbCommandConfiguration:
def __init__(self):
self.base_configuration = BaseConfiguration()

self.dbport = ""
self.dbhost = ""
self.dbpwd = ""
self.dbusr = ""
self.dbauthid = ""
self.db_use_super_login = False
self.database = ""
self.dbschema = ""
self.dbfile = ""
self.dbservice = None
self.sslmode = None
self.tool = None
self.ilifile = ""
self.ilimodels = ""
self.tomlfile = ""
self.dbinstance = ""
self.db_odbc_driver = ""
self.disable_validation = False
self.metaconfig = None
self.metaconfig_id = None
self.metaconfig_params_only = False
self.db_ili_version = None
def __init__(self, other=None):
if not isinstance(other, Ili2DbCommandConfiguration):
self.base_configuration = BaseConfiguration()

self.dbport = ""
self.dbhost = ""
self.dbpwd = ""
self.dbusr = ""
self.dbauthid = ""
self.db_use_super_login = False
self.database = ""
self.dbschema = ""
self.dbfile = ""
self.dbservice = None
self.sslmode = None
self.tool = None
self.ilifile = ""
self.ilimodels = ""
self.tomlfile = ""
self.dbinstance = ""
self.db_odbc_driver = ""
self.disable_validation = False
self.metaconfig = None
self.metaconfig_id = None
self.metaconfig_params_only = False
self.db_ili_version = None
else:
# We got an 'other' object from which we'll get parameters
self.__dict__ = other.__dict__.copy()

def append_args(self, args, values, consider_metaconfig=False, force_append=False):

Expand Down Expand Up @@ -186,8 +190,8 @@ def to_ili2db_args(self):


class ExportConfiguration(Ili2DbCommandConfiguration):
def __init__(self):
super().__init__()
def __init__(self, other: Ili2DbCommandConfiguration = None):
super().__init__(other)
self.xtffile = ""
self.with_exporttid = False
self.iliexportmodels = ""
Expand Down Expand Up @@ -228,8 +232,8 @@ def to_ili2db_args(self, extra_args=[], with_action=True):


class SchemaImportConfiguration(Ili2DbCommandConfiguration):
def __init__(self):
super().__init__()
def __init__(self, other: Ili2DbCommandConfiguration = None):
super().__init__(other)
self.inheritance = "smart1"
self.create_basket_col = False
self.create_import_tid = True
Expand Down Expand Up @@ -323,8 +327,8 @@ def to_ili2db_args(self, extra_args=[], with_action=True):


class ImportDataConfiguration(SchemaImportConfiguration):
def __init__(self):
super().__init__()
def __init__(self, other: Ili2DbCommandConfiguration = None):
super().__init__(other)
self.xtffile = ""
self.delete_data = False
self.with_importtid = False
Expand Down Expand Up @@ -376,8 +380,8 @@ def to_ili2db_args(self, extra_args=[], with_action=True):


class UpdateDataConfiguration(Ili2DbCommandConfiguration):
def __init__(self):
super().__init__()
def __init__(self, other: Ili2DbCommandConfiguration = None):
super().__init__(other)
self.xtffile = ""
self.dataset = ""
self.delete_data = False
Expand Down Expand Up @@ -414,8 +418,8 @@ def to_ili2db_args(self, extra_args=[], with_action=True):


class ValidateConfiguration(Ili2DbCommandConfiguration):
def __init__(self):
super().__init__()
def __init__(self, other: Ili2DbCommandConfiguration = None):
super().__init__(other)
self.ilimodels = ""
self.topics = ""
self.dataset = ""
Expand Down Expand Up @@ -475,8 +479,8 @@ def to_ili2db_args(self, extra_args=[], with_action=True):


class DeleteConfiguration(Ili2DbCommandConfiguration):
def __init__(self):
super().__init__()
def __init__(self, other: Ili2DbCommandConfiguration = None):
super().__init__(other)
self.dataset = ""

def to_ili2db_args(self, extra_args=[], with_action=True):
Expand Down
72 changes: 72 additions & 0 deletions tests/test_ili2dbcommandconfiguration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""
/***************************************************************************
-------------------
begin : 27.09.2024
git sha : :%H$
copyright : (C) 2024 by Germán Carrillo
email : german at opengis ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from qgis.testing import start_app, unittest

from modelbaker.iliwrapper.ili2dbconfig import (
BaseConfiguration,
DeleteConfiguration,
ExportConfiguration,
Ili2DbCommandConfiguration,
ImportDataConfiguration,
SchemaImportConfiguration,
UpdateDataConfiguration,
ValidateConfiguration,
)

start_app()


class TestIli2DbCommandConfiguration(unittest.TestCase):
GPKG_PATH = "/tmp/data.gpkg"
MODELS_DIR = "/tmp/models/"

def test_ili2db_command_configuration_from_an_other(self):
base_config = BaseConfiguration()
base_config.custom_model_directories_enabled = True
base_config.custom_model_directories = self.MODELS_DIR

configuration = Ili2DbCommandConfiguration()
configuration.base_configuration = base_config
configuration.dbfile = self.GPKG_PATH

delete_config = DeleteConfiguration()
assert delete_config.dbfile == ""

delete_config = DeleteConfiguration(configuration)
self.check_members(delete_config)

import_config = ImportDataConfiguration(configuration)
self.check_members(import_config)

import_schema_config = SchemaImportConfiguration(configuration)
self.check_members(import_schema_config)

export_config = ExportConfiguration(configuration)
self.check_members(export_config)

update_config = UpdateDataConfiguration(configuration)
self.check_members(update_config)

validate_config = ValidateConfiguration(configuration)
self.check_members(validate_config)

def check_members(self, config):
assert config.base_configuration.custom_model_directories_enabled == True
assert config.base_configuration.custom_model_directories == self.MODELS_DIR
assert config.dbfile == self.GPKG_PATH

0 comments on commit 5a4cbbb

Please sign in to comment.