Example #1
0
    def test_send(self, mock_socket):
        with pyboinc.BoincSocket('3323', 1234, 3) as bc:
            bc.send(b'asdfasdf')

        mock_socket.assert_called_with(('3323', 1234), timeout=3)
        mock_socket.return_value.sendall.assert_called_with(b'asdfasdf\x03')
        mock_socket.return_value.close.assert_called_with()
Example #2
0
    def test_call_multipart(self, mock_socket):
        mock_socket.return_value.recv.side_effect = [b'some_', b'data\x03']
        with pyboinc.BoincSocket() as bc:
            expected = b'some_data'
            result = bc.call(b'<ssddff   />')
            assert expected == result

        mock_socket.assert_called_with((None, 31416), timeout=None)
        mock_socket.return_value.sendall.assert_called_with(b'<ssddff/>\x03')
        mock_socket.return_value.close.assert_called_with()
Example #3
0
 def test_clean_message(self, mock_socket):
     bs = pyboinc.BoincSocket()
     assert b'<a><b/></a>' == bs.clean_message(b'<a><b/></a>')
     assert b'<a><b/></a>' == bs.clean_message(b'<a><b /></a>')
     assert b'<a><b/></a>' == bs.clean_message(b'<a><b \t/></a>')
     assert b'<a><b/></a>' == bs.clean_message(b'<a><b \n\t/></a>')
Example #4
0
 def test_receive_error(self, mock_socket):
     mock_socket.return_value.recv.return_value = b''
     with pyboinc.BoincSocket() as bc:
         with pytest.raises(RuntimeError):
             bc.receive()
Example #5
0
 def test_receive_multipart(self, mock_socket):
     mock_socket.return_value.recv.side_effect = [b'some_', b'data\x03']
     with pyboinc.BoincSocket() as bc:
         expected = b'some_data'
         result = bc.receive()
         assert expected == result
Example #6
0
 def test_receive(self, mock_socket):
     mock_socket.return_value.recv.return_value = b'some_data\x03'
     with pyboinc.BoincSocket() as bc:
         expected = b'some_data'
         result = bc.receive()
         assert expected == result