Added --get-selections and --set-selections. This allows you to save the
[zeroinstall/zeroinstall-rsl.git] / tests / testwriter.py
blobaa02a1015ca2a0d0666a5651a7272b5a9d0a2ec7
1 #!/usr/bin/env python2.3
2 from basetest import BaseTest
3 import sys, tempfile, os, shutil
4 import unittest
6 sys.path.insert(0, '..')
7 from zeroinstall.injector import writer, model, basedir, reader
9 class TestWriter(BaseTest):
10 def testFeeds(self):
11 iface = model.Interface('http://test/test')
12 iface.stability_policy = model.developer
13 iface.last_checked = 100
14 iface.feeds.append(model.Feed('http://sys-feed', None, False))
15 iface.feeds.append(model.Feed('http://user-feed', 'Linux-*', True))
16 writer.save_interface(iface)
18 iface = model.Interface('http://test/test')
19 self.assertEquals(None, iface.stability_policy)
20 reader.update_user_overrides(iface)
21 self.assertEquals(model.developer, iface.stability_policy)
22 self.assertEquals(100, iface.last_checked)
23 self.assertEquals(None, iface.get_feed('http://sys-feed'))
24 feed = iface.get_feed('http://user-feed')
25 self.assertEquals('http://user-feed', feed.uri)
26 self.assertEquals('Linux', feed.os)
27 self.assertEquals(None, feed.machine)
29 def testStoreNothing(self):
30 iface = model.Interface('http://test/test')
31 impl = iface.get_impl('/some/path')
32 writer.save_interface(iface)
34 iface = model.Interface('http://test/test')
35 self.assertEquals(None, iface.stability_policy)
36 reader.update_user_overrides(iface)
37 self.assertEquals({}, iface.implementations)
39 def testStoreStability(self):
40 iface = model.Interface('http://localhost:8000/Hello')
41 impl = iface.get_impl('sha1=3ce644dc725f1d21cfcf02562c76f375944b266a')
42 impl.user_stability = model.developer
43 writer.save_interface(iface)
45 iface = model.Interface('http://localhost:8000/Hello')
46 self.assertEquals(None, iface.stability_policy)
47 reader.update_user_overrides(iface)
49 # Ignored because not in main interface
50 self.assertEquals(0, len(iface.implementations))
52 # Now visible
53 reader.update(iface, 'Hello.xml')
54 reader.update_user_overrides(iface)
55 self.assertEquals(1, len(iface.implementations))
57 impl = iface.implementations['sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
58 self.assertEquals(model.developer, impl.user_stability)
60 suite = unittest.makeSuite(TestWriter)
61 if __name__ == '__main__':
62 sys.argv.append('-v')
63 unittest.main()