~hakuna-matata/wubi/UEFI

« back to all changes in this revision

Viewing changes to tests/test_backend.py

  • Committer: Evan Dandrea
  • Date: 2011-08-12 16:58:19 UTC
  • mto: This revision was merged to the branch mainline in revision 230.
  • Revision ID: evan.dandrea@canonical.com-20110812165819-yzpbm1vqezq345yz
Initial commit of test work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# tools/pywine -O tests/test_backend.py
 
2
import unittest
 
3
import sys, os
 
4
sys.path.insert(0, 'build\\wubi\\lib')
 
5
from wubi.backends.win32 import backend
 
6
from version import application_name, version, revision
 
7
from wubi import application
 
8
 
 
9
import mock
 
10
from wubi.backends.win32 import registry
 
11
class BackendTests(unittest.TestCase):
 
12
    def setUp(self):
 
13
        w = application.Wubi(application_name, version,
 
14
                             revision, 'build\\wubi')
 
15
        # To get things like info.locale set.
 
16
        w.parse_commandline_arguments()
 
17
        self.back = backend.WindowsBackend(w)
 
18
        w.info.original_exe = os.path.join(os.getcwd(), 'build', 'wubi.exe')
 
19
 
 
20
        # Data
 
21
        self.uninstall_keys = [
 
22
            ('HKEY_LOCAL_MACHINE', 'registry-key', 'UninstallString',
 
23
             'Z:\\tmp\\uninstall-wubi.exe'),
 
24
            ('HKEY_LOCAL_MACHINE', 'registry-key', 'InstallationDir', '/tmp'),
 
25
            ('HKEY_LOCAL_MACHINE', 'registry-key', 'DisplayName', 'Ubuntu'),
 
26
            ('HKEY_LOCAL_MACHINE', 'registry-key', 'DisplayIcon',
 
27
             os.path.join(os.getcwd(), 'build\\wubi\\data\\images\\Wubi.ico')),
 
28
            ('HKEY_LOCAL_MACHINE', 'registry-key', 'DisplayVersion',
 
29
             self.back.info.version_revision),
 
30
            ('HKEY_LOCAL_MACHINE', 'registry-key', 'Publisher', 'Ubuntu'),
 
31
            ('HKEY_LOCAL_MACHINE', 'registry-key', 'URLInfoAbout',
 
32
             'http://www.ubuntu.com'),
 
33
            ('HKEY_LOCAL_MACHINE', 'registry-key', 'HelpLink',
 
34
             'http://www.ubuntu.com/support')]
 
35
        # Patch away!
 
36
        self.save_registry = registry.set_value
 
37
        registry.set_value = mock.Mock()
 
38
    
 
39
    def tearDown(self):
 
40
        registry.set_value = self.save_registry
 
41
 
 
42
    def test_create_uninstaller(self):
 
43
        # We don't have decorators in Python 2.3
 
44
        self.back.info.target_dir = '/tmp'
 
45
        self.back.info.registry_key = 'registry-key'
 
46
        self.back.info.distro = self.back.parse_isolist(
 
47
                                    'build/wubi/data/isolist.ini')[0]
 
48
        self.back.create_uninstaller(None)
 
49
        calls = registry.set_value.call_args_list
 
50
        remove = []
 
51
        for c in calls:
 
52
            if c[0] in self.uninstall_keys:
 
53
                remove.append(c)
 
54
            else:
 
55
                self.fail('Did not expect key to be set: %s' % str(c[0]))
 
56
        for r in remove:
 
57
            calls.remove(r)
 
58
        self.assert_(len(calls) == 0,
 
59
            'Did not set required registry keys:\n%s' % str(calls))
 
60
        # TODO mktempd
 
61
        self.assert_(os.path.exists('/tmp/uninstall-wubi.exe'),
 
62
            'Did not install uninstaller binary.')
 
63
        os.remove('/tmp/uninstall-wubi.exe')
 
64
 
 
65
if __name__ == '__main__':
 
66
    unittest.main()