Ejemplo n.º 1
0
    def test_can_specify_all_options(self, patched_config):
        patched_config.get_options_for_section.side_effect = (
            # Specifies all options by default.
            _mock_get_options_for_section())

        msg = ForwardMsg()
        new_report_msg = msg.new_report
        report_session._populate_theme_msg(new_report_msg.custom_theme)

        self.assertEqual(new_report_msg.HasField("custom_theme"), True)
        self.assertEqual(new_report_msg.custom_theme.primary_color, "coral")
        self.assertEqual(new_report_msg.custom_theme.background_color, "white")
Ejemplo n.º 2
0
    def test_logs_warning_if_base_invalid(self, patched_config, patched_logger):
        patched_config.get_options_for_section.side_effect = (
            _mock_get_options_for_section({"base": "blah"})
        )

        msg = ForwardMsg()
        new_report_msg = msg.new_report
        report_session._populate_theme_msg(new_report_msg.custom_theme)

        patched_logger.warning.assert_called_once_with(
            '"blah" is an invalid value for theme.base.'
            " Allowed values include ['light', 'dark']. Setting theme.base to \"light\"."
        )
Ejemplo n.º 3
0
    def test_logs_warning_if_font_invalid(self, patched_config, patched_logger):
        patched_config.get_options_for_section.side_effect = (
            _mock_get_options_for_section({"font": "comic sans"})
        )

        msg = ForwardMsg()
        new_report_msg = msg.new_report
        report_session._populate_theme_msg(new_report_msg.custom_theme)

        patched_logger.warning.assert_called_once_with(
            '"comic sans" is an invalid value for theme.font.'
            " Allowed values include ['sans serif', 'serif', 'monospace']. Setting theme.font to \"sans serif\"."
        )
Ejemplo n.º 4
0
    def test_no_custom_theme_prop_if_no_theme(self, patched_config):
        patched_config.get_options_for_section.side_effect = (
            _mock_get_options_for_section({
                "primaryColor": None,
                "backgroundColor": None,
                "secondaryBackgroundColor": None,
                "textColor": None,
            }))

        msg = ForwardMsg()
        new_report_msg = msg.new_report
        report_session._populate_theme_msg(new_report_msg.custom_theme)

        self.assertEqual(new_report_msg.HasField("custom_theme"), False)
Ejemplo n.º 5
0
    def test_can_specify_some_options(self, patched_config):
        patched_config.get_options_for_section.side_effect = _mock_get_options_for_section(
            {
                # Leave base, primaryColor, and font defined.
                "backgroundColor": None,
                "secondaryBackgroundColor": None,
                "textColor": None,
            }
        )

        msg = ForwardMsg()
        new_report_msg = msg.new_report
        report_session._populate_theme_msg(new_report_msg.custom_theme)

        self.assertEqual(new_report_msg.HasField("custom_theme"), True)
        self.assertEqual(new_report_msg.custom_theme.primary_color, "coral")
        # In proto3, primitive fields are technically always required and are
        # set to the type's zero value when undefined.
        self.assertEqual(new_report_msg.custom_theme.background_color, "")