예제 #1
0
    def test_plugin_info_configMtime(self):
        panoptes_plugin_info = PanoptesPluginInfo("plugin_name", "path/to/plugin")
        panoptes_plugin_info.config_filename = self.my_dir
        self.assertEqual(panoptes_plugin_info.configMtime, int(os.path.getmtime(self.my_dir)))

        panoptes_plugin_info.config_filename = "/non/existent/file"
        with self.assertRaises(PanoptesPluginConfigurationError):
            panoptes_plugin_info.configMtime
예제 #2
0
    def test_plugin_info_execute_now(self):
        with patch("yahoo_panoptes.framework.plugins.panoptes_base_plugin.time.time", mock_time):
            panoptes_plugin_info = PanoptesPluginInfo("plugin_name", "path/to/plugin")
            panoptes_plugin_info.panoptes_context = self._panoptes_context
            panoptes_plugin_info.kv_store_class = PanoptesTestKeyValueStore
            panoptes_plugin_info.config_filename = "tests/plugins/polling/test/plugin_polling_test.panoptes-plugin"
            panoptes_plugin_info.details.read(panoptes_plugin_info.config_filename)

            mock_moduleMtime = _TIMESTAMP - 1
            mock_configMtime = _TIMESTAMP - 2
            with patch('yahoo_panoptes.framework.plugins.panoptes_base_plugin.PanoptesPluginInfo.configMtime',
                       mock_configMtime):
                with patch('yahoo_panoptes.framework.plugins.panoptes_base_plugin.PanoptesPluginInfo.moduleMtime',
                           mock_moduleMtime):
                    # Ensure first if-block in execute_now returns False
                    panoptes_plugin_info.last_results = int(_TIMESTAMP)
                    panoptes_plugin_info.last_executed = int(_TIMESTAMP)
                    self.assertFalse(panoptes_plugin_info.execute_now)

                    # Ensure second if-block in execute_now returns False
                    panoptes_plugin_info._last_results = None
                    panoptes_plugin_info._last_executed = None

                    panoptes_plugin_info.last_results = int(_TIMESTAMP)
                    panoptes_plugin_info.last_executed = (int(_TIMESTAMP) - panoptes_plugin_info.execute_frequency)
                    self.assertFalse(panoptes_plugin_info.execute_now)

                    # Ensure returns True
                    panoptes_plugin_info._last_results = None
                    panoptes_plugin_info._last_executed = None

                    panoptes_plugin_info.last_results = (int(_TIMESTAMP) - panoptes_plugin_info.execute_frequency)
                    self.assertTrue(panoptes_plugin_info.execute_now)
예제 #3
0
    def test_plugin_info_properties(self):
        panoptes_plugin_info = PanoptesPluginInfo("Test Polling Plugin",
                                                  "tests/plugins/polling/test")

        with self.assertRaises(PanoptesPluginConfigurationError):
            panoptes_plugin_info.panoptes_context

        panoptes_plugin_info.panoptes_context = self._panoptes_context
        panoptes_plugin_info.kv_store_class = PanoptesTestKeyValueStore
        panoptes_plugin_info.last_executed = _LAST_EXECUTED_TEST_VALUE
        panoptes_plugin_info.config_filename = "tests/plugins/polling/test/plugin_polling_test.panoptes-plugin"

        #  Test results_cache_age, execute_frequency, last_executed return 0 on exception.
        self.assertEqual(panoptes_plugin_info.results_cache_age, 0)
        self.assertEqual(panoptes_plugin_info.execute_frequency, 0)

        panoptes_plugin_info.details.read(panoptes_plugin_info.config_filename)

        self.assertEqual(panoptes_plugin_info.results_cache_age, 100)
        self.assertEqual(panoptes_plugin_info.execute_frequency, 60)

        #  Test last_executed setter cannot be reset after being read
        self.assertEqual(panoptes_plugin_info.last_executed, _LAST_EXECUTED_TEST_VALUE)
        panoptes_plugin_info.last_executed = 1
        self.assertNotEqual(panoptes_plugin_info.last_executed, 1)
        self.assertEqual(panoptes_plugin_info.last_executed, _LAST_EXECUTED_TEST_VALUE)

        with patch("yahoo_panoptes.framework.plugins.panoptes_base_plugin.time.time", mock_time):
            self.assertEqual(panoptes_plugin_info.last_executed_age, int(_TIMESTAMP - _LAST_EXECUTED_TEST_VALUE))