def test_update_session(self, mocker, requests_mock, requested_object, is_successful): requests_mock.post(BASE_URL + 'api/core/security/login', json=requested_object) mocker.patch.object(demisto, 'results') client = Client(BASE_URL, '', '', '', '') if is_successful: client.update_session() assert demisto.results.call_count == 0 else: with pytest.raises(SystemExit) as e: # in case login wasn't successful, return_error will exit with a reason (for example, LoginNotValid) # return_error reached client.update_session() assert e
def test_update_session_fail_parsing(self, mocker): """ Given: an exception raised from _http_request who failed to pares json object When: - initiating session Then: - Raise exception with message to check the provided url """ mocker.patch.object(Client, '_http_request', side_effect=DemistoException("Failed to parse json object from " "response: b\"<html><head><script>" "window.top.location='/Default.aspx';" "</script></head><body>" "</body></html>")) client = Client(BASE_URL, '', '', '', '') with pytest.raises(DemistoException) as e: client.update_session() assert "Check the given URL, it can be a redirect issue" in str(e.value)