Update swedish translations
[zeroinstall/zeroinstall-rsl.git] / tests / testwriter.py
blob9c07e8006bc5df87719f0ca1ea8f5b09337b14b1
1 #!/usr/bin/env python2.4
2 from basetest import BaseTest
3 import sys, StringIO
4 import unittest
6 sys.path.insert(0, '..')
7 from zeroinstall.injector import writer, model, reader, qdom
9 test_feed = qdom.parse(StringIO.StringIO("""<interface xmlns='http://zero-install.sourceforge.net/2004/injector/interface'>
10 <name>Test</name>
11 <summary>for testing</summary>
12 <implementation id='sha1=3ce644dc725f1d21cfcf02562c76f375944b266a' version='1'/>
13 </interface>
14 """))
16 class TestWriter(BaseTest):
17 def testFeeds(self):
18 iface = model.Interface('http://test/test')
19 iface._main_feed = model.ZeroInstallFeed(test_feed, local_path = '/Hello')
20 iface.stability_policy = model.developer
21 iface._main_feed.last_checked = 100
22 iface.extra_feeds.append(model.Feed('http://sys-feed', None, False))
23 iface.extra_feeds.append(model.Feed('http://user-feed', 'Linux-*', True))
24 writer.save_interface(iface)
26 iface = model.Interface('http://test/test')
27 self.assertEquals(None, iface.stability_policy)
28 iface._main_feed = model.ZeroInstallFeed(test_feed, local_path = '/Hello')
29 reader.update_user_overrides(iface, iface._main_feed)
30 self.assertEquals(model.developer, iface.stability_policy)
31 self.assertEquals(100, iface.last_checked)
32 self.assertEquals(None, iface.get_feed('http://sys-feed'))
33 feed = iface.get_feed('http://user-feed')
34 self.assertEquals('http://user-feed', feed.uri)
35 self.assertEquals('Linux', feed.os)
36 self.assertEquals(None, feed.machine)
38 def testStoreNothing(self):
39 iface = model.Interface('http://test/test')
40 writer.save_interface(iface)
42 iface = model.Interface('http://test/test')
43 self.assertEquals(None, iface.stability_policy)
44 reader.update_user_overrides(iface)
45 self.assertEquals({}, iface.implementations)
47 def testStoreStability(self):
48 iface = model.Interface('http://localhost:8000/Hello.xml')
49 iface._main_feed = model.ZeroInstallFeed(test_feed, local_path = '/Hello.xml')
50 impl = iface.implementations['sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
51 impl.user_stability = model.developer
52 writer.save_interface(iface)
54 iface = model.Interface('http://localhost:8000/Hello.xml')
55 self.assertEquals(None, iface.stability_policy)
56 reader.update_user_overrides(iface)
58 # Ignored because not in main interface
59 self.assertEquals(0, len(iface.implementations))
61 # Now visible
62 reader.update(iface, 'Hello.xml')
63 reader.update_user_overrides(iface)
64 self.assertEquals(1, len(iface.implementations))
66 impl = iface.implementations['sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
67 self.assertEquals(model.developer, impl.user_stability)
69 suite = unittest.makeSuite(TestWriter)
70 if __name__ == '__main__':
71 sys.argv.append('-v')
72 unittest.main()