summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--UpdateManager/Common/aptsources.py8
-rw-r--r--tests/data/sources.list6
-rw-r--r--tests/test_aptsources.py85
3 files changed, 99 insertions, 0 deletions
diff --git a/UpdateManager/Common/aptsources.py b/UpdateManager/Common/aptsources.py
index 1fa080da..b5fa050d 100644
--- a/UpdateManager/Common/aptsources.py
+++ b/UpdateManager/Common/aptsources.py
@@ -90,6 +90,14 @@ class SourceEntry:
self.template = None
self.children = []
+ def __eq__(self, other):
+ return (self.disabled == other.disabled and
+ self.type == other.type and
+ self.uri == other.uri and
+ self.dist == other.dist and
+ self.comps == other.comps)
+
+
# works mostely like split but takes [] into account
def mysplit(self, line):
line = string.strip(line)
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/test_aptsources.py b/tests/test_aptsources.py
new file mode 100644
index 00000000..4d7e6a0b
--- /dev/null
+++ b/tests/test_aptsources.py
@@ -0,0 +1,85 @@
+#!/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()
+
+ def testAddComponent(self):
+ pass
+
+ 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):
+ sources = aptsources.SourcesList()
+ # test refresh
+ apt_pkg.Config.Set("Dir::Etc", os.getcwd())
+ apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list")
+ apt_pkg.Config.Set("Dir::Etc::sourceparts",".")
+ sources.refresh()
+ self.assertEqual(len(sources.list), 6)
+ # test load
+ sources.list = []
+ sources.load("data/sources.list")
+ self.assertEqual(len(sources.list), 6)
+ # 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: universe
+ before = copy.deepcopy(sources)
+ 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:
+ print c
+ if c == "universe":
+ found_universe += 1
+ if c == "something":
+ found_something += 1
+ self.assertEqual(found_something, 1)
+ self.assertEqual(found_universe, 1)
+
+
+
+
+if __name__ == "__main__":
+ unittest.main()