diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2012-10-17 10:08:36 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2012-10-17 10:08:36 +0200 |
| commit | 718409afe561f7dfc7407214685ccbfacdf31631 (patch) | |
| tree | 837b8b6e1539c1bb976137012ca2c12350dc5150 /tests | |
| parent | 5384546c17c80b809791ef95ac357bc017be83f9 (diff) | |
| parent | 7bd938dd78ab27ec23ffd84811dbdfa5dd83593a (diff) | |
| download | python-apt-718409afe561f7dfc7407214685ccbfacdf31631.tar.gz | |
merged debian-sid branch
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_aptsources.py | 14 | ||||
| -rw-r--r-- | tests/test_auth.py | 29 | ||||
| -rw-r--r-- | tests/test_size_to_str.py | 112 |
3 files changed, 153 insertions, 2 deletions
diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index dcfb0682..41cfabb3 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -233,6 +233,20 @@ class TestAptSources(unittest.TestCase): for key in found: self.assertEqual(found[key], 1) + def test_enable_disabled(self): + """LP: #1042916: Test enabling disabled entry.""" + apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" + "sources.list") + sources = aptsources.sourceslist.SourcesList(True, self.templates) + disabled = sources.add("deb", "http://fi.archive.ubuntu.com/ubuntu/", + "precise", + ["main"]) + disabled.set_enabled(False) + enabled = sources.add("deb", "http://fi.archive.ubuntu.com/ubuntu/", + "precise", + ["main"]) + self.assertEqual(disabled, enabled) + self.assertFalse(disabled.disabled) if __name__ == "__main__": os.chdir(os.path.dirname(__file__)) diff --git a/tests/test_auth.py b/tests/test_auth.py index 99c40db5..2b524d28 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -14,6 +14,13 @@ else: from BaseHTTPServer import HTTPServer from SimpleHTTPServer import SimpleHTTPRequestHandler as HTTPRequestHandler + +if sys.version_info[0] == 2 and sys.version_info[1] == 6: + from unittest2 import TestCase +else: + from unittest import TestCase + + import apt_pkg import apt.auth @@ -103,7 +110,7 @@ DHcut3Yey8o= -----END PGP PUBLIC KEY BLOCK-----""" -class TestAuthKeys(unittest.TestCase): +class TestAuthKeys(TestCase): """Test handling of keys for signed repositories.""" @@ -185,12 +192,30 @@ class TestAuthKeys(unittest.TestCase): self.assertEqual(key.keyid, "46925553") self.assertEqual(key.date, "2012-04-27") + def test_add_key_from_keyserver_too_short(self): + """Ensure that short keyids are not imported""" + with self.assertRaises(apt.auth.AptKeyError): + apt.auth.add_key_from_keyserver("46925553", "hkp://localhost:19191") + + def test_add_key_from_server_mitm(self): + """Verify that the key fingerprint is verified after download""" + self._start_keyserver() + self.addCleanup(self._stop_keyserver) + with self.assertRaises(apt.auth.AptKeyError) as cm: + apt.auth.add_key_from_keyserver( + "0101010178F7FE5C3E65D8AF8B48AD6246925553", + "hkp://localhost:19191") + self.assertTrue( + str(cm.exception).startswith("Fingerprints do not match")) + def testAddKeyFromServer(self): """Install a GnuPG key from a remote server.""" self._start_keyserver() self.addCleanup(self._stop_keyserver) - apt.auth.add_key_from_keyserver("46925553", "hkp://localhost:19191") + apt.auth.add_key_from_keyserver( + "0xa1bD8E9D78F7FE5C3E65D8AF8B48AD6246925553", + "hkp://localhost:19191") ret = apt.auth.list_keys() self.assertEqual(len(ret), 1) diff --git a/tests/test_size_to_str.py b/tests/test_size_to_str.py new file mode 100644 index 00000000..2c2c372f --- /dev/null +++ b/tests/test_size_to_str.py @@ -0,0 +1,112 @@ +#!/usr/bin/python + +__author__ = "Barry Warsaw <barry@ubuntu.com>, James Hunt, Michael Vogt" + +import sys +import unittest + +import apt_pkg + +if sys.version_info[0] == 2 and sys.version_info[1] == 6: + from unittest2 import TestCase +else: + from unittest import TestCase + + +class SizeToStrTestCase(TestCase): + """Test apt_pkg.size_to_str""" + + DATA = { + # XXX: note the trailing spaces for some of these entries! + 10 ** 1 : "10 ", + 10 ** 2 : "100 ", + 10 ** 3 : "1000 ", + 10 ** 4 : "10.0 k", + 10 ** 5 : "100 k", + 10 ** 6 : "1000 k", + 10 ** 7 : "10.0 M", + 10 ** 8 : "100 M", + 10 ** 9 : "1000 M", + 10 ** 10 : "10.0 G", + 10 ** 11 : "100 G", + 10 ** 12 : "1000 G", + 10 ** 13 : "10.0 T", + 10 ** 14 : "100 T", + 10 ** 15 : "1000 T", + 10 ** 16 : "10.0 P", + 10 ** 17 : "100 P", + 10 ** 18 : "1000 P", + 10 ** 19 : "10.0 E", + 10 ** 20 : "100 E", + 10 ** 21 : "1000 E", + 10 ** 22 : "10.0 Z", + 10 ** 23 : "100.0 Z", + 10 ** 24 : "1000 Z", +# 10 ** 25 : "10.0 Y", + 10 ** 26 : "100 Y", + 10 ** 27 : "1000 Y", + + # That's our limit :) + 10 ** 28 : "10000 Y", + + 0 : "0 ", + 1 : "1 ", + 1024 : "1024 ", + 10240 : "10.2 k", + 102400 : "102 k", + 1024000 : "1024 k", + 10240000 : "10.2 M", + 102400000 : "102 M", + 2147483647 : "2147 M", + 2147483648 : "2147 M", + 1024000000 : "1024 M", + 10240000000 : "10.2 G", + + 9 : "9 ", + 99 : "99 ", + 999 : "999 ", + 9999 : "9999 ", + 99999 : "100.0 k", + 999999 : "1000 k", + 9999999 : "10000 k", + 99999999 : "100.0 M", + 999999999 : "1000 M", + 9999999999 : "10000 M", + 99999999999 : "100.0 G", + 999999999999 : "1000 G", + 9999999999999 : "10000 G", + 99999999999999 : "100.0 T", + 999999999999999 : "1000 T", + 9999999999999999 : "10.0 P", + 99999999999999999 : "100 P", + 999999999999999999 : "1000 P", + 9999999999999999999 : "10.0 E", + 99999999999999999999 : "100 E", + 999999999999999999999 : "1000 E", + 9999999999999999999999 : "10.0 Z", + 999999999999999999999999 : "1000 Z", + } + + def test_from_data(self): + for k, v in self.DATA.items(): + size = apt_pkg.size_to_str(k) + msg = "size_to_str(%s) returned '%s', expected '%s'" % (k, size, v) + self.assertEqual(size, v, msg) + + def test_raise_on_unsupported(self): + for v in ["hello", None, {}, [], ()]: + with self.assertRaises(TypeError): + apt_pkg.size_to_str(v) + + +class RegressionTestCase(unittest.TestCase): + """Regression test for LP: #1030278""" + + def test_no_overflow_error(self): + # LP: #1030278 produces an overflow error in size_to_str() with a big + # value under Python 3. + self.assertEqual(apt_pkg.size_to_str(2147483648000000000000), '2147 E') + + +if __name__ == "__main__": + unittest.main() |
