def test_type_error_with_message(self):
     try:
         raise TypeError("Hello", "there")
     except TypeError as e:
         test_defense = defensive_exception("this_test", e, True,
                                            "type error reached")
     self.assertTrue(test_defense)
 def test_type_error_with_dict_message(self):
     try:
         raise TypeError("Hello", "there")
     except TypeError as e:
         test_defense = defensive_exception("this_test", e, True,
                                            {"exception thrower": "tester"})
     self.assertTrue(test_defense)
    def test_type_error(self):
        try:
            raise TypeError("Hello", "there")
        except TypeError as e:
            test_defense = defensive_exception("this_test", e, True)

        self.assertTrue(test_defense)
    def test_exception_return_object(self):
        try:
            raise Exception("This is my exception", "testing")
        except Exception as e:
            res = defensive_exception("test_exception", e, self.pleb)

        self.assertEqual(self.pleb.email, res.email)
    def test_exception_return_boolean(self):
        try:
            raise Exception("This is my exception", "testing")
        except Exception as e:
            res = defensive_exception("test_exception", e, False)

        self.assertFalse(res)
    def test_exception_return_dict(self):
        try:
            raise Exception("This is my exception", "testing")
        except Exception as e:
            test_dict = {"hello": "world"}
            res = defensive_exception("test_exception", e, test_dict)

        self.assertEqual(res, test_dict)
    def test_exception_return_redirect(self):
        try:
            raise Exception("This is my exception", "testing")
        except Exception as e:
            res = defensive_exception("test_exception", e,
                                      redirect("404_Error"))

        self.assertIsInstance(res, HttpResponseRedirect)
    def test_without_raise(self):
        exception = TypeError("Hello", "there")
        test_defense = defensive_exception("this_test", exception, True)

        self.assertTrue(test_defense)