Commits

Olemis Lang committed 83bce29

BH Multiproduct #355 : Load default data into product environment ... ok

Comments (0)

Files changed (1)

t355/t355_r1442601_trac_test_ticket_model.diff

 # HG changeset patch
-# Parent 41e94f06990edc669c8908132e6e3a2d9b0d32fa
+# Parent 73470e3a5b55b7146a43a36696424b5e4ba05896
 BH Multiproduct #355 : Rewrite Trac test cases for ticket models so as to run them against product environments
 
-diff -r 41e94f06990e bloodhound_multiproduct/multiproduct/env.py
---- a/bloodhound_multiproduct/multiproduct/env.py	Fri Feb 08 03:35:21 2013 -0500
-+++ b/bloodhound_multiproduct/multiproduct/env.py	Fri Feb 08 10:23:54 2013 -0500
+diff -r 73470e3a5b55 bloodhound_multiproduct/multiproduct/env.py
+--- a/bloodhound_multiproduct/multiproduct/env.py	Fri Feb 08 12:26:08 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/env.py	Sat Feb 09 00:41:52 2013 -0500
 @@ -105,7 +105,7 @@
          self.parent = None
          self.product = None
                                                enable=enable, disable=disable,
                                                path=path, destroying=destroying)
          # Apply multi product upgrades. This is required as the database proxy (translator)
-@@ -153,6 +153,9 @@
-         # FIXME: Shall we ?
-         #env.config.save()
+@@ -117,6 +117,9 @@
+         except OperationalError:
+             pass
  
 +        if default_data:
 +            self.reset_db(default_data)
 +
-     def reset_db(self, default_data=None):
-         from multiproduct.api import DB_VERSION
-         schema_version = -1
-diff -r 41e94f06990e bloodhound_multiproduct/tests/env.py
---- a/bloodhound_multiproduct/tests/env.py	Fri Feb 08 03:35:21 2013 -0500
-+++ b/bloodhound_multiproduct/tests/env.py	Fri Feb 08 10:23:54 2013 -0500
+     @staticmethod
+     def enable_component_in_config(env, cls):
+         """Keep track of enabled state in configuration as well 
+diff -r 73470e3a5b55 bloodhound_multiproduct/tests/env.py
+--- a/bloodhound_multiproduct/tests/env.py	Fri Feb 08 12:26:08 2013 -0500
++++ b/bloodhound_multiproduct/tests/env.py	Sat Feb 09 00:41:52 2013 -0500
 @@ -117,13 +117,14 @@
  
      # Test setup
          if create_folder:
              if path is None:
                  env.path = tempfile.mkdtemp('bh-product-tempenv')
-diff -r 41e94f06990e bloodhound_multiproduct/tests/ticket/model.py
+@@ -172,6 +173,20 @@
+             # table remains but database version is deleted
+             pass
+ 
++    def _load_default_data(self, env):
++        r"""Initialize environment with default data by respecting
++        values set in system table.
++        """
++        from trac import db_default
++
++        with env.db_transaction as db:
++            for table, cols, vals in db_default.get_data(db):
++                if table != 'system':
++                    db.executemany('INSERT INTO %s (%s) VALUES (%s)' %
++                            (table, ','.join(cols), 
++                                    ','.join(['%s' for c in cols])),
++                            vals)
++
+     def _mp_setup(self):
+         """Shortcut for quick product-aware environment setup.
+         """
+diff -r 73470e3a5b55 bloodhound_multiproduct/tests/ticket/model.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/ticket/model.py	Fri Feb 08 10:23:54 2013 -0500
-@@ -0,0 +1,61 @@
++++ b/bloodhound_multiproduct/tests/ticket/model.py	Sat Feb 09 00:41:52 2013 -0500
+@@ -0,0 +1,62 @@
 +
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +#  or more contributor license agreements.  See the NOTICE file
 +        self._setup_test_log(self.global_env)
 +        self._load_product_from_data(self.global_env, self.default_product)
 +        self.env = ProductEnvironment(self.global_env, self.default_product)
++        self._load_default_data(self.env)
 +
 +        self.env.config.set('ticket-custom', 'foo', 'text')
 +        self.env.config.set('ticket-custom', 'cbon', 'checkbox')