Пример #1
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))
Пример #2
0
    def testRepositories(self):
        with open(options.get_cfg(), 'w') as cfg:
            cfg.write(
"""{
    "repositories": [
        "file://firsturl",
        "http://secondurl",
        "ftp://thirdurl",
        "http://fourthurl"
    ],
    "locales": ["default"],
    "searchpath": ["default"]
}""")
        self.assertEqual(options.get_repos(), ['file://firsturl',
            'http://secondurl','ftp://thirdurl','http://fourthurl'])
Пример #3
0
    def testMissingRemote(self):
        # Add extra non-existent URL to middle of config.
        with open(options.get_cfg()) as f:
            txt = f.read()
        new = txt.split('\n')
        new.insert(3, '"http://notreal.ihope",')
        with open(options.get_cfg(), 'w') as f:
            f.write('\n'.join(new))

        # Make sure other two still update correctly.
        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 reach repo', str(w[0].message))
        r = options.get_repos()
        self._check_entries(r[0])
        self.assertRaises(TypeError, self._check_entries, r[1])
        self._check_entries(r[2])
Пример #4
0
 def testGetRemoteTables(self):
     # Okay, this may seem like a gratuitous function, but it gets around
     # DB quoting issues.  This and options.get_repo will not always produce
     # identical results.
     self.assertEquals(packages.get_remote_tables(), options.get_repos())
Пример #5
0
 def testUpdateRemote(self):
     database_update.update_remote()
     for r in options.get_repos():
         self._check_entries(r)