def test_get_all_from_cadi_when_cadi_server_down_returns_503(app): responses.add(responses.GET, current_app.config['CADI_GET_ALL_URL'], status=500) with raises(ExternalAPIException): get_all_from_cadi()
def test_get_all_from_cadi_when_cadi_server_down_returns_503(mock_get_sso_cookie_for_cadi, app): cadi_id = 'ANA-00-000' mock_get_sso_cookie_for_cadi.return_value = dict(cookies_are='example_cookie') responses.add(responses.POST, current_app.config['CADI_GET_ALL_URL'], status=500) with raises(ExternalAPIException) as e: get_all_from_cadi()
def test_get_all_from_cadi(mock_get_sso_cookie_for_cadi, app): cookie = dict(cookies_are='example_cookie') cadi_resp = dict(_embedded=dict(cadiLineCapInfoList=[ dict(code=u'dEXO-00-001', status=u'Inactive'), dict(code=u'dEXO-00-002', status=u'PUB'), dict(code=u'dEXO-00-003', status=u'SUPERSEDED') ])) mock_get_sso_cookie_for_cadi.return_value = cookie responses.add(responses.GET, current_app.config['CADI_GET_ALL_URL'], json=cadi_resp, status=200) output = list(get_all_from_cadi()) # check that request to glance is called with correct url and cookie url = 'https://icms.cern.ch/tools/restplus/relay/piggyback/' + \ 'cadi/history/capInfo' assert responses.calls[0].request.url == url assert responses.calls[0].request._cookies == cookie # check that inactive|supseded analysis are not returned assert dict(code='dEXO-00-001', status='Inactive') not in output assert dict(code='dEXO-00-003', status='SUPERSEDED') not in output # check that inactive|supseded analysis are not returned assert output == [dict(code='dEXO-00-002', status='PUB')]
def test_get_all_from_cadi(mock_get_sso_cookie_for_cadi, app): cookie = dict(cookies_are='example_cookie') cadi_resp = dict(data=[ dict(code=u'dANA-00-001', status=u'Inactive'), dict(code=u'dANA-00-002', status=u'PUB'), dict(code=u'dANA-00-003', status=u'SUPERSEDED') ]) mock_get_sso_cookie_for_cadi.return_value = cookie responses.add(responses.POST, current_app.config['CADI_GET_ALL_URL'], json=cadi_resp, status=200) output = get_all_from_cadi() # check that request to glance is called with correct url and cookie assert responses.calls[ 0].request.url == 'https://icms.cern.ch/tools/api/viewCadiLines' assert responses.calls[0].request._cookies == cookie # check that inactive|supseded analysis are not returned assert dict(code='dANA-00-001', status='Inactive') not in output assert dict(code='dANA-00-003', status='SUPERSEDED') not in output # check that inactive|supseded analysis are not returned assert output == [dict(code='dANA-00-002', status='PUB')]
def test_get_all_from_cadi(mock_generate_krb_cookie, app): cookie = dict(cookies_are='example_cookie') cadi_resp = dict(data=[ dict(code=u'dANA-00-001', status=u'Inactive'), dict(code=u'dANA-00-002', status=u'PUB'), dict(code=u'dANA-00-003', status=u'SUPERSEDED') ]) mock_generate_krb_cookie.return_value = cookie responses.add(responses.POST, current_app.config['CADI_GET_ALL_URL'], json=cadi_resp, status=200) output = get_all_from_cadi() # check that request to glance is called with correct url and cookie assert responses.calls[0].request.url == 'https://icms.cern.ch/tools/api/viewCadiLines' assert responses.calls[0].request._cookies == cookie # check that inactive|supseded analysis are not returned assert dict(code='dANA-00-001', status='Inactive') not in output assert dict(code='dANA-00-003', status='SUPERSEDED') not in output # check that inactive|supseded analysis are not returned assert output == [dict(code='dANA-00-002', status='PUB')]
def test_get_all_from_cadi_when_cadi_server_down_while_asking_for_auth_returns_503( app): with raises(ExternalAPIException): get_all_from_cadi()
def test_get_all_from_cadi_when_cadi_server_down_while_asking_for_auth_returns_503(mock_get_sso_cookie_for_cadi, app): cadi_id = 'ANA-00-000' mock_get_sso_cookie_for_cadi.side_effect = ExternalAPIException() with raises(ExternalAPIException): get_all_from_cadi()