1 #!/usr/bin/env python2.4
2 from basetest
import BaseTest
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'>
11 <summary>for testing</summary>
12 <implementation id='sha1=3ce644dc725f1d21cfcf02562c76f375944b266a' version='1'/>
16 class TestWriter(BaseTest
):
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
))
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__':