Tizen 2.1 base
[external/libzypp-bindings.git] / swig / python / tests / repoinfo.py
1 #!/usr/bin/python
2 #
3 # Author: Jan Blunck <jblunck@suse.de>
4 #
5
6 import unittest
7
8 import os 
9 cwd = os.path.abspath(os.path.dirname(__file__)) 
10
11 import sys
12 sys.path.insert(0, cwd + "/../../../build/swig/python")
13
14 from zypp import RepoInfo, Url, UrlSet, RepoType
15
16 repo_urls = [ "file:/mounts/mirror/SuSE/ftp.opensuse.org/srv/ftp/pub/opensuse/debug/update/11.1/", 
17               "http://download.opensuse.org/debug/update/11.1/" ] 
18
19 class RepoInfoTestCase(unittest.TestCase):
20
21     def setUp(self):
22         self.info = RepoInfo()
23         self.info.addBaseUrl(Url(repo_urls[0]))
24         self.info.addBaseUrl(Url(repo_urls[1]))
25         self.info.setAlias("default")
26         self.info.setName("default")
27         self.info.setEnabled(True)
28         self.info.setType(RepoType.RPMMD)
29         self.info.setGpgCheck(False)
30
31     def testUrlSetIsUrlSet(self):
32         urls = UrlSet()
33         assert urls.__class__.__name__ == "UrlSet", 'Incorrect class (' + urls.__class__.__name__ + ')'
34
35     def testUrlSetAppend(self):
36         urls = UrlSet()
37         urls.append(Url(repo_urls[0]))
38         urls.append(Url(repo_urls[1]))
39         assert urls.size() == 2, 'Incorrect size ' + urls.size()
40
41     def testBaseUrlsReturnsTuple(self):
42         baseurls = self.info.baseUrls()
43         assert baseurls.__class__.__name__ == "tuple", 'Incorrect class (' + baseurls.__class__.__name__ + ')'
44
45     def testBaseUrlsIteratable(self):
46         baseurls = self.info.baseUrls()
47         for url in baseurls:
48             assert url.__str__() in repo_urls, 'Incorrect URL ' + url.__str__()
49
50     def testSetBaseUrl(self):
51         baseurls = self.info.baseUrls()
52         assert len(baseurls) == 2
53         self.info.setBaseUrl(Url(repo_urls[0]))
54         baseurls = self.info.baseUrls()
55         assert len(baseurls) == 1
56
57     def testDump(self):
58         out = self.info.dump()
59         assert len(out) == 396, 'Invalid output length %d' % len(out)
60
61     def testDumpIni(self):
62         out = self.info.dumpAsIni()
63         assert len(out) == 208, 'Invalid output length %d' % len(out)
64
65     def testDumpXML(self):
66         out = self.info.dumpAsXML()
67         assert len(out) == 253, 'Invalid output length %d' % len(out)
68
69 if __name__ == "__main__":
70     unittest.main()