Example #1
0
    def test_no_version_version_defined(self):
        """ Make sure that the updater handles an erroneous (missing) local
        version gracefully. """

        del version.version

        mock_response = self.mox.CreateMockAnything()
        mock_html = self.mox.CreateMockAnything()
        mock_json_dict = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(urllib2, "urlopen")
        self.mox.StubOutWithMock(json, "loads")
        self.mox.StubOutWithMock(base64, "b64decode")

        urllib2.urlopen(self.__remote_url).AndReturn(mock_response)
        mock_response.read().AndReturn(mock_html)

        json.loads(mock_html).AndReturn(mock_json_dict)

        base64.b64decode(mock_json_dict["content"].AndReturn(
            self.__mock_file_with_proper_version)).AndReturn(
                self.__mock_file_with_proper_version)

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(not stable_updater.check())
Example #2
0
    def test_github_does_not_have_new_version(self):
        """ Make sure that no update is indicated if the remote version euqals
        the local one. """

        version.version = self.__mocked_remote_version

        mock_response = self.mox.CreateMockAnything()
        mock_html = self.mox.CreateMockAnything()
        mock_json_dict = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(urllib2, "urlopen")
        self.mox.StubOutWithMock(json, "loads")
        self.mox.StubOutWithMock(base64, "b64decode")

        urllib2.urlopen(self.__remote_url).AndReturn(mock_response)
        mock_response.read().AndReturn(mock_html)

        json.loads(mock_html).AndReturn(mock_json_dict)

        base64.b64decode(mock_json_dict["content"].AndReturn(
            self.__mock_file_with_proper_version)).AndReturn(
                self.__mock_file_with_proper_version)

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(not stable_updater.check())
        self.assertEquals(version.version,
                          stable_updater.remote_version)
Example #3
0
    def test_malformed_base64_string(self):
        """ Make sure malformed base64 is handled gracefully. """

        version.version = "0.0"

        mock_response = self.mox.CreateMockAnything()
        mock_html = self.mox.CreateMockAnything()
        mock_json_dict = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(urllib2, "urlopen")
        self.mox.StubOutWithMock(json, "loads")
        self.mox.StubOutWithMock(base64, "b64decode")

        urllib2.urlopen(self.__remote_url).AndReturn(mock_response)
        mock_response.read().AndReturn(mock_html)

        json.loads(mock_html).AndReturn(mock_json_dict)

        base64.b64decode(mock_json_dict["content"].AndReturn(
            self.__mock_file_with_proper_version)).AndRaise(
                TypeError("Invalid Base64"))

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(not stable_updater.check())
        self.assertEquals(None, stable_updater.remote_version)
Example #4
0
    def test_mutiple_remote_versions(self):
        """ In case the remote version file contains multiple version
        definitions, make sure that no update is indicated. """

        version.version = "0.0"

        mock_response = self.mox.CreateMockAnything()
        mock_html = self.mox.CreateMockAnything()
        mock_json_dict = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(urllib2, "urlopen")
        self.mox.StubOutWithMock(json, "loads")
        self.mox.StubOutWithMock(base64, "b64decode")

        urllib2.urlopen(self.__remote_url).AndReturn(mock_response)
        mock_response.read().AndReturn(mock_html)

        json.loads(mock_html).AndReturn(mock_json_dict)

        base64.b64decode(mock_json_dict["content"].AndReturn(
            self.__mock_file_with_multiple_versions)).AndReturn(
                self.__mock_file_with_multiple_versions)

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(not stable_updater.check())
        self.assertEquals(None, stable_updater.remote_version)
Example #5
0
    def test_timeout_no_update_available(self):
        """ Make sure that nothing happens (i.e. no status updates) when the
        updater indicates that there are no updates available. """

        mock_timer = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(StableUpdater, "__init__")
        self.mox.StubOutWithMock(StableUpdater, "check")
        self.mox.StubOutWithMock(threading, "Timer")
        self.mox.StubOutWithMock(threading.Thread, "start")
        self.mox.StubOutWithMock(Client, "change_status")

        StableUpdater.__init__(self.__repo, self.__remote_url)

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

        StableUpdater.check().AndReturn(False)

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

        self.mox.ReplayAll()

        notifyer = UpdateNotifyer(self.__repo, self.__remote_url)
        notifyer.start()
        notifyer.timeout()
