diff --git a/CHANGELOG b/CHANGELOG index 0c22f94035..033d68e559 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,4 @@ +* Manage default values of trytond configuration + Version 1.8.0 - 2010-12-24 * Initial release diff --git a/README b/README index b4a4955407..7e0a9576d7 100644 --- a/README +++ b/README @@ -21,6 +21,8 @@ Configuration to connect to a sqlite memory database using trytond as module. >>> config = config.set_trytond(':memory:', database_type='sqlite') When connecting to a database that doesn't exist, Proteus will create it. +If no database name was given, then Proteus will generate one. It will choose +':memory': for 'sqlite' type otherwise `'test_%' % int(time.time())`. Installing a module ~~~~~~~~~~~~~~~~~~~ diff --git a/proteus/config.py b/proteus/config.py index 6a7b2a620b..710b01b296 100644 --- a/proteus/config.py +++ b/proteus/config.py @@ -10,6 +10,7 @@ import threading from decimal import Decimal from types import NoneType import datetime +import time def dump_decimal(self, value, write): write("") @@ -93,21 +94,27 @@ class TrytondProxy(object): class TrytondConfig(Config): 'Configuration for trytond' - def __init__(self, database_name, user, database_type, language='en_US', - password=''): + def __init__(self, database_name=None, user='admin', database_type=None, + language='en_US', password=''): super(TrytondConfig, self).__init__() from trytond.config import CONFIG - CONFIG['db_type'] = database_type CONFIG.parse() + if database_type is not None: + CONFIG['db_type'] = database_type from trytond.modules import register_classes from trytond.pool import Pool from trytond.backend import Database from trytond.protocols.dispatcher import create from trytond.cache import Cache from trytond.transaction import Transaction + self.database_type = CONFIG['db_type'] + if database_name is None: + if self.database_type == 'sqlite': + database_name = ':memory:' + else: + database_name = 'test_%s' % int(time.time()) self.database_name = database_name self._user = user - self.database_type = database_type register_classes() @@ -151,7 +158,7 @@ class TrytondConfig(Config): proxy = self.get_proxy(name, type=type) return [x for x in proxy._object._rpc] -def set_trytond(database_name, user='admin', database_type='postgresql', +def set_trytond(database_name=None, user='admin', database_type=None, language='en_US', password=''): 'Set trytond package as backend' _CONFIG.current = TrytondConfig(database_name, user, database_type, diff --git a/proteus/tests/test_config.py b/proteus/tests/test_config.py index 719052406a..8c568b49dd 100644 --- a/proteus/tests/test_config.py +++ b/proteus/tests/test_config.py @@ -7,7 +7,7 @@ import proteus.config class TestConfig(TestCase): def setUp(self): - proteus.config.set_trytond(':memory:', database_type='sqlite') + proteus.config.set_trytond(database_type='sqlite') def test_proxy(self): config = proteus.config.get_config() @@ -22,7 +22,7 @@ class TestConfig(TestCase): def test_trytond_config_eq(self): config1 = proteus.config.get_config() - proteus.config.set_trytond(':memory:', database_type='sqlite') + proteus.config.set_trytond(database_type='sqlite') config2 = proteus.config.get_config() self.assertEqual(config1, config2) diff --git a/proteus/tests/test_model.py b/proteus/tests/test_model.py index 8d1d760a80..92841eb5c9 100644 --- a/proteus/tests/test_model.py +++ b/proteus/tests/test_model.py @@ -7,7 +7,7 @@ from proteus import config, Model class TestModel(TestCase): def setUp(self): - config.set_trytond(':memory:', database_type='sqlite') + config.set_trytond(database_type='sqlite') def test_class_cache(self): User1 = Model.get('res.user') diff --git a/proteus/tests/test_wizard.py b/proteus/tests/test_wizard.py index 4541b8ae4f..2b824c3e1e 100644 --- a/proteus/tests/test_wizard.py +++ b/proteus/tests/test_wizard.py @@ -7,7 +7,7 @@ from proteus import config, Wizard, Model class TestWizard(TestCase): def setUp(self): - config.set_trytond(':memory:', database_type='sqlite') + config.set_trytond(database_type='sqlite') def test_translation_clean(self): translation_clean = Wizard('ir.translation.clean')