Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_success_one_success(self):
"""Verify success is calculated correctly if one response is successful"""
rs = executor.ResponseList([
SuccessfulResponseMock(None, 1),
FailingResponseMock(None, 1),
FailingResponseMock(None, 1),
FailingResponseMock(None, 1)
])
self.assertTrue(
rs.success(executor.SuccessOn.One),
'Unable to calculate success on one correctly with one response successful'
)
self.assertFalse(
rs.success(executor.SuccessOn.Most),
'Unable to calculate success on most with one response successful'
)
self.assertFalse(
rs.success(executor.SuccessOn.All),
'Unable to calculate success on all with one response successful'
)
def test_success_half_success(self):
"""Verify success is calculated correctly if half responses are successful"""
rs = executor.ResponseList([
SuccessfulResponseMock(None, 1),
SuccessfulResponseMock(None, 1),
FailingResponseMock(None, 1),
FailingResponseMock(None, 1)
])
self.assertTrue(
rs.success(executor.SuccessOn.One),
'Unable to calculate success on one correctly with half responses successful'
)
self.assertFalse(
rs.success(executor.SuccessOn.Most),
'Unable to calculate success on most with half responses successful'
)
self.assertFalse(
rs.success(executor.SuccessOn.All),
'Unable to calculate success on all with half responses successful'
)
rs = executor.ResponseList([
SuccessfulResponseMock(None, 1),
SuccessfulResponseMock(None, 1),
SuccessfulResponseMock(None, 1),
SuccessfulResponseMock(None, 1)
])
self.assertTrue(
rs.success(executor.SuccessOn.One),
'Unable to calculate success on one correctly with all responses successful'
)
self.assertTrue(
rs.success(executor.SuccessOn.Most),
'Unable to calculate success on most with all responses successful'
)
self.assertTrue(
rs.success(executor.SuccessOn.All),
'Unable to calculate success on all with all responses successful'
)
def success(self, option=SuccessOn.One):
"""Check success state of the request.
:param option: Sets a threshold for success sign. ( 1 - SuccessOn.One, 2 - SuccessOn.Most, 3 - SuccessOn.All )
:type option: int
:return: Whether this set of responses is successful
:rtype: bool
"""
result = False
success_list = [resp.success for resp in self._responses]
if option == SuccessOn.One:
result = True in success_list
elif option == SuccessOn.Most:
result = success_list.count(True) / len(success_list) > 0.5
elif option == SuccessOn.All:
result = False not in success_list
return result
def success(self, option=SuccessOn.One):
"""Check success state of the request.
:param option: Sets a threshold for success sign. ( 1 - SuccessOn.One, 2 - SuccessOn.Most, 3 - SuccessOn.All )
:type option: int
:return: Whether this set of responses is successful
:rtype: bool
"""
result = False
success_list = [resp.success for resp in self._responses]
if option == SuccessOn.One:
result = True in success_list
elif option == SuccessOn.Most:
result = success_list.count(True) / len(success_list) > 0.5
elif option == SuccessOn.All:
result = False not in success_list
return result