Projet

Général

Profil

0001-plone_restapi-add-check_status-method-61215.patch

Nicolas Roche, 28 janvier 2022 16:26

Télécharger (3,19 ko)

Voir les différences:

Subject: [PATCH] plone_restapi: add check_status method (#61215)

 passerelle/apps/plone_restapi/models.py |  6 +++++
 tests/test_plone_restapi.py             | 29 +++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
passerelle/apps/plone_restapi/models.py
167 167
            except ValueError as e:
168 168
                raise APIError('PloneRestApi: bad JSON response')
169 169
        try:
170 170
            response.raise_for_status()
171 171
        except RequestException as e:
172 172
            raise APIError('PloneRestApi: %s "%s"' % (e, json_response))
173 173
        return json_response
174 174

  
175
    def check_status(self):
176
        """
177
        Raise an exception if something goes wrong.
178
        """
179
        self.request(path='@types', method='GET')
180

  
175 181
    def call_search(
176 182
        self,
177 183
        uri='',
178 184
        text_template='',
179 185
        filter_expression='',
180 186
        sort=None,
181 187
        order=True,
182 188
        limit=None,
tests/test_plone_restapi.py
220 220

  
221 221
        # make sure the token from cache is used
222 222
        connector.get_token()
223 223
        assert mocked.handlers[0].call['count'] == 1
224 224
        connector.get_token(True)
225 225
        assert mocked.handlers[0].call['count'] == 2
226 226

  
227 227

  
228
def test_check_status(app, connector):
229
    url = connector.service_url + '/@types'
230
    with utils.mock_url(url=connector.token_ws_url, response=TOKEN_RESPONSE):
231
        with utils.mock_url(url=url, response={}):
232
            connector.check_status()
233

  
234
    # idp not responding
235
    with utils.mock_url(url=connector.token_ws_url, response={}, status_code=503):
236
        with pytest.raises(APIError):
237
            connector.check_status()
238

  
239
    # plone not responding
240
    with utils.mock_url(url=connector.token_ws_url, response=TOKEN_RESPONSE):
241
        with utils.mock_url(url=url, response={}, status_code=503):
242
            with pytest.raises(APIError):
243
                connector.check_status()
244

  
245
    # without idp
246
    connector.token_ws_url = ''
247
    connector.save()
248
    with utils.mock_url(url=url, response={}):
249
        connector.check_status()
250

  
251
    # plone not responding
252
    with utils.mock_url(url=url, response={}, status_code=503):
253
        with pytest.raises(APIError):
254
            connector.check_status()
255

  
256

  
228 257
def test_fetch(app, connector, token):
229 258
    endpoint = utils.generic_endpoint_url('plone-restapi', 'fetch', slug=connector.slug)
230 259
    assert endpoint == '/plone-restapi/my_connector/fetch'
231 260
    url = connector.service_url + '/braine-l-alleud/dccd85d12cf54b6899dff41e5a56ee7f'
232 261
    params = {
233 262
        'uid': 'dccd85d12cf54b6899dff41e5a56ee7f',
234 263
        'uri': 'braine-l-alleud',
235 264
        'text_template': '{{ title }} ({{ topics.0.title }})',
236
-