def test_start(self, Popen): backend = Backend.objects.create(name="foo") manager = ListenerManager() manager.start(backend) self.assertEqual(Popen.call_args[0][-1][-1], "foo")
def test_start(self, Popen): backend = Backend.objects.create(name="foo") manager = ListenerManager() manager.start(backend) self.assertEqual(Popen.call_args[0][-1][-1], "foo")
def test_start(self, Popen): backend = Backend.objects.create(name="foo") manager = ListenerManager(argv) manager.start(backend) Popen.assert_called_with(argv + ['foo'])
def test_start(self, Listener): backend = Backend.objects.create(name="foo") manager = ListenerManager() manager.start(backend) Listener.assert_called_with(backend) instance = Listener.return_value instance.start.assert_called_once()
def test_handle_listener(self, Listener, ListenerManager, Backend): backend = object() Backend.objects.get.return_value = backend command = Command() command.handle(BACKEND='foo') ListenerManager.assert_not_called() Listener.assert_called_with(backend) Listener.return_value.run.assert_called()
def test_handle_listener(self, Listener, ListenerManager, Backend): backend = object() Backend.objects.get.return_value = backend command = Command() command.handle(BACKEND='foo') ListenerManager.assert_not_called() Listener.assert_called_with(backend) Listener.return_value.run.assert_called()
def test_stop(self, Popen): backend = Backend.objects.create(name="foo") manager = ListenerManager() Popen.return_value.poll.return_value = None manager.start(backend) manager.stop(backend.id) Popen.return_value.poll.assert_called_once() Popen.return_value.terminate.assert_called_once() Popen.return_value.wait.assert_called_once()
def test_stop(self, Listener): backend = Backend.objects.create(name="foo") manager = ListenerManager() manager.start(backend) manager.stop(backend.id) Listener.return_value.terminate.assert_called_once()
def test_cleanup(self, Listener): backend1 = Backend.objects.create(name="foo") backend2 = Backend.objects.create(name="bar") manager = ListenerManager() manager.start(backend1) manager.start(backend2) manager.stop = MagicMock() manager.cleanup() manager.stop.assert_has_calls([call(backend1.id), call(backend2.id)], any_order=True)
def test_keep_listeners_running_changed(self, Listener): manager = ListenerManager() backend = Backend.objects.create(name="foo") # start existing backends manager.keep_listeners_running() manager.stop = MagicMock() manager.start = MagicMock() # backend is changed backend.name = 'bar' backend.save() manager.keep_listeners_running() manager.stop.assert_called_with(backend.id) manager.start.assert_called_with(backend)
def test_keep_listeners_running_added(self, Listener): manager = ListenerManager() backend1 = Backend.objects.create(name="foo") manager.start = MagicMock() manager.stop = MagicMock() # start existing backends manager.keep_listeners_running() manager.start.assert_called_with(backend1) # new backend, start it too backend2 = Backend.objects.create(name="bar") manager.keep_listeners_running() manager.start.assert_called_with(backend2) manager.stop.assert_not_called()
def test_keep_listeners_running_removed(self, Listener): manager = ListenerManager() backend = Backend.objects.create(name="foo") manager.stop = MagicMock() # start existing backends manager.keep_listeners_running() # backend is removed bid = backend.id backend.delete() manager.keep_listeners_running() manager.stop.assert_called_with(bid)
def test_cleanup(self, Popen): backend1 = Backend.objects.create(name="foo") backend2 = Backend.objects.create(name="bar") manager = ListenerManager() manager.start(backend1) manager.start(backend2) manager.stop = MagicMock() manager.cleanup() manager.stop.assert_has_calls([call(backend1.id), call(backend2.id)], any_order=True)
def test_stop(self, Popen): backend = Backend.objects.create(name="foo") manager = ListenerManager() Popen.return_value.poll.return_value = None manager.start(backend) manager.stop(backend.id) Popen.return_value.poll.assert_called_once() Popen.return_value.terminate.assert_called_once() Popen.return_value.wait.assert_called_once()
def test_keep_listeners_running_restart_dead_process(self, Popen): manager = ListenerManager() backend = Backend.objects.create(name="foo") # start existing backends manager.keep_listeners_running() self.assertEqual(1, len(manager.__processes__)) Popen.assert_called() # "kill" the process Popen.return_value.poll.return_value = -15 # SIGKILL manager.stop = MagicMock() manager.start = MagicMock() # Give it another go manager.keep_listeners_running() manager.stop.assert_called_with(backend.id) manager.start.assert_called_with(backend)
def test_keep_listeners_running_changed(self, Popen): manager = ListenerManager() backend = Backend.objects.create(name="foo") # start existing backends manager.keep_listeners_running() manager.stop = MagicMock() manager.start = MagicMock() # backend is changed backend.name = 'bar' backend.save() manager.keep_listeners_running() manager.stop.assert_called_with(backend.id) manager.start.assert_called_with(backend)
def test_keep_listeners_running_added(self, Popen): manager = ListenerManager() backend1 = Backend.objects.create(name="foo") manager.start = MagicMock() manager.stop = MagicMock() # start existing backends manager.keep_listeners_running() manager.start.assert_called_with(backend1) # new backend, start it too backend2 = Backend.objects.create(name="bar") manager.keep_listeners_running() manager.start.assert_called_with(backend2) manager.stop.assert_not_called()
def test_keep_listeners_running_removed(self, Popen): manager = ListenerManager() backend = Backend.objects.create(name="foo") manager.stop = MagicMock() # start existing backends manager.keep_listeners_running() # backend is removed bid = backend.id backend.delete() manager.keep_listeners_running() manager.stop.assert_called_with(bid)
def test_handle(self, ListenerManager): command = Command() command.handle() ListenerManager.assert_called_once() ListenerManager.return_value.run.assert_called_once()
def test_handle(self, ListenerManager): command = Command() command.handle() ListenerManager.assert_called_once() ListenerManager.return_value.run.assert_called_once()