forked from openlp/openlp
fix up tests
This commit is contained in:
parent
c6076e1054
commit
127f1dc7fd
@ -37,11 +37,19 @@ class Server(QtCore.QObject, LogMixin):
|
||||
self.id = 'OpenLPDual'
|
||||
|
||||
def is_another_instance_running(self):
|
||||
"""
|
||||
Check the see if an other instance is running
|
||||
:return: True of False
|
||||
"""
|
||||
# Is there another instance running?
|
||||
self.out_socket.connectToServer(self.id)
|
||||
return self.out_socket.waitForConnected()
|
||||
|
||||
def post_to_server(self, args):
|
||||
"""
|
||||
Post the file name to the over instance
|
||||
:param args: The passed arguments including maybe a file name
|
||||
"""
|
||||
if 'OpenLP' in args:
|
||||
args.remove('OpenLP')
|
||||
# Yes, there is.
|
||||
@ -51,18 +59,20 @@ class Server(QtCore.QObject, LogMixin):
|
||||
if not self.out_socket.waitForBytesWritten(10):
|
||||
raise Exception(str(self.out_socket.errorString()))
|
||||
self.out_socket.disconnectFromServer()
|
||||
return False
|
||||
|
||||
def start_server(self):
|
||||
# No, there isn't.
|
||||
self.out_socket = None
|
||||
self.out_stream = None
|
||||
self.in_socket = None
|
||||
self.in_stream = None
|
||||
self.server = QtNetwork.QLocalServer()
|
||||
self.server.listen(self._id)
|
||||
self.server.newConnection.connect(self._on_new_connection)
|
||||
return True
|
||||
"""
|
||||
Start the socket server to allow inter app communication
|
||||
:return:
|
||||
"""
|
||||
self.out_socket = None
|
||||
self.out_stream = None
|
||||
self.in_socket = None
|
||||
self.in_stream = None
|
||||
self.server = QtNetwork.QLocalServer()
|
||||
self.server.listen(self._id)
|
||||
self.server.newConnection.connect(self._on_new_connection)
|
||||
return True
|
||||
|
||||
def _on_new_connection(self):
|
||||
"""
|
||||
@ -80,7 +90,7 @@ class Server(QtCore.QObject, LogMixin):
|
||||
|
||||
def _on_ready_read(self):
|
||||
"""
|
||||
Read a record passed to the server and load a service
|
||||
Read a record passed to the server and pass to the service manager to handle
|
||||
:return:
|
||||
"""
|
||||
msg = self.in_stream.readLine()
|
||||
|
@ -51,9 +51,26 @@ class TestServer(TestCase, TestMixin):
|
||||
pass
|
||||
|
||||
def test_is_another_instance_running(self):
|
||||
"""
|
||||
Run a test as if this was the first time and no instance is running
|
||||
"""
|
||||
# GIVEN: A running Server
|
||||
# WHEN: I ask for it to start
|
||||
self.server.is_another_instance_running()
|
||||
value = self.server.is_another_instance_running()
|
||||
# THEN the following is called
|
||||
self.server.out_socket.waitForConnected.assert_called_once_with()
|
||||
self.server.out_socket.connectToServer.assert_called_once_with(self.server.id)
|
||||
assert isinstance(value, MagicMock)
|
||||
|
||||
def test_is_another_instance_running_true(self):
|
||||
"""
|
||||
Run a test as if there is another instance running
|
||||
"""
|
||||
# GIVEN: A running Server
|
||||
self.server.out_socket.waitForConnected.return_value = True
|
||||
# WHEN: I ask for it to start
|
||||
value = self.server.is_another_instance_running()
|
||||
# THEN the following is called
|
||||
self.server.out_socket.waitForConnected.assert_called_once_with()
|
||||
self.server.out_socket.connectToServer.assert_called_once_with(self.server.id)
|
||||
assert value is True
|
||||
|
Loading…
Reference in New Issue
Block a user