Esempio n. 1
0
 def testDatabase(self):
     self.assertEqual(options.get_database(),
         os.path.abspath('temp/database_1.0.sqlite'))
     #This file doesn't have to exist, because it will be created by the
     #database_update module.  But the directory must exist for the
     #database to be created.
     self.assertTrue(os.path.isdir(options.working_dir))
Esempio n. 2
0
    def testBadRemote(self):
        with sqlite3.connect(options.get_database()) as db:
            c = db.cursor()
            #Test for a malformed JSON file.
            repo0 = os.path.join(options.get_working_dir(),
                os.path.basename(options.get_repos()[0]))
            with open(repo0, 'a') as r: r.write(',')
            self.assertRaises(ValueError, database_update.update_remote_url,
                options.get_repos()[0], c)
            # Test for incorrect version.
            #with open(repo0, 'w') as r:
            #    r.write(self.repotxt % (os.path.basename(repo0), 99.7))
            #self.assertRaises(database_update.RepoError,
            #    database_update.update_remote_url,
            #    database_update.open_repos()[0], c)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            database_update.update_remote()
            # Check appropriate warning is shown.
            self.assertEqual(len(w), 1)
            self.assertIn('Could not process', str(w[0].message))
        # Bad repo (first) must be empty.
        self.assertRaises(TypeError, self._check_entries,
            options.get_repos()[0])
        # Good repo (second) should have correct entries.
        self._check_entries(options.get_repos()[1])

        # Make sure we don't get a TypeError warning, as was caused by issues
        # with last_full_update being unset after an error.
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            database_update.update_remote()
            self.assertEqual(len(w), 1)
            self.assertIn('ValueError', str(w[0].message))
Esempio n. 3
0
 def testRemove(self):
     # Create a slightly-modified sacrificial file.
     src = open(os.path.join(testfiles, 'fulltest.pnd')).read()
     dstpath = os.path.join(testfiles, 'fulltest2.pnd')
     with open(dstpath,'w') as dst:
         dst.write(src.replace('sample-package', 'sample2', 1))
     # Make sure it gets in the database.
     database_update.update_local()
     with sqlite3.connect(options.get_database()) as db:
         self.assertIsNotNone( db.execute(
             'Select * From "%s" Where id="sample2"'
             % database_update.LOCAL_TABLE).fetchone() )
     # Now remove it!
     p = packages.Package('sample2')
     p.remove()
     # And make sure it's gone.
     self.assertFalse(os.path.exists(dstpath))
     with sqlite3.connect(options.get_database()) as db:
         self.assertIsNone( db.execute(
             'Select * From "%s" Where id="sample2"'
             % database_update.LOCAL_TABLE).fetchone() )
     self.assertFalse(p.local.exists)
Esempio n. 4
0
 def _check_entries(self, repo):
     with sqlite3.connect(options.get_database()) as db:
         db.row_factory = sqlite3.Row
         #Check that database has correct entries.
         c = db.execute('Select * From "%s"' % repo)
         i = c.fetchone()
         self.assertEqual(i['id'], 'viceVIC.pickle')
         self.assertEqual(i['uri'], "http://example.org/test.pnd")
         self.assertEqual(i['version'], '4.2.1.3')
         self.assertEqual(i['title'], "Vice xVIC")
         self.assertEqual(i['description'], "A VIC Emulator.")
         self.assertEqual(i['info'], "This package is good.")
         self.assertEqual(i['size'], 6503485692)
         self.assertEqual(i['md5'], '55538bb9c9ff46699c154d3de733c68b')
         self.assertEqual(i['modified_time'], 401234)
         self.assertEqual(i['rating'], 12)
         self.assertEqual(i['author_name'], "Ported by Pickle")
         self.assertEqual(i['author_website'], "http://places.there")
         self.assertEqual(i['author_email'], "*****@*****.**")
         self.assertEqual(i['vendor'], "dflemstr")
         self.assertEqual(i['icon'], "http://example.org/test.png")
         self.assertEqual(i['previewpics'], None)
         self.assertEqual(i['licenses'], None)
         self.assertEqual(i['source'], None)
         self.assertEqual(i['categories'], "Game")
         self.assertEqual(i['applications'], None)
         i = c.fetchone()
         self.assertEqual(i['id'], 'Different VICE')
         self.assertEqual(i['uri'], "http://example.org/test2.pnd")
         self.assertEqual(i['version'], '9.3b.3.6.beta')
         self.assertEqual(i['title'], "Vice xVIC, eh?")
         self.assertEqual(i['description'], "It's not prejudice if I'm Canadian, right?!")
         self.assertEqual(i['info'], None)
         self.assertEqual(i['size'], None)
         self.assertEqual(i['md5'], 'd3de733c68b55538bb9c9ff46699c154')
         self.assertEqual(i['modified_time'], None)
         self.assertEqual(i['rating'], None)
         self.assertEqual(i['author_name'], None)
         self.assertEqual(i['author_website'], None)
         self.assertEqual(i['author_email'], None)
         self.assertEqual(i['vendor'], "Tempel")
         self.assertEqual(i['icon'], "http://example.org/test2.png")
         self.assertEqual(i['previewpics'], None)
         self.assertEqual(i['licenses'], None)
         self.assertEqual(i['source'], None)
         self.assertEqual(i['categories'], "Game;Emulator")
         self.assertEqual(i['applications'], None)
         i = c.fetchone()
         self.assertIsNone(i)
