[PATCH oaipmh] Compute OAIRequest's baseurl using Pyramid request's route_url()

Philippe Pepiot philippe.pepiot at logilab.fr
Wed Jun 21 16:08:48 CEST 2017


On 06/21/2017 01:49 PM, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1498044729 -7200
> #      Wed Jun 21 13:32:09 2017 +0200
> # Node ID fe827aac878676a13330726bfd80073de88eba3c
> # Parent  d41c3bf1919f359f52621328510fe6c1832563b9
> Compute OAIRequest's baseurl using Pyramid request's route_url()
> 
> Previously, we used `request.cw_cnx.build_url('oai')` which is a CubicWeb
> method whereas the "oai" route is defined in pure Pyramid. So using
> request.route_url('oai') is the correct way to retrieve the base URL of
> OAI-PMH endpoint.
> 
> Along the way, make OAIRequest.from_request() build the URL itself (from
> passed "request") instead of receiving it.
> 


Applied, thanks !


> diff --git a/test/test_oaipmh.py b/test/test_oaipmh.py
> --- a/test/test_oaipmh.py
> +++ b/test/test_oaipmh.py
> @@ -327,7 +327,7 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
>      def test_noverb(self):
>          with self.admin_access.web_request() as req:
>              result = self.oai_request(req)
> -        self.assertIn('<request>http://testing.fr/cubicweb/oai</request>',
> +        self.assertIn('<request>https://localhost:80/oai</request>',
>                        result)
>          self.assertIn('<error code="badVerb">no verb specified</error',
>                        result)
> @@ -335,7 +335,7 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
>      def test_badverb(self):
>          with self.admin_access.web_request() as req:
>              result = self.oai_request(req, verb='coucou')
> -        self.assertIn('<request>http://testing.fr/cubicweb/oai</request>',
> +        self.assertIn('<request>https://localhost:80/oai</request>',
>                        result)
>          self.assertIn('<error code="badVerb">illegal verb "coucou"</error>',
>                        result)
> @@ -407,7 +407,7 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
>              cnx.commit()
>          with self.admin_access.web_request() as req:
>              result = self.oai_request(req, verb='ListSets')
> -        self.assertIn('<request verb="ListSets">http://testing.fr/cubicweb/oai</request>',
> +        self.assertIn('<request verb="ListSets">https://localhost:80/oai</request>',
>                        result)
>          for spec in ('agent', 'activity'):
>              self.assertIn('<setSpec>{0}</setSpec>'.format(spec),
> @@ -422,7 +422,7 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
>      def test_listidentifiers_no_metadataprefix(self):
>          with self.admin_access.web_request() as req:
>              result = self.oai_request(req, verb='ListIdentifiers')
> -        self.assertIn('<request>http://testing.fr/cubicweb/oai</request>',
> +        self.assertIn('<request>https://localhost:80/oai</request>',
>                        result)
>          self.assertIn(('<error code="badArgument">'
>                         'ListIdentifiers verb requires a "metadataPrefix" restriction'
> @@ -558,7 +558,7 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
>      def test_listrecords_noargument(self):
>          with self.admin_access.web_request() as req:
>              result = self.oai_request(req, verb='ListRecords')
> -        self.assertIn('<request>http://testing.fr/cubicweb/oai</request>',
> +        self.assertIn('<request>https://localhost:80/oai</request>',
>                        result)
>          expected = (
>              '<error code="badArgument">'
> diff --git a/views.py b/views.py
> --- a/views.py
> +++ b/views.py
> @@ -114,7 +114,8 @@ class OAIRequest(object):
>      """Represent an OAI-PMH request."""
>  
>      @classmethod
> -    def from_request(cls, baseurl, request):
> +    def from_request(cls, request):
> +        baseurl = request.route_url('oai')
>          return cls(
>              baseurl,
>              setspec=request.params.get('set'),
> @@ -346,9 +347,7 @@ class OAIView(object):
>      def __init__(self, request):
>          self.request = request
>          self._cw = request.cw_request
> -        baseurl = request.cw_cnx.build_url('oai')
> -        self.oai_request = OAIRequest.from_request(
> -            baseurl, request)
> +        self.oai_request = OAIRequest.from_request(request)
>  
>      def __call__(self):
>          encoding = self._cw.encoding
> 



More information about the saem-devel mailing list