Here are the examples of the python api unit_test.mock.mocked_request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
18 Examples
3
Source : test_connection.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_connection_ok(self):
mocked_request(mock_request_200_connection)
response = self.connection.test()
expected_response = {"success": True}
self.assertEqual(response, expected_response)
@parameterized.expand(
3
Source : test_dAdd.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_not_ok(self, mock_request, exception):
mocked_request(mock_request)
with self.assertRaises(PluginException) as context:
self.action.run(self.params)
self.assertEqual(context.exception.cause, exception)
3
Source : test_dlCreate.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_not_ok(self, mock_request, exception):
mocked_request(mock_request)
with self.assertRaises(PluginException) as context:
self.action.run(self.params_data)
self.assertEqual(context.exception.cause, exception)
3
Source : test_dlGetAll.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_not_ok(self, mock_request, exception):
mocked_request(mock_request)
with self.assertRaises(PluginException) as context:
self.action.run()
self.assertEqual(context.exception.cause, exception)
3
Source : test_close_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_close_alert_when_status_error(self, mock_request, exception):
mocked_request(mock_request)
with self.assertRaises(PluginException) as context:
self.action.run(self.params)
self.assertEqual(
context.exception.cause,
PluginException.causes[exception],
)
def test_close_alert_user_over_100_characters(self):
3
Source : test_close_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_close_alert_user_over_100_characters(self):
mocked_request(mock_request_500)
payload = {**self.params, "user": "LongUsername" * 101}
with self.assertRaises(PluginException) as context:
self.action.run(payload)
self.assertEqual(
context.exception.cause,
PluginException.causes[PluginException.Preset.UNKNOWN],
)
self.assertEqual(
context.exception.data,
'Limit of maximum input characters for parameter "user" has been exceeded (maximum characters 100)',
)
3
Source : test_connection.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_connection_exception(self, mock_request, exception):
mocked_request(mock_request)
with self.assertRaises(ConnectionTestException) as context:
self.connection.test()
self.assertEqual(
context.exception.cause,
PluginException.causes[exception],
)
3
Source : test_create_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_create_alert_when_status_ok(self):
mocked_request(mock_request_202)
response = self.action.run(self.params)
expected_response = {
Output.RESULT: "Request will be processed",
Output.REQUESTID: STUB_REQUEST_ID,
Output.ELAPSED_TIME: 0.302,
Output.ALERTID: STUB_ALERT_ID,
}
self.assertEqual(response, expected_response)
@mock.patch("icon_opsgenie.util.api.ApiClient._get_request_status", return_value=STUB_REQUEST_RESPONSE_NO_ALERT)
3
Source : test_create_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_create_alert_when_no_alertId(self, mock_get_request):
mocked_request(mock_request_202)
with self.assertRaises(PluginException) as context:
self.action.run(self.params)
self.assertEqual(
context.exception.cause,
PluginException.causes[PluginException.Preset.NOT_FOUND],
)
@parameterized.expand(
3
Source : test_create_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_create_alert_when_status_error(self, mock_request, exception):
mocked_request(mock_request)
with self.assertRaises(PluginException) as context:
self.action.run(self.params)
self.assertEqual(
context.exception.cause,
PluginException.causes[exception],
)
def test_create_alert_no_message(self):
3
Source : test_create_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_create_alert_no_message(self):
mocked_request(mock_request_500)
with self.assertRaises(PluginException) as context:
self.action.run()
self.assertEqual(
context.exception.cause,
PluginException.causes[PluginException.Preset.UNKNOWN],
)
self.assertEqual(context.exception.data, "No required parameter has been entered")
def test_create_alert_message_over_130_characters(self):
3
Source : test_create_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_create_alert_message_over_130_characters(self):
mocked_request(mock_request_500)
payload = {"message": "LongMessage" * 131}
with self.assertRaises(PluginException) as context:
self.action.run(payload)
self.assertEqual(
context.exception.cause,
PluginException.causes[PluginException.Preset.UNKNOWN],
)
self.assertEqual(
context.exception.data,
'Limit of maximum input characters for parameter "message" has been exceeded (maximum characters 130)',
)
def test_create_alert_user_over_100_characters(self):
3
Source : test_create_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_create_alert_user_over_100_characters(self):
mocked_request(mock_request_500)
payload = {"message": "An example message", "user": "LongUsername" * 101}
with self.assertRaises(PluginException) as context:
self.action.run(payload)
self.assertEqual(
context.exception.cause,
PluginException.causes[PluginException.Preset.UNKNOWN],
)
self.assertEqual(
context.exception.data,
'Limit of maximum input characters for parameter "user" has been exceeded (maximum characters 100)',
)
def test_create_alert_actions_over_10_elements(self):
3
Source : test_create_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_create_alert_actions_over_10_elements(self):
mocked_request(mock_request_500)
payload = {**self.params, "actions": [str(element) for element in range(1, 12)]}
with self.assertRaises(PluginException) as context:
self.action.run(payload)
self.assertEqual(
context.exception.cause,
PluginException.causes[PluginException.Preset.UNKNOWN],
)
self.assertEqual(
context.exception.data,
'Limit of maximum input characters for parameter "actions" has been exceeded (maximum elements 10)',
)
def test_create_alert_actions_over_50_characters(self):
3
Source : test_create_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_create_alert_actions_over_50_characters(self):
mocked_request(mock_request_500)
payload = {**self.params, "actions": ["First", "LongActionName" * 51]}
with self.assertRaises(PluginException) as context:
self.action.run(payload)
self.assertEqual(
context.exception.cause,
PluginException.causes[PluginException.Preset.UNKNOWN],
)
self.assertEqual(
context.exception.data,
'Limit of maximum input characters for parameter "actions" has been exceeded (maximum characters 50)',
)
3
Source : test_get_alert.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_get_alert_when_status_error(self, mock_request, exception):
mocked_request(mock_request)
with self.assertRaises(PluginException) as context:
self.action.run(self.params)
self.assertEqual(
context.exception.cause,
PluginException.causes[exception],
)
3
Source : test_get_on_calls.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_get_on_calls_when_status_error(self, mock_request, exception):
mocked_request(mock_request)
with self.assertRaises(PluginException) as context:
self.action.run(self.params)
self.assertEqual(
context.exception.cause,
PluginException.causes[exception],
)
0
Source : test_connection.py
with MIT License
from rapid7
with MIT License
from rapid7
def test_connection_exception(self, mock_request, exception):
mocked_request(mock_request)
with self.assertRaises(ConnectionTestException) as context:
self.connection.test()
self.assertEqual(context.exception.cause, PluginException.causes[exception])