Esempio n. 5
0
    def testMissingTables(self):
        os.remove(options.get_database())
        reload(database_update) # To trigger base table creation.
        database_update.update_local()

        # Empty index table.
        p = packages.Package('not-even-real')
        self.assertFalse(p.local.exists)
        self.assertItemsEqual(p.remote, [])
        self.assertEqual(len(packages.get_all_local()), len(packages.get_all()))

        # Table in index, but doesn't successfully reach it.
        with open(options.get_cfg()) as f:
            txt = f.read()
        new = txt.split('\n')
        new.insert(2, '"http://notreal.ihope",')
        with open(options.get_cfg(), 'w') as f:
            f.write('\n'.join(new))
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            database_update.update_remote()
        packages.get_all()
Esempio n. 6
0
 def testUpdateLocal(self):
     database_update.update_local()
     db = sqlite3.connect(options.get_database())
     db.row_factory = sqlite3.Row
     #Check that database has correct entries.
     c = db.execute('Select * From "%s" Where id="bubbman2"'
         %database_update.LOCAL_TABLE)
     i = c.fetchone()
     self.assertEqual(i['id'], 'bubbman2')
     self.assertEqual(i['version'], '1.0.3.1')
     self.assertEqual(i['author_name'], "pymike")
     self.assertEqual(i['author_website'],
         "http://www.pygame.org/project-BubbMan+2-1114-.html")
     self.assertEqual(i['author_email'], None)
     self.assertEqual(i['title'], "BubbMan2")
     self.assertEqual(i['description'], "A solo entry by pymike for PyWeek #8")
     self.assertEqual(i['icon'], 'data/logo.png')
     self.assertEqual(i['uri'], os.path.join(testfiles, 'BubbMan2.pnd'))
     #self.assertEqual(i['md5'], '84c81afa183561f0bb7b2db692646833')
     self.assertEqual(i['vendor'], None)
     self.assertEqual(i['rating'], None)
     self.assertEqual(i['applications'], 'bubbman2')
     self.assertEqual(i['previewpics'], None)
     self.assertEqual(i['licenses'], None)
     self.assertEqual(i['source'], None)
     self.assertEqual(i['categories'], "Game;ActionGame")
     c = db.execute('Select * From "%s" Where id="sparks"'
         %database_update.LOCAL_TABLE)
     i = c.fetchone()
     self.assertEqual(i['id'], 'sparks')
     self.assertEqual(i['version'], '0.4.2.0')
     self.assertEqual(i['author_name'], "Haltux")
     self.assertEqual(i['author_website'], "https://github.com/haltux")
     self.assertEqual(i['author_email'], None)
     self.assertEqual(i['title'], "Sparks")
     self.assertEqual(i['description'], "A vectorial shooter")
     self.assertEqual(i['icon'], 'icon.png')
     self.assertEqual(i['uri'], os.path.join(testfiles, 'Sparks-0.4.2.pnd'))
     #self.assertEqual(i['md5'], 'fb10014578bb3f0c0ae8e88a0fd81121')
     self.assertEqual(i['vendor'], None)
     self.assertEqual(i['rating'], None)
     self.assertEqual(i['applications'], 'sparks')
     self.assertEqual(i['previewpics'], None)
     self.assertEqual(i['licenses'], None)
     self.assertEqual(i['source'], None)
     self.assertEqual(i['categories'], "Game;ArcadeGame")
     c = db.execute('Select * From "%s" Where id="the-lonely-tower"'
         %database_update.LOCAL_TABLE)
     i = c.fetchone()
     self.assertEqual(i['id'], 'the-lonely-tower')
     self.assertEqual(i['version'], '2.2.0.0')
     self.assertEqual(i['author_name'], "Randy Heydon")
     self.assertEqual(i['author_website'],
         "http://randy.heydon.selfip.net/Programs/The Lonely Tower/")
     self.assertEqual(i['author_email'], None)
     self.assertEqual(i['title'], "The Lonely Tower")
     self.assertEqual(i['description'], "A dumb arty game made for a competition.")
     self.assertEqual(i['icon'],
         'lonelytower/assets/male-brunette-angry-listening-notrans.png')
     self.assertEqual(i['uri'], os.path.join(testfiles, 'The Lonely Tower-2.2.pnd'))
     #self.assertEqual(i['md5'], '0314d0f7055052cd91ec608d63acad2a')
     self.assertEqual(i['vendor'], None)
     self.assertEqual(i['rating'], None)
     self.assertEqual(i['applications'], 'the-lonely-tower')
     self.assertEqual(i['previewpics'], None)
     self.assertEqual(i['licenses'], None)
     self.assertEqual(i['source'], None)
     self.assertEqual(i['categories'], "Game;RolePlaying")
     c = db.execute('Select * From "%s" Where id="sample-package"'
         %database_update.LOCAL_TABLE)
     i = c.fetchone()
     self.assertEqual(i['id'], 'sample-package')
     self.assertEqual(i['version'], '1.0.0.0')
     self.assertEqual(i['author_name'], "packagers name")
     self.assertEqual(i['author_website'], "http://www.website.foo")
     self.assertEqual(i['author_email'], "*****@*****.**")
     self.assertEqual(i['title'], "Sample Collection")
     self.assertEqual(i['description'],
         "This is a really verbose package with a whole lot of stuff from 2 different sources, mixing different things, having stuff in ways sometimes making use of stuff, often not.")
     self.assertEqual(i['icon'], "my-icon.png")
     self.assertEqual(i['uri'], os.path.join(testfiles, 'fulltest.pnd'))
     #self.assertEqual(i['md5'], '201f7b98cc4933cd728087b548035b71')
     self.assertEqual(i['vendor'], None)
     self.assertEqual(i['rating'], None)
     self.assertEqual(i['applications'],
         'sample-app1;sample-app2;sample-app3')
     self.assertEqual(i['previewpics'],
         'preview-image.png;application_1.png;different-preview-image.png')
     # TODO: Add support for license reading, then enable these tests.
     #self.assertEqual(i['licenses'],
     #    'I do as I please;other;Qt-commercial;public domain;GPLv2+;GPLv2+')
     #self.assertEqual(i['source'],
     #    'git://git.openpandora.org;http://pandora.org/sources/package.tar.bz2')
     self.assertEqual(i['categories'],
         "Game;Emulator;System;Emulator;Game;StrategyGame;System")
     c = db.execute('Select * From "%s" Where id="chromium-dev"'
         %database_update.LOCAL_TABLE)
     i = c.fetchone()
     self.assertEqual(i['id'], 'chromium-dev')
     self.assertEqual(i['version'], '10.0.642.1')
     self.assertEqual(i['author_name'], "")
     self.assertEqual(i['author_website'], "http://sites.google.com/a/chromium.org/dev/")
     self.assertEqual(i['author_email'], None)
     self.assertEqual(i['title'], "Chromium-Dev")
     self.assertEqual(i['description'],
         u"Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all users to experience the web. This site contains design documents, architecture overviews, testing information, and more to help you learn to build and work with the Chromium source code.\u201d.")
     self.assertEqual(i['icon'], "product_logo_48.png")
     self.assertEqual(i['uri'], os.path.join(testfiles, 'Chromium-dev.pxml.pnd'))
     #self.assertEqual(i['md5'], 'ec93f8e51b50be4ee51d87d342a6028a')
     self.assertEqual(i['vendor'], None)
     self.assertEqual(i['rating'], None)
     self.assertEqual(i['applications'], 'chromium-dev')
     self.assertEqual(i['previewpics'], './preview.jpg')
     self.assertEqual(i['licenses'], None)
     self.assertEqual(i['source'], None)
     self.assertEqual(i['categories'], 'Network;WebBrowser')