示例#1
0
    def test_notify_on_stable_interval(self):
        """ Make sure that an UpdateNotifyer, with a StableUpdater, for the
        configured interval is constructed when the configuration data indicates
        so. """

        mock_file = self.mox.CreateMockAnything()
        mock_timer = self.mox.CreateMockAnything()
        mock_file.closed = False
        mock_file.name = "foobar"

        action, model, interval = ("notify", "stable", "43200")

        self.mox.StubOutWithMock(SafeConfigParser, "get")
        self.mox.StubOutWithMock(StableUpdater, "__init__")
        self.mox.StubOutWithMock(threading, "Timer")

        config = ConfigurationParser()
        config.parse(mock_file)
        config.get("updates", "action").AndReturn(action)
        config.get("updates", "model").AndReturn(model)
        config.get("updates", "interval").AndReturn(interval)

        StableUpdater.__init__(REPO, construct_url_for_version_file())

        threading.Timer(int(interval), mox.IgnoreArg()).AndReturn(mock_timer)
        mock_timer.start()

        self.mox.ReplayAll()

        update_handler = get_update_handler()
        update_handler.start()

        self.assertTrue(isinstance(update_handler, UpdateNotifyer))
示例#2
0
    def test_notify_on_stable_no_interval(self):
        """ Make sure that the default interval is used for the StableUpdater,
        if no default interval is given in the configuration. """

        mock_file = self.mox.CreateMockAnything()
        mock_timer = self.mox.CreateMockAnything()
        mock_file.closed = False
        mock_file.name = "foobar"

        action, model = ("notify", "stable")

        self.mox.StubOutWithMock(SafeConfigParser, "get")
        self.mox.StubOutWithMock(StableUpdater, "__init__")
        self.mox.StubOutWithMock(threading, "Timer")

        config = ConfigurationParser()
        config.parse(mock_file)
        config.get("updates", "action").AndReturn(action)
        config.get("updates", "model").AndReturn(model)
        config.get("updates", "interval").AndRaise(NoOptionError("updates",
                                                                 "interval"))

        StableUpdater.__init__(REPO, construct_url_for_version_file())

        threading.Timer(DEFAULT_INTERVAL,
                        mox.IgnoreArg()).AndReturn(mock_timer)
        mock_timer.start()

        self.mox.ReplayAll()

        update_handler = get_update_handler()
        update_handler.start()

        self.assertTrue(isinstance(update_handler, UpdateNotifyer))
示例#3
0
    def test_notify_on_stable_malformed_interval(self):
        """ A malformed interval in the configuration (i.e. non-integer) should
        result in the default interval being used. """

        mock_file = self.mox.CreateMockAnything()
        mock_timer = self.mox.CreateMockAnything()
        mock_file.closed = False
        mock_file.name = "foobar"

        action, model, interval = ("notify", "stable", "FOO")

        self.mox.StubOutWithMock(SafeConfigParser, "get")
        self.mox.StubOutWithMock(StableUpdater, "__init__")
        self.mox.StubOutWithMock(threading, "Timer")

        config = ConfigurationParser()
        config.parse(mock_file)
        config.get("updates", "action").AndReturn(action)
        config.get("updates", "model").AndReturn(model)
        config.get("updates", "interval").AndReturn(interval)

        StableUpdater.__init__(REPO, construct_url_for_version_file())

        threading.Timer(DEFAULT_INTERVAL, mox.IgnoreArg()).AndReturn(mock_timer)
        mock_timer.start()

        self.mox.ReplayAll()

        update_handler = get_update_handler()
        update_handler.start()

        self.assertTrue(isinstance(update_handler, UpdateNotifyer))