Fixed proxy handling
[zeroinstall.git] / tests / testpolicy.py
blob1e733f1c7da8235f13837559aa230625fa3a05fc
1 #!/usr/bin/env python
2 from basetest import BaseTest
3 import sys
4 import unittest
6 sys.path.insert(0, '..')
7 from zeroinstall.support import tasks
8 from zeroinstall.injector import model
9 from zeroinstall.injector.policy import Policy
11 import warnings
12 import logging
13 logger = logging.getLogger()
14 #logger.setLevel(logging.DEBUG)
16 class TestPolicy(BaseTest):
17 def testSource(self):
18 iface_cache = self.config.iface_cache
20 foo = iface_cache.get_interface('http://foo/Binary.xml')
21 self.import_feed(foo.uri, 'Binary.xml')
22 foo_src = iface_cache.get_interface('http://foo/Source.xml')
23 self.import_feed(foo_src.uri, 'Source.xml')
24 compiler = iface_cache.get_interface('http://foo/Compiler.xml')
25 self.import_feed(compiler.uri, 'Compiler.xml')
27 self.config.freshness = 0
28 self.config.network_use = model.network_full
29 p = Policy('http://foo/Binary.xml', config = self.config)
30 tasks.wait_for_blocker(p.solve_with_downloads())
31 assert p.implementation[foo].id == 'sha1=123'
33 # Now ask for source instead
34 p.requirements.source = True
35 p.requirements.command = 'compile'
36 tasks.wait_for_blocker(p.solve_with_downloads())
37 assert p.solver.ready, p.solver.get_failure_reason()
38 assert p.implementation[foo].id == 'sha1=234' # The source
39 assert p.implementation[compiler].id == 'sha1=345' # A binary needed to compile it
41 if __name__ == '__main__':
42 unittest.main()