1 #!/usr/bin/env python2.4
2 from basetest
import BaseTest
3 import sys
, tempfile
, os
, shutil
, StringIO
6 sys
.path
.insert(0, '..')
7 from zeroinstall
.injector
import writer
, model
, reader
, qdom
8 from zeroinstall
.support
import basedir
10 test_feed
= qdom
.parse(StringIO
.StringIO("""<interface xmlns='http://zero-install.sourceforge.net/2004/injector/interface'>
12 <summary>for testing</summary>
13 <implementation id='sha1=3ce644dc725f1d21cfcf02562c76f375944b266a' version='1'/>
17 class TestWriter(BaseTest
):
19 iface
= model
.Interface('http://test/test')
20 iface
._main
_feed
= model
.ZeroInstallFeed(test_feed
, local_path
= '/Hello')
21 iface
.stability_policy
= model
.developer
22 iface
._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
)
27 iface
= model
.Interface('http://test/test')
28 self
.assertEquals(None, iface
.stability_policy
)
29 iface
._main
_feed
= model
.ZeroInstallFeed(test_feed
, local_path
= '/Hello')
30 reader
.update_user_overrides(iface
, iface
._main
_feed
)
31 self
.assertEquals(model
.developer
, iface
.stability_policy
)
32 self
.assertEquals(100, iface
.last_checked
)
33 self
.assertEquals(None, iface
.get_feed('http://sys-feed'))
34 feed
= iface
.get_feed('http://user-feed')
35 self
.assertEquals('http://user-feed', feed
.uri
)
36 self
.assertEquals('Linux', feed
.os
)
37 self
.assertEquals(None, feed
.machine
)
39 def testStoreNothing(self
):
40 iface
= model
.Interface('http://test/test')
41 writer
.save_interface(iface
)
43 iface
= model
.Interface('http://test/test')
44 self
.assertEquals(None, iface
.stability_policy
)
45 reader
.update_user_overrides(iface
)
46 self
.assertEquals({}, iface
.implementations
)
48 def testStoreStability(self
):
49 iface
= model
.Interface('http://localhost:8000/Hello')
50 iface
._main
_feed
= model
.ZeroInstallFeed(test_feed
, local_path
= '/Hello')
51 impl
= iface
.implementations
['sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
52 impl
.user_stability
= model
.developer
53 writer
.save_interface(iface
)
55 iface
= model
.Interface('http://localhost:8000/Hello')
56 self
.assertEquals(None, iface
.stability_policy
)
57 reader
.update_user_overrides(iface
)
59 # Ignored because not in main interface
60 self
.assertEquals(0, len(iface
.implementations
))
63 reader
.update(iface
, 'Hello.xml')
64 reader
.update_user_overrides(iface
)
65 self
.assertEquals(1, len(iface
.implementations
))
67 impl
= iface
.implementations
['sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
68 self
.assertEquals(model
.developer
, impl
.user_stability
)
70 suite
= unittest
.makeSuite(TestWriter
)
71 if __name__
== '__main__':