[PATCH 1 of 3 saem_ref] [test/oai] Fix test failure with oaipmh 0.4.2 and cw 3.24

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Mar 22 13:41:05 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490180137 -3600
#      Wed Mar 22 11:55:37 2017 +0100
# Node ID 7115d84ee7ec0ccc8c430d9296e13ee37e83d100
# Parent  fff3daf3672daeade407c6478cc3e966adca2138
[test/oai] Fix test failure with oaipmh 0.4.2 and cw 3.24

oaipmh 0.4.2 is more pyramid based, triggering side effect on url building when using
cubicweb 3.24 (usage of https-url instead of base-url). Fix it using conditional
override of init_config, that will be removed once we depends on 3.25.

diff --git a/cubicweb_saem_ref/__init__.py b/cubicweb_saem_ref/__init__.py
--- a/cubicweb_saem_ref/__init__.py
+++ b/cubicweb_saem_ref/__init__.py
@@ -42,10 +42,11 @@ def cwuri_url(entity):
 
 
 def permanent_url(entity):
     """Return permanent URL for an entity: either ark based if entity has an ark, or <site url>/<eid>.
     """
+    print 'PERMANT URL FOR', entity, entity._cw, entity._cw.build_url('')
     ark = getattr(entity, 'ark', None)
     if ark is not None:
         return entity._cw.build_url('ark:/' + ark)
     return entity._cw.build_url(text_type(entity.eid))
 
diff --git a/test/test_oai.py b/test/test_oai.py
--- a/test/test_oai.py
+++ b/test/test_oai.py
@@ -21,19 +21,21 @@ import time
 
 from dateutil.parser import parse as parse_date
 from lxml import etree
 import pytz
 
+from cubicweb import __pkginfo__
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.pyramid.test import PyramidCWTest
 
 from cubes.oaipmh.views import OAIError, OAIRequest
 
 from cubicweb_saem_ref import permanent_url
 
 import testutils
 
+CW_324 = __pkginfo__.numversion < (3, 25)
 
 EntityInfo = namedtuple('EntityInfo', ['ark', 'url', 'eid'])
 
 
 def publish_entity(entity):
@@ -169,10 +171,18 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
     }
 
     _validate_xml = True
     _debug_xml = False
 
+    if CW_324:
+        # webapp is initialized with https as url scheme, which trigger usage of https-url instead
+        # of base-url in 3.24, but tests below rely in base-url being used.
+        @classmethod
+        def init_config(cls, config):
+            super(PyramidCWTest, cls).init_config(config)
+            config.global_set_option('https-url', config['base-url'])
+
     def oai_request(self, req, **formparams):
         response = self.webapp.get('/oai', formparams)
         self.assertEqual(response.headers['Content-Type'], 'text/xml; charset=UTF-8')
         if self._validate_xml:
             self.assertXmlValid(response.body, self.datapath('OAI-PMH.xsd'),


More information about the saem-devel mailing list