Exemplo n.º 1
0
class TestRecvAll(unittest.TestCase):
    def setUp(self):
        self.s = PapovoxLikeServer()

    def test_single_try(self):
        self.s.socket = SocketMock()
        self.assertEqual(len(self.s.recvall(23)), 23)

    def test_multiple_tries(self):
        self.s.socket = SocketMock(recv_size=2)
        self.assertEqual(len(self.s.recvall(23)), 23)

    def test_can_ask_for_nothing(self):
        self.s.socket = SocketMock(recv_size=2)
        self.assertEqual(len(self.s.recvall(0)), 0)

    def test_nothing_is_an_error(self):
        self.s.socket = SocketMock(recv_size=0)
        self.assertRaises(socket.error, self.s.recvall, 23)

    def test_nothing_is_not_an_error_when_asked_for_nothing(self):
        self.s.socket = SocketMock(recv_size=0)
        self.assertEqual(len(self.s.recvall(0)), 0)

    def test_no_more_than_asked(self):
        self.s.socket = SocketMock(recv_size=42)
        self.assertEqual(len(self.s.recvall(23)), 23)
Exemplo n.º 2
0
class TestRecvAll(unittest.TestCase):
    def setUp(self):
        self.s = PapovoxLikeServer()

    def test_single_try(self):
        self.s.socket = SocketMock()
        self.assertEqual(len(self.s.recvall(23)), 23)

    def test_multiple_tries(self):
        self.s.socket = SocketMock(recv_size=2)
        self.assertEqual(len(self.s.recvall(23)), 23)

    def test_can_ask_for_nothing(self):
        self.s.socket = SocketMock(recv_size=2)
        self.assertEqual(len(self.s.recvall(0)), 0)

    def test_nothing_is_an_error(self):
        self.s.socket = SocketMock(recv_size=0)
        self.assertRaises(socket.error, self.s.recvall, 23)

    def test_nothing_is_not_an_error_when_asked_for_nothing(self):
        self.s.socket = SocketMock(recv_size=0)
        self.assertEqual(len(self.s.recvall(0)), 0)

    def test_no_more_than_asked(self):
        self.s.socket = SocketMock(recv_size=42)
        self.assertEqual(len(self.s.recvall(23)), 23)
Exemplo n.º 3
0
    def setUp(self):
        # Caixa de mensagens de sistema
        self.sysbox = []

        class FakeSocket(object):
            @staticmethod
            def sendall(data):
                self.sysbox.append(data)

        self.s = PapovoxLikeServer()
        self.s.socket = FakeSocket()
Exemplo n.º 4
0
class TestAccept(unittest.TestCase):
    addr = ('127.9.9.9', 9999)

    def setUp(self):
        self.s = PapovoxLikeServer()

    def test_basic(self):
        nickname = u"Olavo".encode(SYSTEM_ENCODING)
        self.s.server_socket = PapovoxSocketMock(self.addr, nickname)
        client_socket = self.s.server_socket.client_socket
        self.s._accept()
        self.assertEqual((self.s.socket, self.s.addr, self.s.nickname),
                         (client_socket, self.addr, nickname))

    def test_nickname_with_accents(self):
        nickname = u"Anônimo".encode(SYSTEM_ENCODING)
        self.s.server_socket = PapovoxSocketMock(self.addr, nickname)
        client_socket = self.s.server_socket.client_socket
        self.s._accept()
        self.assertEqual((self.s.socket, self.s.addr, self.s.nickname),
                         (client_socket, self.addr, nickname))
Exemplo n.º 5
0
class TestAccept(unittest.TestCase):
    addr = ('127.9.9.9', 9999)

    def setUp(self):
        self.s = PapovoxLikeServer()

    def test_basic(self):
        nickname = u"Olavo".encode(SYSTEM_ENCODING)
        self.s.server_socket = PapovoxSocketMock(self.addr, nickname)
        client_socket = self.s.server_socket.client_socket
        self.s._accept()
        self.assertEqual((self.s.socket, self.s.addr, self.s.nickname),
                         (client_socket, self.addr, nickname))

    def test_nickname_with_accents(self):
        nickname = u"Anônimo".encode(SYSTEM_ENCODING)
        self.s.server_socket = PapovoxSocketMock(self.addr, nickname)
        client_socket = self.s.server_socket.client_socket
        self.s._accept()
        self.assertEqual((self.s.socket, self.s.addr, self.s.nickname),
                         (client_socket, self.addr, nickname))
Exemplo n.º 6
0
class TestRecv(unittest.TestCase):
    def setUp(self):
        self.s = PapovoxLikeServer()

    def test_exact_amount(self):
        self.s.socket = SocketMock()
        self.assertEqual(len(self.s.recv(23)), 23)

    def test_less_data(self):
        self.s.socket = SocketMock(recv_size=2)
        self.assertEqual(len(self.s.recv(23)), 2)

    def test_nothing_is_an_error(self):
        self.s.socket = SocketMock(recv_size=0)
        self.assertRaises(socket.error, self.s.recv, 23)

    def test_nothing_is_not_an_error_when_asked_for_nothing(self):
        self.s.socket = SocketMock(recv_size=0)
        self.assertEqual(len(self.s.recv(0)), 0)

    def test_no_more_than_asked(self):
        self.s.socket = SocketMock(recv_size=42)
        self.assertEqual(len(self.s.recv(23)), 23)
Exemplo n.º 7
0
class TestRecv(unittest.TestCase):
    def setUp(self):
        self.s = PapovoxLikeServer()

    def test_exact_amount(self):
        self.s.socket = SocketMock()
        self.assertEqual(len(self.s.recv(23)), 23)

    def test_less_data(self):
        self.s.socket = SocketMock(recv_size=2)
        self.assertEqual(len(self.s.recv(23)), 2)

    def test_nothing_is_an_error(self):
        self.s.socket = SocketMock(recv_size=0)
        self.assertRaises(socket.error, self.s.recv, 23)

    def test_nothing_is_not_an_error_when_asked_for_nothing(self):
        self.s.socket = SocketMock(recv_size=0)
        self.assertEqual(len(self.s.recv(0)), 0)

    def test_no_more_than_asked(self):
        self.s.socket = SocketMock(recv_size=42)
        self.assertEqual(len(self.s.recv(23)), 23)
Exemplo n.º 8
0
 def setUp(self):
     self.s = PapovoxLikeServer()
Exemplo n.º 9
0
 def setUp(self):
     self.s = PapovoxLikeServer()