def setUp(self, config=None): if config is None: config = get_collector_config('WebsiteCollector', {'url': ''}) else: config = get_collector_config('WebsiteCollector', config) self.collector = WebsiteMonitorCollector(config, None) self.patcher = patch('urllib2.urlopen') self.urlopen_mock = self.patcher.start()
class TestWebsiteCollector(CollectorTestCase): def setUp(self, config=None): if config is None: config = get_collector_config('WebsiteCollector', { 'url': '' }) else: config = get_collector_config('WebsiteCollector', config) self.collector = WebsiteMonitorCollector(config, None) self.patcher = patch('urllib2.urlopen') self.urlopen_mock = self.patcher.start() def test_import(self): self.assertTrue(WebsiteMonitorCollector) @patch.object(Collector, 'publish') def test_websitemonitorcollector_with_data(self, publish_mock): self.collector.collect() self.urlopen_mock.return_value = MockResponse(200) metrics = {} self.setDocExample(collector=self.collector.__class__.__name__, metrics=metrics, defaultpath=self.collector.config['path']) self.assertPublishedMany([publish_mock], metrics) @patch.object(Collector, 'publish') def test_websitemonitorcollector(self, publish_mock): self.setUp() self.collector.collect() self.assertPublishedMany(publish_mock, { }) def tearDown(self): self.patcher.stop()
def setUp(self, config=None): if config is None: config = get_collector_config("WebsiteCollector", {"url": ""}) else: config = get_collector_config("WebsiteCollector", config) self.collector = WebsiteMonitorCollector(config, None) self.patcher = patch("urllib2.urlopen") self.urlopen_mock = self.patcher.start()
def setUp(self, config=None): if config is None: config = get_collector_config('WebsiteCollector', { 'url': '' }) else: config = get_collector_config('WebsiteCollector', config) self.collector = WebsiteMonitorCollector(config, None) self.patcher = patch('urllib2.urlopen') self.urlopen_mock = self.patcher.start()