~mvo/update-manager/not-automatic

« back to all changes in this revision

Viewing changes to tests/test_dist_upgrade_fetcher_core.py

  • Committer: Michael Vogt
  • Date: 2009-01-27 13:48:14 UTC
  • Revision ID: michael.vogt@ubuntu.com-20090127134814-irzg2ixiaduozksz
tests/test_dist_upgrade_fetcher_core.py,
tests/data-sources-list-test/sources.list.hardy:
- add tests for the MetaReleaseCore and DistUpgradeCore code
UpdateManager/Core/utils.py:
- make the url_downloadable() function more robust
UpdateManager/Core/MetaRelease.py:
- more debug output (if DEBUG_UPDATE_MANAGER is given)
UpdateManager/Core/DistUpgradeFetcherCore.py:
- more debug output (if DEBUG_UPDATE_MANAGER is given)
- import aptsources right from the beginning to avoid side effect
  of the import (apt_pkg.init() is called on module init)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import unittest
 
4
 
 
5
import os
 
6
import os.path
 
7
import sys
 
8
import time
 
9
sys.path.insert(0, "../")
 
10
 
 
11
from UpdateManager.Core.MetaRelease import *
 
12
from UpdateManager.Core.DistUpgradeFetcherCore import *
 
13
 
 
14
 
 
15
def get_new_dist():
 
16
    """ 
 
17
    common code to test new dist fetching, get the new dist information
 
18
    for hardy+1
 
19
    """
 
20
    meta = MetaReleaseCore()
 
21
    #meta.DEBUG = True
 
22
    meta.current_dist_name = "hardy"
 
23
    meta.METARELEASE_URI = "http://changelogs.ubuntu.com/meta-release"
 
24
    while meta.downloading:
 
25
        time.sleep(0.1)
 
26
    meta._buildMetaReleaseFile()
 
27
    meta.download()
 
28
    return meta.new_dist
 
29
 
 
30
class TestFetchProgress(apt.progress.FetchProgress):
 
31
    " class to test if the fetch progress was run "
 
32
    def start(self):
 
33
        self.started = True
 
34
    def stop(self):
 
35
        self.stopped = True
 
36
    def pulse(self):
 
37
        self.pulsed = True
 
38
        return True
 
39
 
 
40
class TestMetaReleaseCore(unittest.TestCase):
 
41
 
 
42
    def setUp(self):
 
43
        self.new_dist = None
 
44
 
 
45
    def testnewdist(self):
 
46
        new_dist = get_new_dist()
 
47
        self.assert_(new_dist is not None)
 
48
 
 
49
class TestDistUpgradeFetcherCore(DistUpgradeFetcherCore):
 
50
    " subclass of the DistUpgradeFetcherCore class to make it testable "
 
51
    def runDistUpgrader(self):
 
52
        " do not actually run the upgrader here "
 
53
        return True
 
54
 
 
55
class TestDistUpgradeFetcherCoreTestCase(unittest.TestCase):
 
56
    testdir = os.path.abspath("./data-sources-list-test/")
 
57
 
 
58
    def setUp(self):
 
59
        self.new_dist = get_new_dist()
 
60
        apt_pkg.Config.Set("Dir::Etc",self.testdir)
 
61
        apt_pkg.Config.Set("Dir::Etc::sourcelist", "sources.list.hardy")
 
62
    
 
63
    def testfetcher(self):
 
64
        progress = TestFetchProgress()
 
65
        fetcher = TestDistUpgradeFetcherCore(self.new_dist, progress)
 
66
        #fetcher.DEBUG=True
 
67
        res = fetcher.run()
 
68
        self.assertTrue(res)
 
69
        self.assertTrue(progress.started)
 
70
        self.assertTrue(progress.stopped)
 
71
        self.assertTrue(progress.pulsed)
 
72
 
 
73
    def testfetcher_ftp(self):
 
74
        progress = TestFetchProgress()
 
75
        fetcher = TestDistUpgradeFetcherCore(self.new_dist, progress)
 
76
        fetcher.current_dist_name = "hardy"
 
77
        #fetcher.DEBUG=True
 
78
        res = fetcher.run()
 
79
        self.assertTrue(res)
 
80
        self.assert_(fetcher.uri.startswith("ftp://uk.archive.ubuntu.com"))
 
81
        self.assertTrue(progress.started)
 
82
        self.assertTrue(progress.stopped)
 
83
        self.assertTrue(progress.pulsed)
 
84
 
 
85
 
 
86
if __name__ == '__main__':
 
87
    unittest.main()
 
88