Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactoring : extracted method for easier mocking

  • Loading branch information...
commit 625b82c404b04558e86eab80a84c8b95773d3ad0 1 parent 680dc6d
@mriehl mriehl authored
View
5 src/main/python/yadtreceiver/__init__.py
@@ -219,11 +219,14 @@ def set_configuration(self, configuration):
self.configuration = configuration
+ def initialize_twisted_logging(self):
+ log.startLogging(LogFile.fromFullPath(self.configuration['log_filename']))
+
def startService(self):
"""
Initializes logging and establishes connection to broadcaster.
"""
- log.startLogging(LogFile.fromFullPath(self.configuration['log_filename']))
+ self.initialize_twisted_logging()
log.msg('yadtreceiver version %s' % __version__)
self._client_watchdog()
self._refresh_connection(first_call=True)
View
30 src/unittest/python/yadtreceiver_tests.py
@@ -31,6 +31,20 @@ class YadtReceiverTests (unittest.TestCase):
def test_if_this_test_fails_maybe_you_have_yadtreceiver_installed_locally (self):
self.assertEqual('${version}', __version__)
+ @patch('yadtreceiver.LogFile')
+ @patch('yadtreceiver.log')
+ def test_should_call_start_logging_when_initializing_twisted_logging(self, mock_log, mock_log_file_class):
+ receiver = Receiver()
+ receiver.set_configuration({'log_filename' : 'log/file.log',
+ 'targets' : set(['devabc123']),
+ 'broadcaster_host': 'broadcaster_host',
+ 'broadcaster_port': 1234})
+ mock_log_file = Mock(LogFile)
+ mock_log_file_class.fromFullPath.return_value = mock_log_file
+
+ receiver.initialize_twisted_logging()
+
+ self.assertEquals(call(mock_log_file), mock_log.startLogging.call_args)
def test_should_set_configuration (self):
configuration = 'configuration'
@@ -120,20 +134,12 @@ def test_should_initialize_watchdog_and_start_connection_when_service_starts (se
self.assertEquals(call(first_call=True), mock_receiver._refresh_connection.call_args)
- @patch('yadtreceiver.LogFile')
- @patch('yadtreceiver.log')
- def test_should_initialize_logging_when_service_starts (self, mock_log, mock_log_file_class):
- receiver = Receiver()
- receiver.set_configuration({'log_filename' : 'log/file.log',
- 'targets' : set(['devabc123']),
- 'broadcaster_host': 'broadcaster_host',
- 'broadcaster_port': 1234})
- mock_log_file = Mock(LogFile)
- mock_log_file_class.fromFullPath.return_value = mock_log_file
+ def test_should_initialize_logging_when_service_starts (self):
+ mock_receiver = Mock(Receiver)
- receiver.startService()
+ Receiver.startService(mock_receiver)
- self.assertEquals(call(mock_log_file), mock_log.startLogging.call_args)
+ self.assertEquals(call(), mock_receiver.initialize_twisted_logging.call_args)
def test_should_subscribe_to_target_from_configuration_when_connected (self):
Please sign in to comment.
Something went wrong with that request. Please try again.