Beispiel #1
0
    def test_UpdateCheck(self):
        """Unit tests for class UpdateCheck"""

        update_tests = []
        wa = '<winapp2 url="http://katana.oooninja.com/bleachbit/winapp2.ini" sha512="ce9e18252f608c8aff28811e372124d29a86404f328d3cd51f1f220578744bb8b15f55549eabfe8f1a80657fc940f6d6deece28e0532b3b0901a4c74110f7ba7"/>'
        update_tests.append(
            ('<updates><stable ver="0.8.4">http://084</stable><beta ver="0.8.5beta">http://085beta</beta>%s</updates>' % wa,
                           ((u'0.8.4', u'http://084'), (u'0.8.5beta', u'http://085beta'))))
        update_tests.append(
            ('<updates><stable ver="0.8.4">http://084</stable>%s</updates>' % wa,
                           ((u'0.8.4', u'http://084'), )))
        update_tests.append(
            ('<updates><beta ver="0.8.5beta">http://085beta</beta>%s</updates>' % wa,
                           ((u'0.8.5beta', u'http://085beta'), )))
        update_tests.append(('<updates></updates>', ()))

        # fake network
        original_open = urllib2.build_opener
        xml = ""

        class fake_opener:

            def add_headers(self):
                pass

            def read(self):
                return xml

            def open(self, url):
                return self

        urllib2.build_opener = fake_opener
        for update_test in update_tests:
            xml = update_test[0]
            updates = check_updates(True, False, None, None)
            self.assertEqual(updates, update_test[1])
        urllib2.build_opener = original_open

        # real network
        for update in check_updates(True, False, None, None):
            if not update:
                continue
            ver = update[0]
            url = update[1]
            self.assert_(isinstance(ver, (type(None), unicode)))
            self.assert_(isinstance(url, (type(None), unicode)))

        # test failure
        Common.update_check_url = "http://localhost/doesnotexist"
        self.assertEqual(
            check_updates(True, False, None, None),
            ())
Beispiel #2
0
    def test_UpdateCheck(self):
        """Unit tests for class UpdateCheck"""

        update_tests = []
        wa = '<winapp2 url="http://katana.oooninja.com/bleachbit/winapp2.ini" sha512="ce9e18252f608c8aff28811e372124d29a86404f328d3cd51f1f220578744bb8b15f55549eabfe8f1a80657fc940f6d6deece28e0532b3b0901a4c74110f7ba7"/>'
        update_tests.append(
            ('<updates><stable ver="0.8.4">http://084</stable><beta ver="0.8.5beta">http://085beta</beta>%s</updates>' % wa,
                           ((u'0.8.4', u'http://084'), (u'0.8.5beta', u'http://085beta'))))
        update_tests.append(
            ('<updates><stable ver="0.8.4">http://084</stable>%s</updates>' % wa,
                           ((u'0.8.4', u'http://084'), )))
        update_tests.append(
            ('<updates><beta ver="0.8.5beta">http://085beta</beta>%s</updates>' % wa,
                           ((u'0.8.5beta', u'http://085beta'), )))
        update_tests.append(('<updates></updates>', ()))

        # fake network
        original_open = urllib2.build_opener
        xml = ""

        class fake_opener:

            def add_headers(self):
                pass

            def read(self):
                return xml

            def open(self, url):
                return self

        urllib2.build_opener = fake_opener
        for update_test in update_tests:
            xml = update_test[0]
            updates = check_updates(True, False, None, None)
            self.assertEqual(updates, update_test[1])
        urllib2.build_opener = original_open

        # real network
        for update in check_updates(True, False, None, None):
            if not update:
                continue
            ver = update[0]
            url = update[1]
            self.assert_(isinstance(ver, (type(None), unicode)))
            self.assert_(isinstance(url, (type(None), unicode)))

        # test failure
        Common.update_check_url = "http://localhost/doesnotexist"
        self.assertEqual(
            check_updates(True, False, None, None),
            ())
Beispiel #3
0
 def test_UpdateCheck_real(self):
     """Unit test for class UpdateCheck with bad network address"""
     # expect connection failure
     preserve_url = bleachbit.update_check_url
     bleachbit.update_check_url = "http://localhost/doesnotexist"
     self.assertEqual(check_updates(True, False, None, None), ())
     bleachbit.update_check_url = preserve_url
