コード例 #1
0
    def setUp(self):
        fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'fixtures', 'dinstall.status.done')
        with io.open(fixture, encoding='utf-8') as f:
            self.data_not_running = f.read()

        fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'fixtures', 'dinstall.status.running')
        with io.open(fixture, encoding='utf-8') as f:
            self.data_running = f.read()

        self.mocker = requests_mock.Mocker()
        self.mocker.start()

        session = requests.Session()
        self.datasource = Dinstall(session)
コード例 #2
0
    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)
コード例 #3
0
class TestDatasourceDinstall(unittest.TestCase):
    def setUp(self):
        fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'fixtures', 'dinstall.status.done')
        with io.open(fixture, encoding='utf-8') as f:
            self.data_not_running = f.read()

        fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'fixtures', 'dinstall.status.running')
        with io.open(fixture, encoding='utf-8') as f:
            self.data_running = f.read()

        self.mocker = requests_mock.Mocker()
        self.mocker.start()

        session = requests.Session()
        self.datasource = Dinstall(session)

    def tearDown(self):
        self.mocker.stop()

    def testNotRunning(self):
        self.mocker.register_uri('GET',
                                 Dinstall.URL,
                                 text=self.data_not_running)
        self.datasource.update()
        self.assertEqual(self.datasource.get_status(), 'not running')

    def testRunning(self):
        self.mocker.register_uri('GET', Dinstall.URL, text=self.data_running)
        self.datasource.update()
        self.assertEqual(self.datasource.get_status(), 'packages/contents')
コード例 #4
0
class TestDatasourceDinstall(unittest.TestCase):
    def setUp(self):
        fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'fixtures', 'dinstall.status.done')
        with io.open(fixture, encoding='utf-8') as f:
            self.data_not_running = f.read()

        fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'fixtures', 'dinstall.status.running')
        with io.open(fixture, encoding='utf-8') as f:
            self.data_running = f.read()

        self.mocker = requests_mock.Mocker()
        self.mocker.start()

        session = requests.Session()
        self.datasource = Dinstall(session)

    def tearDown(self):
        self.mocker.stop()

    def testNotRunning(self):
        self.mocker.register_uri('GET', Dinstall.URL,
                                 text=self.data_not_running)
        self.datasource.update()
        self.assertEqual(self.datasource.get_status(), 'not running')

    def testRunning(self):
        self.mocker.register_uri('GET', Dinstall.URL, text=self.data_running)
        self.datasource.update()
        self.assertEqual(self.datasource.get_status(), 'packages/contents')
コード例 #5
0
    def setUp(self):
        fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'fixtures', 'dinstall.status.done')
        with io.open(fixture, encoding='utf-8') as f:
            self.data_not_running = f.read()

        fixture = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'fixtures', 'dinstall.status.running')
        with io.open(fixture, encoding='utf-8') as f:
            self.data_running = f.read()

        self.mocker = requests_mock.Mocker()
        self.mocker.start()

        session = requests.Session()
        self.datasource = Dinstall(session)