Example #6
0
    def test_version_check_fails_second_time(self):
        """ If a second version check fails, make sure that the update
        availability statuses reflects that. """

        version.version = "0.0"

        mock_response = self.mox.CreateMockAnything()
        mock_html = self.mox.CreateMockAnything()
        mock_json_dict = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(urllib2, "urlopen")
        self.mox.StubOutWithMock(json, "loads")
        self.mox.StubOutWithMock(base64, "b64decode")

        urllib2.urlopen(self.__remote_url).AndReturn(mock_response)
        mock_response.read().AndReturn(mock_html)

        json.loads(mock_html).AndReturn(mock_json_dict)

        base64.b64decode(mock_json_dict["content"].AndReturn(
            self.__mock_file_with_proper_version)).AndReturn(
                self.__mock_file_with_proper_version)

        urllib2.urlopen(self.__remote_url).AndRaise(urllib2.URLError("Timeout"))

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(stable_updater.check())
        self.assertEquals(self.__mocked_remote_version,
                          stable_updater.remote_version)

        self.assertTrue(not stable_updater.check())
        self.assertEquals(None, stable_updater.remote_version)
Example #7
0
    def test_malformed_version_variable_definition(self):
        """ Malformed remote version variables should be handled gracefully.
        """

        version.version = self.__mocked_remote_version

        mock_response = self.mox.CreateMockAnything()
        mock_html = self.mox.CreateMockAnything()
        mock_json_dict = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(urllib2, "urlopen")
        self.mox.StubOutWithMock(json, "loads")
        self.mox.StubOutWithMock(base64, "b64decode")

        urllib2.urlopen(self.__remote_url).AndReturn(mock_response)
        mock_response.read().AndReturn(mock_html)

        json.loads(mock_html).AndReturn(mock_json_dict)

        base64.b64decode(mock_json_dict["content"].AndReturn(
            self.__mock_file_with_malformed_version)).AndReturn(
                self.__mock_file_with_malformed_version)

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(not stable_updater.check())
        self.assertEquals(None, stable_updater.remote_version)
Example #8
0
    def test_github_has_new_version(self):
        """ Ensure proper behavior when we receive a remote version file that
        details a version newer than the current one. """

        version.version = "0.0"

        mock_response = self.mox.CreateMockAnything()
        mock_html = self.mox.CreateMockAnything()
        mock_json_dict = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(urllib2, "urlopen")
        self.mox.StubOutWithMock(json, "loads")
        self.mox.StubOutWithMock(base64, "b64decode")

        urllib2.urlopen(self.__remote_url).AndReturn(mock_response)
        mock_response.read().AndReturn(mock_html)

        json.loads(mock_html).AndReturn(mock_json_dict)

        base64.b64decode(mock_json_dict["content"].AndReturn(
            self.__mock_file_with_proper_version)).AndReturn(
                self.__mock_file_with_proper_version)

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(stable_updater.check())
        self.assertEquals(self.__mocked_remote_version,
                          stable_updater.remote_version)
Example #9
0
    def test_no_remote_version(self):
        """ If there is no remote version to be found, ensure that no updates
        are indicated. """

        version.version = "0.0"

        mock_response = self.mox.CreateMockAnything()
        mock_html = self.mox.CreateMockAnything()
        mock_json_dict = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(urllib2, "urlopen")
        self.mox.StubOutWithMock(json, "loads")
        self.mox.StubOutWithMock(base64, "b64decode")

        urllib2.urlopen(self.__remote_url).AndReturn(mock_response)
        mock_response.read().AndReturn(mock_html)

        json.loads(mock_html).AndReturn(mock_json_dict)

        base64.b64decode(mock_json_dict["content"].AndReturn(
            self.__mock_file_without_version)).AndReturn(
                self.__mock_file_without_version)

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(not stable_updater.check())
        self.assertEquals(None, stable_updater.remote_version)
Example #10
0
    def test_init_stable_update(self):
        """ Make sure that the StableUpdater is used if no updater is detailed.
        """

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

        StableUpdater.__init__(self.__repo, self.__remote_url)

        self.mox.ReplayAll()

        notifyer = UpdateNotifyer(self.__repo, self.__remote_url)
Example #11
0
    def test_invalid_url(self):
        """ Invalid URL should be handled gracefully. """

        version.version = "0.0"

        self.mox.StubOutWithMock(urllib2, "urlopen")

        urllib2.urlopen(self.__remote_url).AndRaise(
            ValueError("Unknown url type"))

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(not stable_updater.check())
        self.assertEquals(None, stable_updater.remote_version)
Example #12
0
    def test_github_not_responding(self):
        """ Make sure that the updater handles unresponsive remote servers
        properly. """

        version.version = "0.0"

        self.mox.StubOutWithMock(urllib2, "urlopen")

        urllib2.urlopen(self.__remote_url).AndRaise(urllib2.URLError("Timeout"))

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(not stable_updater.check())
        self.assertEquals(None, stable_updater.remote_version)
Example #13
0
    def test_start(self):
        """ Make sure that a timer for the proper interval is started when the
        UpdateNotifyer.start method is called. """

        mock_timer = self.mox.CreateMockAnything()

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

        StableUpdater.__init__(self.__repo, self.__remote_url)

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

        self.mox.ReplayAll()

        notifyer = UpdateNotifyer(self.__repo, self.__remote_url)
        notifyer.start()
