summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorglatzor@ubuntu.com <>2006-09-09 23:02:52 +0200
committerglatzor@ubuntu.com <>2006-09-09 23:02:52 +0200
commita5a1685317f25de0a0d7bd8ccc5317a17fa219bf (patch)
tree4eaf74f7e56334a1a8c787b2ac5d8ee1f675c3bd /tests
parent650cb474d23914be801af09d5f9c31cfc9765b07 (diff)
parente4b06af1ace3bbb4281a9c762113f8a2699116c3 (diff)
downloadpython-apt-a5a1685317f25de0a0d7bd8ccc5317a17fa219bf.tar.gz
* merge with mvo
Diffstat (limited to 'tests')
-rw-r--r--tests/data/sources.list6
-rw-r--r--tests/data/sources.list.testDistribution14
-rw-r--r--tests/test_aptsources.py99
3 files changed, 119 insertions, 0 deletions
diff --git a/tests/data/sources.list b/tests/data/sources.list
new file mode 100644
index 00000000..5481d4f0
--- /dev/null
+++ b/tests/data/sources.list
@@ -0,0 +1,6 @@
+# comment 1
+deb http://de.archive.ubuntu.com/ubuntu/ edgy main
+# comment 2
+deb http://de.archive.ubuntu.com/ubuntu/ edgy restricted
+# comment 3
+deb http://de.archive.ubuntu.com/ubuntu/ edgy universe \ No newline at end of file
diff --git a/tests/data/sources.list.testDistribution b/tests/data/sources.list.testDistribution
new file mode 100644
index 00000000..dd900645
--- /dev/null
+++ b/tests/data/sources.list.testDistribution
@@ -0,0 +1,14 @@
+# comment 1
+deb http://de.archive.ubuntu.com/ubuntu/ edgy main
+# comment 2
+deb http://de.archive.ubuntu.com/ubuntu/ edgy restricted
+# comment 3
+deb http://de.archive.ubuntu.com/ubuntu/ edgy universe
+# comment 4
+deb http://de.archive.ubuntu.com/ubuntu/ edgy-updates universe multiverse
+# comment 5
+deb http://de.archive.ubuntu.com/ubuntu/ edgy-security main
+# comment 6
+deb http://ftp.debian.org/debian sid main
+# comment 7
+deb http://de.archive.ubuntu.com/ubuntu/ breezy main \ No newline at end of file
diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py
new file mode 100644
index 00000000..d5b5ff9f
--- /dev/null
+++ b/tests/test_aptsources.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+
+import UpdateManager.Common.aptsources as aptsources
+import unittest
+import apt_pkg
+import os
+import copy
+
+class TestAptSources(unittest.TestCase):
+ def __init__(self, methodName):
+ unittest.TestCase.__init__(self, methodName)
+ apt_pkg.init()
+ apt_pkg.Config.Set("Dir::Etc", os.getcwd())
+ apt_pkg.Config.Set("Dir::Etc::sourceparts",".")
+
+ def testIsMirror(self):
+ self.assertTrue(aptsources.is_mirror("http://archive.ubuntu.com",
+ "http://de.archive.ubuntu.com"))
+ self.assertFalse(aptsources.is_mirror("http://archive.ubuntu.com",
+ "http://ftp.debian.org"))
+
+ def testSourcesListReading(self):
+ apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list")
+ sources = aptsources.SourcesList()
+ self.assertEqual(len(sources.list), 6)
+ # test load
+ sources.list = []
+ sources.load("data/sources.list")
+ self.assertEqual(len(sources.list), 6)
+
+ def testSourcesListAdding(self):
+ apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list")
+ sources = aptsources.SourcesList()
+ # test to add something that is already there (main)
+ before = copy.deepcopy(sources)
+ sources.add("deb","http://de.archive.ubuntu.com/ubuntu/",
+ "edgy",
+ ["main"])
+ self.assertTrue(sources.list == before.list)
+ # test to add something that is already there (restricted)
+ before = copy.deepcopy(sources)
+ sources.add("deb","http://de.archive.ubuntu.com/ubuntu/",
+ "edgy",
+ ["restricted"])
+ self.assertTrue(sources.list == before.list)
+ # test to add something new: multiverse
+ sources.add("deb","http://de.archive.ubuntu.com/ubuntu/",
+ "edgy",
+ ["multiverse"])
+ found = False
+ for entry in sources:
+ if (entry.type == "deb" and
+ entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and
+ entry.dist == "edgy" and
+ "multiverse" in entry.comps):
+ found = True
+ self.assertTrue(found)
+ # test to add something new: multiverse *and*
+ # something that is already there
+ before = copy.deepcopy(sources)
+ sources.add("deb","http://de.archive.ubuntu.com/ubuntu/",
+ "edgy",
+ ["universe", "something"])
+ found_universe = 0
+ found_something = 0
+ for entry in sources:
+ if (entry.type == "deb" and
+ entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and
+ entry.dist == "edgy"):
+ for c in entry.comps:
+ if c == "universe":
+ found_universe += 1
+ if c == "something":
+ found_something += 1
+ #print "\n".join([s.str() for s in sources])
+ self.assertEqual(found_something, 1)
+ self.assertEqual(found_universe, 1)
+
+ def testDistribution(self):
+ apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list.testDistribution")
+ sources = aptsources.SourcesList()
+ distro = aptsources.Distribution()
+ distro.get_sources(sources)
+ comp = "restricted"
+ distro.enable_component(sources, comp)
+ found = 0
+ for entry in sources:
+ if (entry.type == "deb" and
+ entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and
+ entry.dist == "edgy"):
+ for c in entry.comps:
+ if c == comp:
+ found += 1
+ print "".join([s.str() for s in sources])
+ self.assertEqual(found, 1)
+
+
+if __name__ == "__main__":
+ unittest.main()