How to use defcon - 10 common examples

To help you get started, we’ve selected a few defcon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github criteo / defcon / defcon / status / tests.py View on Github external
def test_plugin_instance(self):
        """See if we can create plugin instances."""
        p = models.Plugin.objects.create()
        pi = models.PluginInstance.objects.create(plugin=p)
        self.assertEqual(pi.component, None)
github criteo / defcon / defcon / status / tests.py View on Github external
def test_run_add_status(self):
        out = StringIO()
        self.addCleanup(out.close)
        status = base.Status('Test status', 5, 'http://foo/#5')

        with self.components_with_plugin(status):
            management.call_command('runplugins', stdout=out)
            self.assertIn("Running test Production:Fake plugin", out.getvalue())
            self.assertIn("Created Fake plugin:Test status", out.getvalue())

            status_model = models.Status.objects.all()[0]

            self.assertEqual(status_model.title, status['title'])
            self.assertEqual(status_model.link, status['link'])
            self.assertEqual(status_model.description, status['description'])
            self.assertEqual(status_model.defcon, status['defcon'])
            self.assertFalse(status_model.override)
github criteo / defcon / defcon / status / tests.py View on Github external
def test_update_plugin(self):
        out = StringIO()
        self.addCleanup(out.close)
        management.call_command('loadplugins', stdout=out)

        with mock.patch.object(FakePlugin, "name", "Updated Fake"):
            management.call_command('loadplugins', stdout=out)

            plugin = FakePlugin()
            self.assertIn("Updated %s" % plugin.name, out.getvalue())

            plugin_model = models.Plugin.objects.get(id=plugin.short_name)
            self.assertEqual(plugin_model.name, plugin.name)
github criteo / defcon / defcon / plugins / test_static.py View on Github external
def test_simple(self):
        """Test __init__."""
        p = static.StaticPlugin()
        self.assertEquals(p.short_name, 'static')

        s = base.Status('test', 2, 'test')
        p = static.StaticPlugin({'statuses': [s]})
        self.assertEquals(p.statuses(), {s['id']: s})
github criteo / defcon / defcon / status / tests.py View on Github external
def test_run_update_status(self):
        out = StringIO()
        self.addCleanup(out.close)
        status = base.Status('Test status', 5, 'http://foo/#5')

        with self.components_with_plugin(status):
            management.call_command('runplugins', stdout=out)

            status.description = 'status description'

            management.call_command('runplugins', stdout=out)
            self.assertIn("Running test Production:Fake plugin", out.getvalue())
            self.assertIn("Updated Fake plugin:Test status", out.getvalue())

            status_model = models.Status.objects.all()[0]
            self.assertEqual(status_model.description, status['description'])
github criteo / defcon / defcon / plugins / test_base.py View on Github external
def test_basic(self):
        """Test that we can create statuses."""
        s = base.Status('Test status', 5, 'http://github.com/criteo/defcon',
                        description='This is a test')
        expected = {
            'defcon': 5, 'title': 'Test status',
            'description': 'This is a test',
            'link': 'http://github.com/criteo/defcon',
            'id': uuid.UUID('235c445a-cd6f-5f46-91af-bada596275a6'),
            'time_start': None,
            'time_end': None,
        }

        self.assertEqual(dict(s), expected)
github criteo / defcon / defcon / plugins / test_base.py View on Github external
def test_plugin(self):
        """Test that we can build plugins."""
        class _FakePlugin(base.Plugin):
            """Fake class for testing."""

            def __init__(self, settings):
                """Fake __init__."""
                super(_FakePlugin, self).__init__(settings)

            @property
            def short_name(self):
                return 'fake'

            @property
            def name(self):
                return 'fake'

            def statuses(self):
                """Fake statuses."""
github criteo / defcon / defcon / status / tests.py View on Github external
def test_remove_plugin(self):
        out = StringIO()
        self.addCleanup(out.close)
        management.call_command('loadplugins', stdout=out)

        with self.settings(DEFCON_PLUGINS=[]):
            management.call_command('loadplugins', stdout=out)
            self.assertIn('Removed', out.getvalue())
            self.assertEqual(0, len(models.Plugin.objects.all()))
github criteo / defcon / defcon / status / tests.py View on Github external
def test_add_plugin(self):
        out = StringIO()
        self.addCleanup(out.close)
        management.call_command('loadplugins', stdout=out)

        plugin = FakePlugin()
        self.assertIn("Created %s" % plugin.name, out.getvalue())

        plugin_model = models.Plugin.objects.get(id=plugin.short_name)
        self.assertEqual(plugin_model.id, plugin.short_name)
        self.assertEqual(plugin_model.name, plugin.name)
        self.assertEqual(plugin_model.description, plugin.description)
        self.assertEqual(plugin_model.link, plugin.link)
        self.assertEqual(plugin_model.py_module, DEFCON_PLUGINS[0])
github criteo / defcon / defcon / status / tests.py View on Github external
def test_add_component(self):
        out = StringIO()
        self.addCleanup(out.close)
        components = copy.deepcopy(DEFCON_COMPONENTS)
        component = components['production']

        with self.settings(DEFCON_COMPONENTS=components):
            management.call_command("loadcomponents", stdout=out)
            self.assertIn("Created %s" % component["name"], out.getvalue())

            component_model = models.Component.objects.get(id="production")
            self.assertEqual(component_model.name, component["name"])
            self.assertEqual(component_model.description,
                             component["description"])
            self.assertEqual(component_model.link, component["link"])
            self.assertEqual(component_model.contact, component["contact"])