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 |
|
-
|