~ubuntu-branches/ubuntu/quantal/ubuntu-release-upgrader/quantal

« back to all changes in this revision

Viewing changes to tests/test_end_of_life.py

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2012-06-25 12:10:31 UTC
  • Revision ID: package-import@ubuntu.com-20120625121031-n0d033rbh92yc8xp
Tags: 1:0.165
* Rename source package, split upgrade bits out of update-manager
* do-partial-upgrade:
  - Add a private command for running a partial upgrade (dist-upgrade)
* data/com.ubuntu.release-upgrader.policy:
  - Add a PolicyKit policy file to give nice user strings when
    do-partial-upgrade and do-release-upgrade are run under pkexec
* debian/tests:
  - add dep8 tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
from gi.repository import Gtk, GObject
 
4
 
 
5
import mock
 
6
import os
 
7
import subprocess
 
8
import unittest
 
9
 
 
10
CURDIR = os.path.dirname(os.path.abspath(__file__))
 
11
 
 
12
 
 
13
class TestDistroEndOfLife(unittest.TestCase):
 
14
 
 
15
    # we need to test two cases:
 
16
    # - the current distro is end of life
 
17
    # - the next release (the upgrade target) is end of life
 
18
 
 
19
    def test_distro_current_distro_end_of_life(self):
 
20
        """ this code tests that check-new-release-gtk shows a 
 
21
            dist-no-longer-supported dialog when it detects that the 
 
22
            running distribution is no longer supported
 
23
        """
 
24
        def _nag_dialog_close_helper(checker):
 
25
            # this helper is called to verify that the nag dialog appears
 
26
            # and that it 
 
27
            dialog = getattr(checker, "no_longer_supported_nag", None)
 
28
            self.assertNotEqual(dialog, None)
 
29
            dialog.response(Gtk.ResponseType.DELETE_EVENT)
 
30
            self.dialog_called = True
 
31
        # ----
 
32
        try:
 
33
            from check_new_release_gtk import CheckNewReleaseGtk
 
34
        except ImportError:
 
35
            # This may fail in python2, since the Gtk bits needed only exist
 
36
            # in update-manager's python3-only code
 
37
            return
 
38
        options = mock.Mock()
 
39
        options.datadir = CURDIR + "/../data"
 
40
        options.test_uri = None
 
41
        checker = CheckNewReleaseGtk(options)
 
42
        meta_release = mock.Mock()
 
43
        # pretend the current distro is no longer supported
 
44
        meta_release.no_longer_supported = subprocess.Popen(
 
45
            ["lsb_release", "-c", "-s"], 
 
46
            stdout=subprocess.PIPE,
 
47
            universal_newlines=True).communicate()[0].strip()
 
48
        meta_release.flavor_name = "Ubuntu"
 
49
        meta_release.current_dist_version = "0.0"
 
50
        # build new release mock
 
51
        new_dist = mock.Mock()
 
52
        new_dist.name = "zaphod"
 
53
        new_dist.version = "127.0"
 
54
        new_dist.supported = True
 
55
        new_dist.releaseNotesHtmlUri = "http://www.ubuntu.com/html"
 
56
        new_dist.releaseNotesURI = "http://www.ubuntu.com/text"
 
57
        meta_release.upgradable_to = new_dist
 
58
        # schedule a close event in 1 s
 
59
        GObject.timeout_add_seconds(1, _nag_dialog_close_helper, checker)
 
60
        # run the dialog, this will also run a gtk mainloop so that the 
 
61
        # timeout works
 
62
        self.dialog_called = False
 
63
        checker.new_dist_available(meta_release, new_dist)
 
64
        self.assertTrue(self.dialog_called, True)
 
65
 
 
66
    def _p(self):
 
67
        while Gtk.events_pending():
 
68
            Gtk.main_iteration()
 
69
 
 
70
if __name__ == "__main__":
 
71
    import logging
 
72
    logging.basicConfig(level=logging.DEBUG)
 
73
    unittest.main()