Example #1
0
    def test_friendly_error_message_output_if_data_feed_throws_secret_not_found(
            self):
        secrets = ""
        config_for_notification_that_prints_password = """
        dashboard:
          data-feeds:
            - type: leak-secrets
              options:
                secret-id: twitter-api
        """

        StaticComponentSource.add(SecretLeakerCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            self.save_file("config.yml",
                           config_for_notification_that_prints_password)
            self.save_file("secrets.yml", secrets)
            result = self.call_cli(runner, start,
                                   "--once config.yml --secrets secrets.yml")

        err_msg = "The secret 'twitter-api' is missing from your secrets file according to the data feed config " \
                  "'leak-secrets'"
        self.assertIn(err_msg, result.output)
        self.assertEqual(1, result.exit_code)
    def test_options_passed_to_notification(self):
        config_with_single_notification = """
        dashboard:
          display:
            type: console
            options:
              seconds-per-notifications: 0
          data-feeds:
            - type: text
              options:
                text:
                  - Test Message 1
          notifications:
            - name: Test access to options
              type: test-notification-1
              options:
                test-option: Value from options
        """

        StaticComponentSource.add(DummyNotificationCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            self.save_file("single_config-notification.yml",
                           config_with_single_notification)
            result = self.call_cli(runner, start,
                                   "single_config-notification.yml --once")

        self.assertIn("1 notifications loaded", result.output)
        self.assertIn("Value from options", result.output)
        self.assertEqual(0, result.exit_code)
Example #3
0
    def test_display_is_provided_with_notification(self):
        config_with_single_notification = """
        dashboard:
          display:
            type: test-display
          data-feeds:
            - type: text
              options:
                text: Test Message 1
          notifications:
            - name: Print message
              type: text-from-message
        """

        StaticComponentSource.add(DummyDisplayCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            self.save_file("config.yml", config_with_single_notification)
            result = self.call_cli(runner, start, "config.yml --once")

        self.assertIn(
            "Draw notification (Text (name=Print message, text=Test Message 1))",
            result.output)
        self.assertEqual(0, result.exit_code)
Example #4
0
    def test_secrets_available_to_data_feeds(self):
        secrets = "twitter-api: This is a secret"
        config_for_notification_that_prints_password = """
        dashboard:
          data-feeds:
            - type: leak-secrets
              options:
                secret-id: twitter-api
        """

        StaticComponentSource.add(SecretLeakerCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            self.save_file("config.yml",
                           config_for_notification_that_prints_password)
            self.save_file("secrets.yml", secrets)
            result = self.call_cli(
                runner, view, "datafeeds config.yml --secrets secrets.yml")

        data = json.loads(result.output)
        self.assertEqual(1, len(data["source-data"]),
                         "Source data should contain 1 message")
        self.assertEqual("This is a secret", data["source-data"][0]["text"],
                         "Secret is in message")
        self.assertEqual(0, result.exit_code)
    def test_last_config_takes_precedence(self):
        first_config = """
        dashboard:
          display:
            type: test-display-with-interval
            options:
              seconds-per-notifications: 999
        """

        second_config = """
        dashboard:
          display:
            type: test-display-with-interval
            options:
              seconds-per-notifications: 123
        """

        StaticComponentSource.add(DummyDisplayCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            self.save_file("config.yml", first_config)
            self.http_server.serve_content(second_config)

            result = self.call_cli(runner, start, "config.yml %s --once" % self.http_server.url)

        self.assertIn("Display (interval=123)", result.output)
        self.assertEqual(0, result.exit_code)
    def test_notification_shown_in_list_all(self):
        StaticComponentSource.add(DummyNotificationCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            result = self.call_cli(runner, list, "all")

        self.assertIn("Available notifications:", result.output)
        self.assertIn(" - test-notification-1", result.output)
        self.assertEqual(0, result.exit_code)
    def test_filter_shown_in_list_of_available_filters(self):
        StaticComponentSource.add(DummyFilterCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            result = self.call_cli(runner, list, "filters")

        self.assertIn("Available filters:", result.output)
        self.assertIn(" - test-filter", result.output)
        self.assertEqual(0, result.exit_code)
Example #8
0
    def test_data_feed_shown_in_list_all(self):
        StaticComponentSource.add(DummyFeedCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            result = self.call_cli(runner, list, "all")

        self.assertIn("Available datafeeds:", result.output)
        self.assertIn(" - test-feed", result.output)
        self.assertEqual(0, result.exit_code)
Example #9
0
    def test_display_shown_in_list_of_available_displays(self):
        StaticComponentSource.add(DummyDisplayCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            result = self.call_cli(runner, list, "displays")

        self.assertIn("Available displays:", result.output)
        self.assertIn(" - test-display", result.output)
        self.assertEqual(0, result.exit_code)
Example #10
0
    def test_display_is_loaded_from_config(self):
        config_with_dummy_display = """
        dashboard:
          display:
            type: test-display
        """

        StaticComponentSource.add(DummyDisplayCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            self.save_file("config.yml", config_with_dummy_display)
            result = self.call_cli(runner, start, "config.yml --once")

        self.assertIn("Display loaded: dummy display", result.output)
        self.assertEqual(0, result.exit_code)
Example #11
0
    def test_secrets_available_to_data_feed_config(self):
        secrets = "twitter-api: This secret has been printed to the console"

        StaticComponentSource.add(SecretLeakerCreator)

        runner = CliRunner()
        with runner.isolated_filesystem():
            self.save_file(
                "config.yml",
                self.dashboard_that_outputs_messages_containing_test)
            self.save_file("secrets.yml", secrets)
            result = self.call_cli(runner, start,
                                   "--once config.yml --secrets secrets.yml")

        self.assertIn("This secret has been printed to the console",
                      result.output)
        self.assertEqual(0, result.exit_code)
Example #12
0
    def test_display_that_does_not_support_notification_output_shows_error(
            self):
        StaticComponentSource.add(DummyNotificationCreator)
        config_with_unsupported_output = """
        dashboard:
          display:
            type: console
          notifications:
            - name: Notification with unsupported output
              type: test-notification-with-unsupported-output
        """

        runner = CliRunner()
        with runner.isolated_filesystem():
            self.save_file("config_with_unsupported_output.yml",
                           config_with_unsupported_output)
            result = self.call_cli(
                runner, start, "config_with_unsupported_output.yml --once")

        self.assertIn("does not support the notification output",
                      result.output)
        self.assertEqual(1, result.exit_code)
Example #13
0
def initialise_component_loader():
    configs = ComponentCreatorLoader()
    configs.add_source(ExternalPackageSource())
    configs.add_source(StaticComponentSource())
    return configs