Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    def test_without_raise(self):
        exception = TypeError("Hello", "there")
        test_defense = defensive_exception("this_test", exception, True)

        self.assertTrue(test_defense)