2018-02-11 11:42:13 +00:00
|
|
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2018 OpenLP Developers #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
"""
|
|
|
|
Package to test the PJLink UDP functions
|
|
|
|
"""
|
|
|
|
|
|
|
|
from unittest import TestCase
|
|
|
|
from unittest.mock import call, patch
|
|
|
|
|
|
|
|
import openlp.core.projectors.pjlink
|
2018-04-20 06:04:43 +00:00
|
|
|
from openlp.core.projectors.constants import PJLINK_PORT
|
2018-02-11 11:42:13 +00:00
|
|
|
|
2018-05-03 14:58:50 +00:00
|
|
|
from openlp.core.projectors.pjlink import PJLinkUDP
|
|
|
|
from tests.resources.projector.data import TEST1_DATA
|
2018-02-11 11:42:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestPJLinkBase(TestCase):
|
|
|
|
"""
|
|
|
|
Tests for the PJLinkUDP class
|
|
|
|
"""
|
|
|
|
@patch.object(openlp.core.projectors.pjlink, 'log')
|
|
|
|
def test_get_datagram_data_negative_zero_length(self, mock_log):
|
|
|
|
"""
|
|
|
|
Test get_datagram when pendingDatagramSize = 0
|
|
|
|
"""
|
|
|
|
# GIVEN: Test setup
|
2018-05-03 14:58:50 +00:00
|
|
|
pjlink_udp = PJLinkUDP()
|
|
|
|
log_warning_calls = [call('(UDP) No data (-1)')]
|
|
|
|
log_debug_calls = [call('(UDP) PJLinkUDP() Initialized for port 4352'),
|
2018-02-11 11:42:13 +00:00
|
|
|
call('(UDP) get_datagram() - Receiving data')]
|
|
|
|
with patch.object(pjlink_udp, 'pendingDatagramSize') as mock_datagram, \
|
|
|
|
patch.object(pjlink_udp, 'readDatagram') as mock_read:
|
|
|
|
mock_datagram.return_value = -1
|
|
|
|
mock_read.return_value = ('', TEST1_DATA['ip'], PJLINK_PORT)
|
|
|
|
|
|
|
|
# WHEN: get_datagram called with 0 bytes ready
|
|
|
|
pjlink_udp.get_datagram()
|
|
|
|
|
|
|
|
# THEN: Log entries should be made and method returns
|
2018-05-03 14:58:50 +00:00
|
|
|
mock_log.warning.assert_has_calls(log_warning_calls)
|
2018-02-11 11:42:13 +00:00
|
|
|
mock_log.debug.assert_has_calls(log_debug_calls)
|
|
|
|
|
|
|
|
@patch.object(openlp.core.projectors.pjlink, 'log')
|
|
|
|
def test_get_datagram_data_no_data(self, mock_log):
|
|
|
|
"""
|
|
|
|
Test get_datagram when data length = 0
|
|
|
|
"""
|
|
|
|
# GIVEN: Test setup
|
2018-05-03 14:58:50 +00:00
|
|
|
pjlink_udp = PJLinkUDP()
|
|
|
|
log_warning_calls = [call('(UDP) get_datagram() called when pending data size is 0')]
|
|
|
|
log_debug_calls = [call('(UDP) PJLinkUDP() Initialized for port 4352'),
|
|
|
|
call('(UDP) get_datagram() - Receiving data')]
|
2018-02-11 11:42:13 +00:00
|
|
|
with patch.object(pjlink_udp, 'pendingDatagramSize') as mock_datagram, \
|
|
|
|
patch.object(pjlink_udp, 'readDatagram') as mock_read:
|
2018-04-20 06:04:43 +00:00
|
|
|
mock_datagram.return_value = 0
|
2018-02-11 11:42:13 +00:00
|
|
|
mock_read.return_value = ('', TEST1_DATA['ip'], PJLINK_PORT)
|
|
|
|
|
|
|
|
# WHEN: get_datagram called with 0 bytes ready
|
|
|
|
pjlink_udp.get_datagram()
|
|
|
|
|
|
|
|
# THEN: Log entries should be made and method returns
|
2018-05-03 14:58:50 +00:00
|
|
|
mock_log.warning.assert_has_calls(log_warning_calls)
|
2018-02-11 11:42:13 +00:00
|
|
|
mock_log.debug.assert_has_calls(log_debug_calls)
|
|
|
|
|
|
|
|
@patch.object(openlp.core.projectors.pjlink, 'log')
|
|
|
|
def test_get_datagram_pending_zero_length(self, mock_log):
|
|
|
|
"""
|
|
|
|
Test get_datagram when pendingDatagramSize = 0
|
|
|
|
"""
|
|
|
|
# GIVEN: Test setup
|
2018-05-03 14:58:50 +00:00
|
|
|
pjlink_udp = PJLinkUDP()
|
|
|
|
log_warning_calls = [call('(UDP) get_datagram() called when pending data size is 0')]
|
|
|
|
log_debug_calls = [call('(UDP) PJLinkUDP() Initialized for port 4352'),
|
2018-02-11 11:42:13 +00:00
|
|
|
call('(UDP) get_datagram() - Receiving data')]
|
|
|
|
with patch.object(pjlink_udp, 'pendingDatagramSize') as mock_datagram:
|
|
|
|
mock_datagram.return_value = 0
|
|
|
|
|
|
|
|
# WHEN: get_datagram called with 0 bytes ready
|
|
|
|
pjlink_udp.get_datagram()
|
|
|
|
|
|
|
|
# THEN: Log entries should be made and method returns
|
2018-05-03 14:58:50 +00:00
|
|
|
mock_log.warning.assert_has_calls(log_warning_calls)
|
2018-02-11 11:42:13 +00:00
|
|
|
mock_log.debug.assert_has_calls(log_debug_calls)
|