Exemple #1
0
    def test_should_return_metrics_file(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_loader.get_metrics_directory.return_value = '/tmp/metrics'

        actual_metrics_file = ReceiverConfigLoader.get_metrics_file(
            mock_loader)

        self.assertEqual('/tmp/metrics/yrc.metrics', actual_metrics_file)
Exemple #2
0
    def test_should_return_targets(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.get_option_as_set.return_value = set(['abc', 'def'])
        mock_loader._parser = mock_parser

        actual_targets = ReceiverConfigLoader.get_targets(mock_loader)

        self.assertEqual(set(['abc', 'def']), actual_targets)
        self.assertEqual(
            call(SECTION_RECEIVER, 'targets', DEFAULT_TARGETS), mock_parser.get_option_as_set.call_args)
Exemple #3
0
    def test_should_return_broadcaster_port_option(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.get_option_as_int.return_value = 42
        mock_loader._parser = mock_parser

        actual_app_status_port = ReceiverConfigLoader.get_app_status_port(
            mock_loader)

        self.assertEqual(42, actual_app_status_port)
        self.assertEqual(
            call(SECTION_RECEIVER, 'app_status_port', DEFAULT_APP_STATUS_PORT), mock_parser.get_option_as_int.call_args)
Exemple #4
0
    def test_should_return_broadcaster_port_option(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.get_option_as_int.return_value = 8081
        mock_loader._parser = mock_parser

        actual_broadcaster_port = ReceiverConfigLoader.get_broadcaster_port(
            mock_loader)

        self.assertEqual(8081, actual_broadcaster_port)
        self.assertEqual(
            call(SECTION_BROADCASTER, 'port', DEFAULT_BROADCASTER_PORT), mock_parser.get_option_as_int.call_args)
Exemple #5
0
    def test_should_return_broadcaster_host_option(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.get_option.return_value = 'broadcaster.host'
        mock_loader._parser = mock_parser

        actual_broadcaster_host = ReceiverConfigLoader.get_broadcaster_host(
            mock_loader)

        self.assertEqual('broadcaster.host', actual_broadcaster_host)
        self.assertEqual(
            call(SECTION_BROADCASTER, 'host', DEFAULT_BROADCASTER_HOST), mock_parser.get_option.call_args)
Exemple #6
0
    def test_should_return_metrics_directory(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.get_option.return_value = '/tmp/metrics'
        mock_loader._parser = mock_parser

        actual_metrics_directory = ReceiverConfigLoader.get_metrics_directory(
            mock_loader)

        self.assertEqual('/tmp/metrics', actual_metrics_directory)
        self.assertEqual(
            call(SECTION_RECEIVER, 'metrics_directory', None), mock_parser.get_option.call_args)
Exemple #7
0
    def test_should_delegate_read_configuration_file(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.read_configuration_file.return_value = {'spam': 'eggs'}
        mock_loader._parser = mock_parser

        actual_configuration = ReceiverConfigLoader.read_configuration_file(
            mock_loader, 'filename.cfg')

        self.assertEqual({'spam': 'eggs'}, actual_configuration)
        self.assertEqual(
            call('filename.cfg'), mock_parser.read_configuration_file.call_args)
Exemple #8
0
    def test_should_return_targets_directory(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.get_option.return_value = '/directory/with/targets'
        mock_loader._parser = mock_parser

        actual_targets_directory = ReceiverConfigLoader.get_targets_directory(
            mock_loader)

        self.assertEqual('/directory/with/targets', actual_targets_directory)
        self.assertEqual(
            call(SECTION_RECEIVER, 'targets_directory', DEFAULT_TARGETS_DIRECTORY), mock_parser.get_option.call_args)
Exemple #9
0
    def test_should_return_script_to_execute(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.get_option.return_value = '/script/to/execute'
        mock_loader._parser = mock_parser

        actual_script_to_execute = ReceiverConfigLoader.get_script_to_execute(
            mock_loader)

        self.assertEqual('/script/to/execute', actual_script_to_execute)
        self.assertEqual(
            call(SECTION_RECEIVER, 'script_to_execute', DEFAULT_SCRIPT_TO_EXECUTE), mock_parser.get_option.call_args)
Exemple #10
0
    def test_should_return_python_command(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.get_option.return_value = '/spam/eggs/python'
        mock_loader._parser = mock_parser

        actual_python_command = ReceiverConfigLoader.get_python_command(
            mock_loader)

        self.assertEqual('/spam/eggs/python', actual_python_command)
        self.assertEqual(
            call(SECTION_RECEIVER, 'python_command', DEFAULT_PYTHON_COMMAND), mock_parser.get_option.call_args)
Exemple #11
0
    def test_should_return_log_filename(self):
        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.get_option.return_value = 'filename.log'
        mock_loader._parser = mock_parser

        actual_log_filename = ReceiverConfigLoader.get_log_filename(
            mock_loader)

        self.assertEqual('filename.log', actual_log_filename)
        self.assertEqual(
            call(SECTION_RECEIVER, 'log_filename', DEFAULT_LOG_FILENAME), mock_parser.get_option.call_args)
Exemple #12
0
    def test_should_return_hostname_from_receiver_section(self, mock_socket):
        mock_socket.gethostname.return_value = 'localhost'

        mock_loader = Mock(ReceiverConfigLoader)
        mock_parser = Mock(YadtConfigParser)
        mock_parser.get_option.return_value = 'actual.hostname'
        mock_loader._parser = mock_parser

        actual_hostname = ReceiverConfigLoader.get_hostname(mock_loader)

        self.assertEqual('actual.hostname', actual_hostname)
        self.assertEqual(call(), mock_socket.gethostname)
        self.assertEqual(
            call(SECTION_RECEIVER, 'hostname', 'localhost'), mock_parser.get_option.call_args)
Exemple #13
0
    def test_should_create_instance_of_SafeConfigParser(self):
        parser = ReceiverConfigLoader()

        name_of_type = parser._parser.__class__.__name__
        self.assertEqual('YadtConfigParser', name_of_type)