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_raise_without_args(self):
"""
Ensure that a default exception/code is used if the message requested
by the code provided requires an argument list and none is provided.
"""
with self.assertRaises(ResultException) as cm:
raise ResultException(101)
self.assertEqual(cm.exception.status_code, 100)
def test_raise_using_invalid_code(self):
"""
Ensure that a default exception/code is used if invalid code is provided.
"""
with self.assertRaises(ResultException) as cm:
raise ResultException('foo')
self.assertEqual(cm.exception.status_code, 100)
def test_raise_without_insufficient_args(self):
"""
Ensure that a default exception/code is used if the message requested
by the code provided requires an argument list but the one provided
does not contain the correct amount of arguments.
"""
with self.assertRaises(ResultException) as cm:
raise ResultException(102, 'foo')
self.assertEqual(cm.exception.status_code, 100)
def test_key_value_slicing_is_not_supported(self):
"""
Test __getitem__() fails when non-integer values for start and stop are
provided
"""
result = self.create_result()
with self.assertRaises(ResultException) as cm:
invalid_result = result['bar': 'foo']
self.assertEqual(cm.exception.status_code, 101)
def test_get_item_invalid_key_slice(self):
"""
Test that when invalid start and stop values are provided in a slice
an exception is raised. Specifically this happens when the slice start
and stop are different types.
"""
result = Result(self.view001)
with self.assertRaises(ResultException) as cm:
invalid_result = result['foo': ['bar', 'baz']]
self.assertEqual(cm.exception.status_code, 101)
ten = ResultByKey(10)
with self.assertRaises(ResultException) as cm:
invalid_result = result['foo': ten]
self.assertEqual(cm.exception.status_code, 101)
def test_key_value_access_is_not_supported(self):
"""
Test __getitem__() fails when a key value is provided
"""
result = self.create_result()
with self.assertRaises(ResultException) as cm:
invalid_result = result['foo']
self.assertEqual(cm.exception.status_code, 101)
def test_raise_without_code(self):
"""
Ensure that a default exception/code is used if none is provided.
"""
with self.assertRaises(ResultException) as cm:
raise ResultException()
self.assertEqual(cm.exception.status_code, 100)
def test_raise_with_proper_code_and_args(self):
"""
Ensure that the requested exception is raised.
"""
with self.assertRaises(ResultException) as cm:
raise ResultException(102, 'foo', 'bar')
self.assertEqual(cm.exception.status_code, 102)