Exemplo n.º 1
0
class TestMessage:
    """
    Проверка основных методов класса Message из модуля systems.jim
    """
    def setup(self):
        self.monkeypatch = MonkeyPatch()
        self.monkeypatch.setattr("socket.socket", SocketTest)
        self.sock = socket.socket()
        self.m = JIMMessage()

    def teardown(self):
        del self.sock
        del self.monkeypatch
        del self.m

    def test_encoding(self):
        self.m = JIMMessage(DICT_TEST_DATA)
        assert BYTE_TEST_DATA == self.m.encoded_message

    def test_decoding(self):
        self.m = JIMMessage(BYTE_TEST_DATA)
        assert DICT_TEST_DATA == self.m.dict_message

    def test_decoding_bad_message(self):
        with pytest.raises(DecodedMessageError):
            JIMMessage(WRONG_BYTE_TEST_DATA)

    def test_encoding_bad_message(self):
        with pytest.raises(TypeError):
            JIMMessage(123)

    def test_wrong_message_type(self):
        with pytest.raises(TypeError):
            JIMMessage(123)

    def test_send(self):
        self.m.create_presence_message()
        self.m.send_message(self.sock)
        assert self.sock.data == self.m.encoded_message

    def test_receive(self):
        self.m.rcv_message(self.sock)
        assert self.m.dict_message.get(RESPONSE) == OK

    def test_bad_receive(self):
        self.monkeypatch.setattr('socket.socket', WrongSocketTest)
        self.sock = socket.socket()
        with pytest.raises(ClosedSocketError):
            self.m.rcv_message(self.sock)

    def test_send_recv_message(self):
        self.m.encoded_message = BYTE_TEST_DATA
        self.m.send_rcv_message(self.sock)
        assert self.sock.data == BYTE_TEST_DATA
        assert self.m.dict_message.get(RESPONSE) == OK
Exemplo n.º 2
0
 def test_wrong_message_type(self):
     with pytest.raises(TypeError):
         JIMMessage(123)
Exemplo n.º 3
0
 def test_encoding_bad_message(self):
     with pytest.raises(TypeError):
         JIMMessage(123)
Exemplo n.º 4
0
 def test_decoding_bad_message(self):
     with pytest.raises(DecodedMessageError):
         JIMMessage(WRONG_BYTE_TEST_DATA)
Exemplo n.º 5
0
 def test_decoding(self):
     self.m = JIMMessage(BYTE_TEST_DATA)
     assert DICT_TEST_DATA == self.m.dict_message
Exemplo n.º 6
0
 def test_encoding(self):
     self.m = JIMMessage(DICT_TEST_DATA)
     assert BYTE_TEST_DATA == self.m.encoded_message
Exemplo n.º 7
0
 def setup(self):
     self.monkeypatch = MonkeyPatch()
     self.monkeypatch.setattr("socket.socket", SocketTest)
     self.sock = socket.socket()
     self.m = JIMMessage()