Please review this at http://codereview.appspot.com/4125045/
This is an improvement for running scenarii on unittest server in separate
databases.

Affected files:
  M CHANGELOG
  M proteus/config.py
  M proteus/tests/test_config.py
  M proteus/tests/test_model.py
  M proteus/tests/test_wizard.py


Index: CHANGELOG
===================================================================
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,2 +1,4 @@
+* Manage default values of trytond configuration
+
 Version 1.8.0 - 2010-12-24
 * Initial release
Index: proteus/config.py
===================================================================
--- a/proteus/config.py
+++ b/proteus/config.py
@@ -10,6 +10,7 @@
 from decimal import Decimal
 from types import NoneType
 import datetime
+import time

 def dump_decimal(self, value, write):
     write("<value><double>")
@@ -93,21 +94,27 @@
 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 @@
         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,
Index: proteus/tests/test_config.py
===================================================================
--- a/proteus/tests/test_config.py
+++ b/proteus/tests/test_config.py
@@ -7,7 +7,7 @@
 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 @@

     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)

Index: proteus/tests/test_model.py
===================================================================
--- a/proteus/tests/test_model.py
+++ b/proteus/tests/test_model.py
@@ -7,7 +7,7 @@
 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')
Index: proteus/tests/test_wizard.py
===================================================================
--- a/proteus/tests/test_wizard.py
+++ b/proteus/tests/test_wizard.py
@@ -7,7 +7,7 @@
 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')



-- 
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/

Attachment: pgpmAqhRAeq9I.pgp
Description: PGP signature

Reply via email to