class TestDatasourceTestingRmQueue(unittest.TestCase): def setUp(self): self.datasource = RmQueue() fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)), \ 'fixtures', 'rm_queue.html') self.datasource.update(open(fixture)) def testURL(self): """ Check we have a sane URL. """ self.assert_(len(self.datasource.URL) > 5) self.assert_(self.datasource.URL.startswith('http')) def testInterval(self): """ Check we have a sane update interval. """ self.assert_(self.datasource.INTERVAL > 60) def testSize(self): self.assertEqual(self.datasource.get_size(), 10) def testTop(self): self.assert_(self.datasource.is_rm('libgocr')) def testBottom(self): self.assert_(self.datasource.is_rm('sablevm-classlib'))
def setUp(self): fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures", "rm_queue.html") with io.open(fixture, encoding="utf-8") as f: data = f.read() self.mocker = requests_mock.Mocker() self.mocker.start() self.mocker.register_uri("GET", RmQueue.URL, text=data) session = requests.Session() self.datasource = RmQueue(session)
def _topic_callback(self): sections = { self.testing_rc_bugs.get_number_bugs: 'RC bug count', self.stable_rc_bugs.get_number_bugs: 'Stable RC bug count', self.new_queue.get_size: 'NEW queue', RmQueue().get_size: 'RM queue', } with self.topic_lock: values = {} for callback, prefix in sections.iteritems(): values[callback] = callback() for channel in self.irc.state.channels: new_topic = topic = self.irc.state.getTopic(channel) for callback, prefix in sections.iteritems(): if values[callback]: new_topic = rewrite_topic(new_topic, prefix, values[callback]) if topic != new_topic: log.info("Queueing change of topic in #%s to '%s'" % (channel, new_topic)) self.queued_topics[channel] = new_topic event_name = '%s_topic' % channel try: schedule.removeEvent(event_name) except KeyError: pass schedule.addEvent(lambda channel=channel: self._update_topic(channel), time.time() + 60, event_name)
def __init__(self, irc): super().__init__(irc) self.irc = irc self.topic_lock = threading.Lock() self.dbus_service = BTSDBusService(self._email_callback) self.mainloop = None mainloop = GObject.MainLoop() if not mainloop.is_running(): mainloop_thread = threading.Thread(target=mainloop.run) mainloop_thread.start() self.mainloop = mainloop self.dbus_bus = SystemBus() self.dbus_bus.publish(self.dbus_service.interface_name, self.dbus_service) self.dbus_service.start() self.requests_session = requests.Session() self.requests_session.verify = True self.queued_topics = {} self.last_n_messages = [] self.stable_rc_bugs = StableRCBugs(self.requests_session) self.testing_rc_bugs = TestingRCBugs(self.requests_session) self.new_queue = NewQueue(self.requests_session) self.dinstall = Dinstall(self.requests_session) self.rm_queue = RmQueue(self.requests_session) self.apt_archive = AptArchive( self.registryValue('apt_configuration_directory'), self.registryValue('apt_cache_directory')) self.data_sources = (self.stable_rc_bugs, self.testing_rc_bugs, self.new_queue, self.dinstall, self.rm_queue, self.apt_archive) # Schedule datasource updates def wrapper(source): def implementation(): try: source.update() except Exception as e: log.exception('Failed to update {}: {}'.format( source.NAME, e)) self._topic_callback() return implementation for source in self.data_sources: schedule.addPeriodicEvent(wrapper(source), source.INTERVAL, source.NAME, now=False) schedule.addEvent(wrapper(source), time.time() + 1)
def setUp(self): fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'rm_queue.html') with io.open(fixture, encoding='utf-8') as f: data = f.read() self.mocker = requests_mock.Mocker() self.mocker.start() self.mocker.register_uri('GET', RmQueue.URL, text=data) session = requests.Session() self.datasource = RmQueue(session)
class TestDatasourceTestingRmQueue(unittest.TestCase): def setUp(self): fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures", "rm_queue.html") with io.open(fixture, encoding="utf-8") as f: data = f.read() self.mocker = requests_mock.Mocker() self.mocker.start() self.mocker.register_uri("GET", RmQueue.URL, text=data) session = requests.Session() self.datasource = RmQueue(session) def tearDown(self): self.mocker.stop() def testURL(self): """ Check we have a sane URL. """ self.assertTrue(len(self.datasource.URL) > 5) self.assertTrue(self.datasource.URL.startswith("http")) def testInterval(self): """ Check we have a sane update interval. """ self.assertTrue(self.datasource.INTERVAL > 60) def testSize(self): self.datasource.update() self.assertEqual(self.datasource.get_size(), 5) def testTop(self): self.datasource.update() self.assertTrue(self.datasource.is_rm("mtasc")) def testBottom(self): self.datasource.update() self.assertTrue(self.datasource.is_rm("rnahybrid"))
class TestDatasourceTestingRmQueue(unittest.TestCase): def setUp(self): fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'rm_queue.html') with io.open(fixture, encoding='utf-8') as f: data = f.read() self.mocker = requests_mock.Mocker() self.mocker.start() self.mocker.register_uri('GET', RmQueue.URL, text=data) session = requests.Session() self.datasource = RmQueue(session) def tearDown(self): self.mocker.stop() def testURL(self): """ Check we have a sane URL. """ self.assertTrue(len(self.datasource.URL) > 5) self.assertTrue(self.datasource.URL.startswith('http')) def testInterval(self): """ Check we have a sane update interval. """ self.assertTrue(self.datasource.INTERVAL > 60) def testSize(self): self.datasource.update() self.assertEqual(self.datasource.get_size(), 5) def testTop(self): self.datasource.update() self.assertTrue(self.datasource.is_rm('mtasc')) def testBottom(self): self.datasource.update() self.assertTrue(self.datasource.is_rm('rnahybrid'))
def setUp(self): self.datasource = RmQueue() fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)), \ 'fixtures', 'rm_queue.html') self.datasource.update(open(fixture))