2 from basetest
import BaseTest
6 sys
.path
.insert(0, '..')
7 from zeroinstall
.injector
import writer
, model
, reader
, qdom
, iface_cache
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 main_feed
= model
.ZeroInstallFeed(test_feed
, local_path
= '/Hello')
20 iface_cache
.iface_cache
._feeds
[iface
.uri
] = main_feed
21 iface
.stability_policy
= model
.developer
22 main_feed
.last_checked
= 100
23 iface
.extra_feeds
.append(model
.Feed('http://sys-feed', None, False))
24 iface
.extra_feeds
.append(model
.Feed('http://user-feed', 'Linux-*', True))
25 writer
.save_interface(iface
)
26 writer
.save_feed(main_feed
)
28 iface
= model
.Interface('http://test/test')
29 self
.assertEquals(None, iface
.stability_policy
)
30 main_feed
= model
.ZeroInstallFeed(test_feed
, local_path
= '/Hello')
31 iface_cache
.iface_cache
._feeds
[iface
.uri
] = main_feed
32 reader
.update_user_overrides(iface
)
33 reader
.update_user_feed_overrides(main_feed
)
34 self
.assertEquals(model
.developer
, iface
.stability_policy
)
35 self
.assertEquals(100, main_feed
.last_checked
)
36 self
.assertEquals("[<Feed from http://user-feed>]", str(iface
.extra_feeds
))
38 feed
= iface
.extra_feeds
[0]
39 self
.assertEquals('http://user-feed', feed
.uri
)
40 self
.assertEquals('Linux', feed
.os
)
41 self
.assertEquals(None, feed
.machine
)
43 def testStoreNothing(self
):
44 iface
= model
.Interface('http://test/test')
45 writer
.save_interface(iface
)
47 iface
= model
.Interface('http://test/test')
48 self
.assertEquals(None, iface
.stability_policy
)
49 reader
.update_user_overrides(iface
)
51 feed
= iface_cache
.iface_cache
.get_feed(iface
.uri
)
52 self
.assertEquals(None, feed
)
54 def testStoreStability(self
):
55 main_feed
= reader
.load_feed('Hello.xml', local
= True)
56 impl
= main_feed
.implementations
['sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
57 impl
.user_stability
= model
.developer
58 writer
.save_feed(main_feed
)
61 main_feed
= reader
.load_feed('Hello.xml', local
= True)
62 reader
.update_user_feed_overrides(main_feed
)
63 self
.assertEquals(1, len(main_feed
.implementations
))
65 impl
= main_feed
.implementations
['sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
66 self
.assertEquals(model
.developer
, impl
.user_stability
)
68 if __name__
== '__main__':