~ubuntu-branches/ubuntu/karmic/zeroinstall-injector/karmic

« back to all changes in this revision

Viewing changes to tests/testdownload.py

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Leonard
  • Date: 2009-04-05 10:40:06 UTC
  • mfrom: (1.1.9 upstream) (6.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090405104006-e3x93j5ibvjqu65a
Tags: 0.39-1ubuntu1
* Updated build for Python 2.6.
* FFe: LP: #336317.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python2.4
 
1
#!/usr/bin/env python2.5
2
2
from basetest import BaseTest
3
3
import sys, tempfile, os
4
4
from StringIO import StringIO
7
7
 
8
8
sys.path.insert(0, '..')
9
9
 
10
 
# If http_proxy is set it can cause the download tests to fail.
11
 
os.environ["http_proxy"] = ""
 
10
os.environ["http_proxy"] = "localhost:8000"
12
11
 
13
12
from zeroinstall.injector import model, autopolicy, gpg, iface_cache, download, reader, trust, handler, background, arch, selections, qdom
14
13
from zeroinstall.zerostore import Store; Store._add_with_helper = lambda *unused: False
99
98
                try:
100
99
                        sys.stdout = StringIO()
101
100
                        self.child = server.handle_requests('Hello.xml', '6FCF121BE2390E0B.gpg')
102
 
                        policy = autopolicy.AutoPolicy('http://localhost:8000/Hello.xml', download_only = False,
 
101
                        policy = autopolicy.AutoPolicy('http://example.com:8000/Hello.xml', download_only = False,
103
102
                                                       handler = DummyHandler())
104
103
                        assert policy.need_download()
105
104
                        sys.stdin = Reply("N\n")
162
161
                        self.child = server.handle_requests('Hello.xml', '6FCF121BE2390E0B.gpg', 'HelloWorld.tgz')
163
162
                        sys.stdin = Reply("Y\n")
164
163
                        _download_missing_selections(Options(), sels)
165
 
                        path = iface_cache.iface_cache.stores.lookup(sels.selections['http://localhost:8000/Hello.xml'].id)
 
164
                        path = iface_cache.iface_cache.stores.lookup(sels.selections['http://example.com:8000/Hello.xml'].id)
 
165
                        assert os.path.exists(os.path.join(path, 'HelloWorld', 'main'))
 
166
 
 
167
                        assert sels.download_missing(iface_cache.iface_cache, None) is None
 
168
                finally:
 
169
                        sys.stdout = old_out
 
170
 
 
171
        def testSelectionsWithFeed(self):
 
172
                from zeroinstall.injector.cli import _download_missing_selections
 
173
                root = qdom.parse(file("selections.xml"))
 
174
                sels = selections.Selections(root)
 
175
                class Options: dry_run = False
 
176
 
 
177
                old_out = sys.stdout
 
178
                try:
 
179
                        sys.stdout = StringIO()
 
180
                        self.child = server.handle_requests('Hello.xml', '6FCF121BE2390E0B.gpg', 'HelloWorld.tgz')
 
181
                        sys.stdin = Reply("Y\n")
 
182
 
 
183
                        from zeroinstall.injector import fetch
 
184
                        from zeroinstall.injector.handler import Handler
 
185
                        handler = Handler()
 
186
                        fetcher = fetch.Fetcher(handler)
 
187
                        handler.wait_for_blocker(fetcher.download_and_import_feed('http://example.com:8000/Hello.xml', iface_cache.iface_cache))
 
188
 
 
189
                        _download_missing_selections(Options(), sels)
 
190
                        path = iface_cache.iface_cache.stores.lookup(sels.selections['http://example.com:8000/Hello.xml'].id)
166
191
                        assert os.path.exists(os.path.join(path, 'HelloWorld', 'main'))
167
192
 
168
193
                        assert sels.download_missing(iface_cache.iface_cache, None) is None
255
280
                try:
256
281
                        sys.stdout = StringIO()
257
282
                        getLogger().setLevel(ERROR)
258
 
                        trust.trust_db.trust_key('DE937DD411906ACF7C263B396FCF121BE2390E0B', 'localhost:8000')
 
283
                        trust.trust_db.trust_key('DE937DD411906ACF7C263B396FCF121BE2390E0B', 'example.com:8000')
259
284
                        self.child = server.handle_requests(server.Give404('/Hello.xml'), 'latest.xml', '/0mirror/keys/6FCF121BE2390E0B.gpg')
260
 
                        policy = autopolicy.AutoPolicy('http://localhost:8000/Hello.xml', download_only = False)
261
 
                        policy.fetcher.feed_mirror = 'http://localhost:8000/0mirror'
 
285
                        policy = autopolicy.AutoPolicy('http://example.com:8000/Hello.xml', download_only = False)
 
286
                        policy.fetcher.feed_mirror = 'http://example.com:8000/0mirror'
262
287
 
263
288
                        refreshed = policy.solve_with_downloads()
264
289
                        policy.handler.wait_for_blocker(refreshed)
271
296
                try:
272
297
                        sys.stdout = StringIO()
273
298
                        getLogger().setLevel(ERROR)
274
 
                        iface = iface_cache.iface_cache.get_interface('http://localhost:8000/Hello.xml')
 
299
                        iface = iface_cache.iface_cache.get_interface('http://example.com:8000/Hello.xml')
275
300
                        mtime = int(os.stat('Hello-new.xml').st_mtime)
276
301
                        iface_cache.iface_cache.update_interface_from_network(iface, file('Hello-new.xml').read(), mtime + 10000)
277
302
 
278
 
                        trust.trust_db.trust_key('DE937DD411906ACF7C263B396FCF121BE2390E0B', 'localhost:8000')
 
303
                        trust.trust_db.trust_key('DE937DD411906ACF7C263B396FCF121BE2390E0B', 'example.com:8000')
279
304
                        self.child = server.handle_requests(server.Give404('/Hello.xml'), 'latest.xml', '/0mirror/keys/6FCF121BE2390E0B.gpg', 'Hello.xml')
280
 
                        policy = autopolicy.AutoPolicy('http://localhost:8000/Hello.xml', download_only = False)
281
 
                        policy.fetcher.feed_mirror = 'http://localhost:8000/0mirror'
 
305
                        policy = autopolicy.AutoPolicy('http://example.com:8000/Hello.xml', download_only = False)
 
306
                        policy.fetcher.feed_mirror = 'http://example.com:8000/0mirror'
282
307
 
283
308
                        # Update from mirror (should ignore out-of-date timestamp)
284
309
                        refreshed = policy.fetcher.download_and_import_feed(iface.uri, iface_cache.iface_cache)
293
318
                                assert "New interface's modification time is before old version" in str(ex)
294
319
 
295
320
                        # Must finish with the newest version
296
 
                        self.assertEquals(1209206132, iface_cache.iface_cache._get_signature_date(iface.uri))
 
321
                        self.assertEquals(1235911552, iface_cache.iface_cache._get_signature_date(iface.uri))
297
322
                finally:
298
323
                        sys.stdout = old_out
299
324
 
300
325
        def testBackground(self, verbose = False):
301
 
                p = autopolicy.AutoPolicy('http://localhost:8000/Hello.xml')
 
326
                p = autopolicy.AutoPolicy('http://example.com:8000/Hello.xml')
302
327
                reader.update(iface_cache.iface_cache.get_interface(p.root), 'Hello.xml')
303
328
                p.freshness = 0
304
329
                p.network_use = model.network_minimal