Example #14
0
    def test_empty_response_read(self):
        """ Empty HTML/JSON should be handled gracefully. """

        version.version = "0.0"

        mock_response = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(urllib2, "urlopen")
        self.mox.StubOutWithMock(json, "loads")
        self.mox.StubOutWithMock(base64, "b64decode")

        urllib2.urlopen(self.__remote_url).AndReturn(mock_response)
        mock_response.read().AndReturn("")

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(not stable_updater.check())
        self.assertEquals(None, stable_updater.remote_version)
Example #15
0
    def test_stop(self):
        """ Ensure that the timer is cancelled if UpdateNotifyer.stop is called.
        """

        mock_timer = self.mox.CreateMockAnything()

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

        StableUpdater.__init__(self.__repo, self.__remote_url)

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

        mock_timer.cancel()

        self.mox.ReplayAll()

        notifyer = UpdateNotifyer(self.__repo, self.__remote_url)
        notifyer.start()
        notifyer.stop()
Example #16
0
    def test_timeout_update_available(self):
        """ Make sure that we get a status update if the selected updater
        indicates that an update is available. """

        mock_timer = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(StableUpdater, "__init__")
        self.mox.StubOutWithMock(StableUpdater, "check")
        self.mox.StubOutWithMock(StableUpdater, "get_update_version")
        self.mox.StubOutWithMock(threading, "Timer")
        self.mox.StubOutWithMock(threading.Thread, "start")
        self.mox.StubOutWithMock(Client, "change_status")

        StableUpdater.__init__(self.__repo, self.__remote_url)

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

        StableUpdater.check().AndReturn(True)
        StableUpdater.get_update_version().AndReturn("1.0")
        Client.change_status(mox.IgnoreArg())

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

        self.mox.ReplayAll()

        notifyer = UpdateNotifyer(self.__repo, self.__remote_url)
        notifyer.start()
        notifyer.timeout()
Example #17
0
    def test_github_response_no_content(self):
        """ Make sure that a request response without any JSON content is
        handled gracefully. """

        version.version = "0.0"

        mock_response = self.mox.CreateMockAnything()
        mock_html = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(urllib2, "urlopen")
        self.mox.StubOutWithMock(json, "loads")

        urllib2.urlopen(self.__remote_url).AndReturn(mock_response)
        mock_response.read().AndReturn(mock_html)

        json.loads(mock_html).AndRaise(ValueError("No JSON object"))

        self.mox.ReplayAll()

        stable_updater = StableUpdater(self.__repo, self.__remote_url)

        self.assertTrue(not stable_updater.check())
        self.assertEquals(None, stable_updater.remote_version)
Example #18
0
    def test_timeout_update_still_available(self):
        """ Make sure that we do not spam with software update notices. Once
        there has been an update notification, updates found thereafter should
        not be indicated. """

        mock_timer = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(StableUpdater, "__init__")
        self.mox.StubOutWithMock(StableUpdater, "check")
        self.mox.StubOutWithMock(StableUpdater, "get_update_version")
        self.mox.StubOutWithMock(threading, "Timer")
        self.mox.StubOutWithMock(threading.Thread, "start")
        self.mox.StubOutWithMock(Client, "change_status")

        StableUpdater.__init__(self.__repo, self.__remote_url)

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

        StableUpdater.check().AndReturn(True)
        Client.change_status(mox.IgnoreArg())

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

        StableUpdater.check().AndReturn(True)
        StableUpdater.get_update_version().AndReturn("1.0")

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

        self.mox.ReplayAll()

        notifyer = UpdateNotifyer(self.__repo, self.__remote_url)
        notifyer.start()
        notifyer.timeout()
        notifyer.timeout()
Example #19
0
    def test_toggle_update_availability(self):
        """ Make sure that the update indicaiton is reset if an update all of a
        sudden is not available. """

        mock_timer = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(StableUpdater, "__init__")
        self.mox.StubOutWithMock(StableUpdater, "check")
        self.mox.StubOutWithMock(StableUpdater, "get_update_version")
        self.mox.StubOutWithMock(threading, "Timer")
        self.mox.StubOutWithMock(threading.Thread, "start")
        self.mox.StubOutWithMock(Client, "change_status")

        StableUpdater.__init__(self.__repo, self.__remote_url)

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

        StableUpdater.check().AndReturn(True)
        StableUpdater.get_update_version().AndReturn("1.0")
        Client.change_status(mox.IgnoreArg())

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

        StableUpdater.check().AndReturn(True)
        StableUpdater.get_update_version().AndReturn("1.0")

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

        StableUpdater.check().AndReturn(False)

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

        StableUpdater.check().AndReturn(True)
        Client.change_status(mox.IgnoreArg())

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

        self.mox.ReplayAll()

        notifyer = UpdateNotifyer(self.__repo, self.__remote_url)
        notifyer.start()
        notifyer.timeout()
        notifyer.timeout()
        notifyer.timeout()
        notifyer.timeout()