Beispiel #4
0
    def test_UpdateCheck_fake(self):
        """Unit tests for class UpdateCheck using fake network"""

        wa = '<winapp2 url="http://katana.oooninja.com/bleachbit/winapp2.ini" sha512="ce9e18252f608c8aff28811e372124d29a86404f328d3cd51f1f220578744bb8b15f55549eabfe8f1a80657fc940f6d6deece28e0532b3b0901a4c74110f7ba7"/>'
        update_tests = [
            ('<updates><stable ver="0.8.4">http://084</stable><beta ver="0.8.5beta">http://085beta</beta>%s</updates>'
             % wa, ((u'0.8.4', u'http://084'), (u'0.8.5beta',
                                                u'http://085beta'))),
            ('<updates><stable ver="0.8.4">http://084</stable>%s</updates>' %
             wa, ((u'0.8.4', u'http://084'), )),
            ('<updates><beta ver="0.8.5beta">http://085beta</beta>%s</updates>'
             % wa, ((u'0.8.5beta', u'http://085beta'), )),
            ('<updates></updates>', ())
        ]

        # fake network
        original_open = bleachbit.Update.build_opener
        xml = ""

        class FakeOpener:
            def add_headers(self):
                pass

            def read(self):
                return xml

            def open(self, url):
                return self

        # TODO: mock
        bleachbit.Update.build_opener = FakeOpener
        for xml, expected in update_tests:
            updates = check_updates(True, False, None, None)
            self.assertEqual(updates, expected)
        bleachbit.Update.build_opener = original_open
Beispiel #5
0
    def test_UpdateCheck_fake(self):
        """Unit tests for class UpdateCheck using fake network"""

        wa = '<winapp2 url="http://katana.oooninja.com/bleachbit/winapp2.ini" sha512="ce9e18252f608c8aff28811e372124d29a86404f328d3cd51f1f220578744bb8b15f55549eabfe8f1a80657fc940f6d6deece28e0532b3b0901a4c74110f7ba7"/>'
        update_tests = [
            ('<updates><stable ver="0.8.4">http://084</stable><beta ver="0.8.5beta">http://085beta</beta>%s</updates>' % wa,
                           ((u'0.8.4', u'http://084'), (u'0.8.5beta', u'http://085beta'))),
            ('<updates><stable ver="0.8.4">http://084</stable>%s</updates>' % wa,
                           ((u'0.8.4', u'http://084'), )),
            ('<updates><beta ver="0.8.5beta">http://085beta</beta>%s</updates>' % wa,
                           ((u'0.8.5beta', u'http://085beta'), )),
            ('<updates></updates>', ())]

        # fake network
        original_open = bleachbit.Update.build_opener
        xml = ""

        class FakeOpener:
            def add_headers(self):
                pass

            def read(self):
                return xml

            def open(self, url):
                return self

        # TODO: mock
        bleachbit.Update.build_opener = FakeOpener
        for xml, expected in update_tests:
            updates = check_updates(True, False, None, None)
            self.assertEqual(updates, expected)
        bleachbit.Update.build_opener = original_open
Beispiel #6
0
 def test_UpdateCheck_real(self):
     """Unit test for class UpdateCheck with bad network address"""
     # expect connection failure
     preserve_url = bleachbit.update_check_url
     bleachbit.update_check_url = "http://localhost/doesnotexist"
     self.assertEqual(
         check_updates(True, False, None, None),
         ())
     bleachbit.update_check_url = preserve_url
Beispiel #7
0
    def test_UpdateCheck_real_network(self):
        """Unit tests for class UpdateCheck using real network"""

        # real network
        for update in check_updates(True, False, None, None):
            if not update:
                continue
            ver = update[0]
            url = update[1]
            self.assertIsInstance(ver, (type(None), unicode))
            self.assertIsInstance(url, (type(None), unicode))
Beispiel #8
0
    def test_UpdateCheck_real_network(self):
        """Unit tests for class UpdateCheck using real network"""

        # real network
        for update in check_updates(True, False, None, None):
            if not update:
                continue
            ver = update[0]
            url = update[1]
            self.assertIsInstance(ver, (type(None), unicode))
            self.assertIsInstance(url, (type(None), unicode))