Exemplo n.º 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))
Exemplo n.º 2
0
    def test_get_credentials_missing_section(self):
        """ Test reading the credentials from a configuration file where the
        credentials section is missing (uninitialized). """

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

        username, password = ("*****@*****.**", "password")

        self.mox.StubOutWithMock(SafeConfigParser, "get")
        self.mox.StubOutWithMock(SafeConfigParser, "add_section")
        self.mox.StubOutWithMock(SafeConfigParser, "set")
        self.mox.StubOutWithMock(__builtin__, "raw_input")

        config = ConfigurationParser()
        config.parse(mock_file)
        error = NoSectionError("credentials")
        config.get("credentials", "username").AndRaise(error)

        config.add_section("credentials")

        raw_input(mox.IgnoreArg()).AndReturn(username)
        raw_input(mox.IgnoreArg()).AndReturn(password)

        config.set("credentials", "username", username)
        config.set("credentials", "password", password)

        self.mox.ReplayAll()

        self.assertEquals((username, password), credentials.get_credentials())
Exemplo n.º 3
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))
Exemplo n.º 4
0
    def test_notify_on_bleeding_edge_interval(self):
        """ Make sure that a BleedingEdgeUpdater is constructed if the
        configuration details it. """

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

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

        self.mox.StubOutWithMock(SafeConfigParser, "get")
        self.mox.StubOutWithMock(BleedingEdgeUpdater, "__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)

        BleedingEdgeUpdater.__init__(REPO, construct_url_for_head_commit())

        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))
Exemplo n.º 5
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))
Exemplo n.º 6
0
    def test_parsing_existing_configuration_file(self):
        """ Test the parsing of an 'existing' file """
        existing_config_file = self.mox.CreateMockAnything()
        existing_config_file.closed = False
        existing_config_file.name = "foobar"

        self.mox.StubOutWithMock(SafeConfigParser, "read")

        SafeConfigParser.read(existing_config_file.name)

        self.mox.ReplayAll()

        config = ConfigurationParser()
        try:
            config.parse(existing_config_file)
        except FileNotFoundException:
            self.fail()
Exemplo n.º 7
0
    def test_update_section_no_action(self):
        """ If there is no configured action, no update handler should be
        constructed. """

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

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

        config = ConfigurationParser()
        config.parse(mock_file)
        config.get("updates", "action").AndRaise(NoOptionError("updates",
                                                               "action"))
        self.mox.ReplayAll()

        self.assertEqual(None, get_update_handler())
Exemplo n.º 8
0
    def test_get_credentials(self):
        """ Ensure proper behavior when the configuration file contains the
        username-password pair. """

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

        username, password = ("*****@*****.**", "password")

        self.mox.StubOutWithMock(SafeConfigParser, "get")

        config = ConfigurationParser()
        config.parse(mock_file)
        config.get("credentials", "username").AndReturn(username)
        config.get("credentials", "password").AndReturn(password)

        self.mox.ReplayAll()

        self.assertEquals((username, password), credentials.get_credentials())
Exemplo n.º 9
0
    def test_update_section_unknown_model(self):
        """ If the configured model string does not match a known model, an
        UnknownModel exception should be raised. """

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

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

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

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

        self.assertRaises(UnknownModel, get_update_handler)
Exemplo n.º 10
0
    def test_setting_option(self):
        """ Test setting an option - this should be a simple delegate to
        SafeConfigParser.set, with a write upon successful set. """

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

        self.mox.StubOutWithMock(SafeConfigParser, "read")
        self.mox.StubOutWithMock(SafeConfigParser, "set")
        self.mox.StubOutWithMock(SafeConfigParser, "write")

        SafeConfigParser.read(mock_file.name)
        SafeConfigParser.set("credentials", "username", "foo")
        mock_file.truncate(0)
        mock_file.flush()
        SafeConfigParser.write(mock_file)

        self.mox.ReplayAll()
        
        config = ConfigurationParser()
        config.parse(mock_file)
        config.set("credentials", "username", "foo")
Exemplo n.º 11
0
    def test_removing_section(self):
        """ Test removin a section - this should be a simple delegate to
        SafeConfigParser.remove_section, with a write upon successful removal. """

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

        self.mox.StubOutWithMock(SafeConfigParser, "read")
        self.mox.StubOutWithMock(SafeConfigParser, "remove_section")
        self.mox.StubOutWithMock(SafeConfigParser, "write")

        SafeConfigParser.read(mock_file.name)
        SafeConfigParser.remove_section("credentials")
        mock_file.truncate(0)
        mock_file.flush()
        SafeConfigParser.write(mock_file)

        self.mox.ReplayAll()
        
        config = ConfigurationParser()
        config.parse(mock_file)
        config.remove_section("credentials")