[req] Return base-url in case https-url is None in base_url()
authorDenis Laxalde <denis.laxalde@logilab.fr>
Fri, 13 Dec 2013 10:24:10 +0100
changeset 9386 a33da516028f
parent 9385 65ad67b0df22
child 9387 f31f0c8bda4f
[req] Return base-url in case https-url is None in base_url() Closes #3376322.
req.py
test/unittest_req.py
--- a/req.py	Thu Dec 19 17:09:08 2013 +0100
+++ b/req.py	Fri Dec 13 10:24:10 2013 +0100
@@ -456,7 +456,7 @@
         """return the root url of the instance
         """
         if secure:
-            return self.vreg.config.get('https-url', self.vreg.config['base-url'])
+            return self.vreg.config.get('https-url') or self.vreg.config['base-url']
         return self.vreg.config['base-url']
 
     # abstract methods to override according to the web front-end #############
--- a/test/unittest_req.py	Thu Dec 19 17:09:08 2013 +0100
+++ b/test/unittest_req.py	Fri Dec 13 10:24:10 2013 +0100
@@ -53,6 +53,16 @@
 
 
 class RequestCWTC(CubicWebTC):
+
+    def test_base_url(self):
+        base_url = self.config['base-url']
+        self.assertEqual(self.session.base_url(), base_url)
+        assert 'https-url' not in self.config
+        self.assertEqual(self.session.base_url(secure=True), base_url)
+        secure_base_url = base_url.replace('http', 'https')
+        self.config.global_set_option('https-url', secure_base_url)
+        self.assertEqual(self.session.base_url(secure=True), secure_base_url)
+
     def test_view_catch_ex(self):
         req = self.request()
         rset = self.execute('CWUser X WHERE X login "hop"')