You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by rj...@apache.org on 2013/06/12 02:53:41 UTC
svn commit: r1492028 - in /bloodhound/trunk/bloodhound_multiproduct:
multiproduct/api.py multiproduct/env.py tests/env.py
Author: rjollos
Date: Wed Jun 12 00:53:40 2013
New Revision: 1492028
URL: http://svn.apache.org/r1492028
Log:
Refs #386: Implemented expansion `$(envname)` and allow for absolute URLs in `product_base_url`. Added test cases for `product_base_url`.
Modified:
bloodhound/trunk/bloodhound_multiproduct/multiproduct/api.py
bloodhound/trunk/bloodhound_multiproduct/multiproduct/env.py
bloodhound/trunk/bloodhound_multiproduct/tests/env.py
Modified: bloodhound/trunk/bloodhound_multiproduct/multiproduct/api.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/multiproduct/api.py?rev=1492028&r1=1492027&r2=1492028&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_multiproduct/multiproduct/api.py (original)
+++ bloodhound/trunk/bloodhound_multiproduct/multiproduct/api.py Wed Jun 12 00:53:40 2013
@@ -89,10 +89,10 @@ class MultiProductSystem(Component):
e.g. the use cases listed in bh:wiki:/Proposals/BEP-0003#url-mapping .
Both absolute as well as relative URLs are supported. The later
will be resolved with respect to the base URL of the parent global
- environment. The pattern may contain references to $(prefix)s and
- $(name)s placeholders representing the product prefix and name
- respectively . If nothing is set the following will be used
- `products/$(prefix)s`
+ environment. The pattern may contain references to $(envname)s,
+ $(prefix)s and $(name)s placeholders representing the environment name,
+ product prefix and product name respectively . If nothing is set the
+ following will be used `products/$(prefix)s`
Note the usage of `$(...)s` instead of `%(...)s` as the later form
would be interpreted by the ConfigParser itself. """)
Modified: bloodhound/trunk/bloodhound_multiproduct/multiproduct/env.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/multiproduct/env.py?rev=1492028&r1=1492027&r2=1492028&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_multiproduct/multiproduct/env.py (original)
+++ bloodhound/trunk/bloodhound_multiproduct/multiproduct/env.py Wed Jun 12 00:53:40 2013
@@ -860,14 +860,22 @@ class ProductEnvironment(Component, Comp
"configuration, generated links may be "
"incorrect")
urlpattern = 'products/$(prefix)s'
+ envname = os.path.basename(self.parent.path)
prefix = unicode_quote(self.product.prefix, safe="")
name = unicode_quote(self.product.name, safe="")
url = urlpattern.replace('$(', '%(') \
+ .replace('%(envname)s', envname) \
.replace('%(prefix)s', prefix) \
.replace('%(name)s', name)
- parent_href = Href(self.parent.abs_href(), path_safe="/!~*'()%",
- query_safe="!~*'()%")
- self._abs_href = Href(parent_href(url))
+ if urlsplit(url).netloc:
+ # Absolute URLs
+ self._abs_href = Href(url)
+ else:
+ # Relative URLs
+ parent_href = Href(self.parent.abs_href(),
+ path_safe="/!~*'()%",
+ query_safe="!~*'()%")
+ self._abs_href = Href(parent_href(url))
else:
self._abs_href = Href(self.base_url)
return self._abs_href
Modified: bloodhound/trunk/bloodhound_multiproduct/tests/env.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/tests/env.py?rev=1492028&r1=1492027&r2=1492028&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_multiproduct/tests/env.py (original)
+++ bloodhound/trunk/bloodhound_multiproduct/tests/env.py Wed Jun 12 00:53:40 2013
@@ -532,10 +532,79 @@ class ProductEnvApiTestCase(Multiproduct
self.assertIs(env1, envgen3[prefix],
"Identity check (by product model) '%s'" % (prefix,))
+class ProductEnvHrefTestCase(MultiproductTestCase):
+ """Assertions for resolution of product environment's base URL
+ [https://issues.apache.org/bloodhound/wiki/Proposals/BEP-0003 BEP 3]
+ """
+
+ def product_base_url(url_template):
+ def decorator(f):
+ f.product_base_url = url_template
+ return f
+
+ return decorator
+
+ def setUp(self):
+ self._mp_setup()
+ self.env.path = '/path/to/env'
+ url_pattern = getattr(getattr(self, self._testMethodName).im_func,
+ 'product_base_url', '')
+ self.env.config.set('multiproduct', 'product_base_url', url_pattern)
+ self.product_env = ProductEnvironment(self.env, self.default_product)
+
+ def tearDown(self):
+ # Release reference to transient environment mock object
+ if self.env is not None:
+ try:
+ self.env.reset_db()
+ except OperationalError:
+ # "Database not found ...",
+ # "OperationalError: no such table: system" or the like
+ pass
+ self.env = None
+ self.product_env = None
+
+ @product_base_url('http://$(prefix)s.domain.tld/')
+ def test_href_subdomain(self):
+ """Test product sub domain base URL
+ """
+ self.assertEqual('http://tp1.domain.tld', self.product_env.abs_href())
+
+ @product_base_url('/path/to/bloodhound/$(prefix)s')
+ def test_href_sibling_paths(self):
+ """Test product base URL at sibling paths
+ """
+ self.assertEqual('http://example.org/trac.cgi/path/to/bloodhound/tp1',
+ self.product_env.abs_href())
+
+ @product_base_url('/$(envname)s/$(prefix)s')
+ def test_href_inherit_sibling_paths(self):
+ """Test product base URL at sibling paths inheriting configuration.
+ """
+ self.assertEqual('http://example.org/trac.cgi/env/tp1',
+ self.product_env.abs_href())
+
+ @product_base_url('/products/$(prefix)s')
+ def test_href_embed(self):
+ """Test default product base URL /products/prefix
+ """
+ self.assertEqual('http://example.org/trac.cgi/products/tp1',
+ self.product_env.abs_href())
+
+ @product_base_url('http://$(envname)s.tld/bh/$(prefix)s')
+ def test_href_complex(self):
+ """Test complex product base URL
+ """
+ self.assertEqual('http://env.tld/bh/tp1', self.product_env.abs_href())
+
+ product_base_url = staticmethod(product_base_url)
+
+
def test_suite():
return unittest.TestSuite([
unittest.makeSuite(ProductEnvTestCase,'test'),
- unittest.makeSuite(ProductEnvApiTestCase, 'test')
+ unittest.makeSuite(ProductEnvApiTestCase, 'test'),
+ unittest.makeSuite(ProductEnvHrefTestCase, 'test'),
])
if __name__ == '__main__':