Exemplo n.º 1
0
 def setUp(self):
     self.i = Inject()
Exemplo n.º 2
0
class InjectTest(unittest.TestCase):

    def setUp(self):
        self.i = Inject()

    @mock.patch('httplib.HTTPConnection')
    def test_message_accepted(self, _conn):
        _conn.return_value.getresponse.return_value.status = 200
        self.i.postmessage('everything alright')
        self.assertEqual(0, self.i.returncode)

    @mock.patch('httplib.HTTPConnection')
    def test_unauthorized(self, _conn):
        _conn.return_value.getresponse.return_value.status = 401
        self.i.postmessage('unauthorized')
        self.assertEqual(77, self.i.returncode)

    @mock.patch('httplib.HTTPConnection')
    def test_not_found(self, _conn):
        _conn.return_value.getresponse.return_value.status = 404
        self.i.postmessage('not found')
        self.assertEqual(67, self.i.returncode)

    @mock.patch('httplib.HTTPConnection')
    def test_bad_request(self, _conn):
        _conn.return_value.getresponse.return_value.status = 400
        self.i.postmessage('bad request')
        self.assertEqual(78, self.i.returncode)

    @mock.patch('httplib.HTTPConnection')
    def test_bad_gateway(self, _conn):
        _conn.return_value.getresponse.return_value.status = 502
        self.i.postmessage('bad gateway')
        self.assertEqual(75, self.i.returncode)

    @mock.patch('httplib.HTTPConnection')
    def test_socket_error(self, _conn):
        _conn.return_value.request.side_effect = socket.error()
        self.i.postmessage('bad gateway')
        self.assertEqual(75, self.i.returncode)