Commits

Olemis Lang committed 93fc92b

BH Multiproduct #387 : Parameterize testenv's tracd options. Mixins for digest and basic auth

  • Participants
  • Parent commits d61428b
  • Branches t387_test_functional

Comments (0)

Files changed (1)

t387/t387_r1515319_functional_test.6.diff

 
 diff -r dc26c55b4721 bloodhound_multiproduct/tests/functional/__init__.py
 --- a/bloodhound_multiproduct/tests/functional/__init__.py	Thu Aug 29 12:43:46 2013 -0500
-+++ b/bloodhound_multiproduct/tests/functional/__init__.py	Sun Sep 01 03:38:27 2013 -0500
++++ b/bloodhound_multiproduct/tests/functional/__init__.py	Mon Sep 02 00:00:16 2013 -0500
 @@ -17,6 +17,7 @@
  #  specific language governing permissions and limitations
  #  under the License.
  import imp
  from inspect import isclass
  import os
-@@ -35,9 +36,11 @@
+@@ -35,15 +36,18 @@
  from trac.util.compat import close_fds
  from trac.util.text import unicode_quote
  from trac.web.href import Href
  from tests import unittest
  
  #----------------
-@@ -57,6 +60,7 @@
+ # Product-aware classes for functional tests
+ #----------------
+ 
++# TODO: Virtual ABCs for isinstance() checks
+ class MultiproductFunctionalMixin(object):
+     """Mixin class applying multi-product upgrade path upon a given
+     functional Trac test environment. Access to the global environment
+@@ -57,6 +61,7 @@
      def init(self):
          """Determine the location of Trac source code
          """
          self.bhmp_upgrade = False
          self.trac_src = os.path.realpath(os.path.join( 
                  __import__('trac', []).__file__, '..' , '..'))
-@@ -114,7 +118,7 @@
+@@ -114,7 +119,7 @@
          """Default implementation just returning href object for global
          environment and failing if product prefix is specified.
          """
              raise LookupError('Unknown environment ' + repr(envname))
          if prefix is not None:
              self._fail_no_mp_setup()
-@@ -205,16 +209,11 @@
+@@ -156,6 +161,11 @@
+         if do_wait: # Delay to ensure command executes and caches resets
+             time.sleep(5)
+ 
++    def _tracd_options(self):
++        """List options to run tracd server started for the test run.
++        """
++        return ["--port=%s" % self.port, "-s", "--hostname=127.0.0.1"]
++
+     def start(self):
+         """Starts the webserver, and waits for it to come up.
+         
+@@ -169,9 +179,11 @@
+                 args = [exe]
+         else:
+             args = [sys.executable]
+-        options = ["--port=%s" % self.port, "-s", "--hostname=127.0.0.1"]
++        options = self._tracd_options()
+         if 'TRAC_TEST_TRACD_OPTIONS' in os.environ:
+             options += os.environ['TRAC_TEST_TRACD_OPTIONS'].split()
++        self.get_trac_environment().log.debug('Starting tracd with args ' +
++                                              ' '.join(options))
+         args.append(os.path.join(self.trac_src, 'trac', 'web',
+                                  'standalone.py'))
+         server = Popen(args + options + [self.tracdir],
+@@ -205,16 +217,11 @@
          plugins_dir = global_env.shared_plugins_dir
          load_components(global_env, plugins_dir and (plugins_dir,))
  
  
      def configure_web_hooks(self):
          """Setup web bootstrap_handlers and generation of product and global
-@@ -238,6 +237,8 @@
+@@ -238,6 +245,8 @@
          global environment.
          """
          def _default_base_href(user=None, prefix=None, envname=None):
              # TODO: Does not generate /login ? Should it ?
              parts = urllib2.urlparse.urlsplit(self.url)
              if not user or user == 'anonymous':
-@@ -252,6 +253,17 @@
+@@ -252,6 +261,17 @@
  
      # Protected methods
  
      def _bloodhound_install(self):
          """Execute Bloodhound installer script
          """
-@@ -267,29 +279,22 @@
+@@ -267,29 +287,22 @@
                                        os.path.join(self.bh_src, 'installer',
                                                     'bloodhound_setup.py'))
  
          finally:
              os.chdir(cwd)
  
-@@ -307,6 +312,53 @@
+@@ -307,6 +320,76 @@
          return MultiProductSystem(env).default_product_prefix
  
  
 +                                 (self.__class__.__name__, attrnm))
 +
 +
++# TODO: Virtual ABCs for isinstance() checks
++class BasicAuthTestEnvironment(object):
++    """Setup tracd for HTTP basic authentication.
++    """
++    def _tracd_options(self):
++        options = super(BasicAuthTestEnvironment, self)._tracd_options()
++        options.append("--basic-auth=%s,%s," % (self.bh_install_project,
++                                                self.htpasswd))
++        return options
++
++
++# TODO: Virtual ABCs for isinstance() checks
++class DigestAuthTestEnvironment(object):
++    """Setup tracd for HTTP digest authentication.
++    """
++    def _tracd_options(self):
++        options = super(DigestAuthTestEnvironment, self)._tracd_options()
++        options.append("--auth=%s,%s,%s" % (self.bh_install_project,
++                                            self.htdigest,
++                                            self.htdigest_realm))
++        return options
++
++
  class BloodhoundFunctionalTester(FunctionalTester):
      """Leverages Trac library of higher-level operations for interacting with
      a fully featured Apache(TM) Bloodhound test environment.
-@@ -652,9 +704,10 @@
+@@ -652,9 +735,10 @@
      As a consequence some methods of Trac functional tester have to be
      executed in special ways.
      """
  
      class in_product(BloodhoundFunctionalTester.in_product):
          """Context manager temporarily switching to product URL
-@@ -744,10 +797,26 @@
+@@ -744,10 +828,26 @@
  
      tester_class = BloodhoundGlobalEnvFunctionalTester
  
          except:
              # Ensure tracd process is killed on failure
              print "Stopping web server...\n"
-@@ -770,6 +839,7 @@
+@@ -770,6 +870,7 @@
          order access default product URL namespace instead of global.
          """
          self.setUp()
          if hasattr(self, 'fixture'):
              for test in self._tests:
                  if hasattr(test, 'setFixture'):
-@@ -778,10 +848,20 @@
+@@ -778,10 +879,20 @@
          for test in self._tests:
              if result.shouldStop:
                  break
              else:
                  test(result)
          self.tearDown()
-@@ -801,11 +881,27 @@
+@@ -801,11 +912,27 @@
          :param prefix:  target product prefix
          :return:        context manager object
          """