~ubuntu-core-dev/ubuntu/xenial/ubuntu-release-upgrader/xenial

« back to all changes in this revision

Viewing changes to tests/test_end_of_life.py

  • Committer: Michael Vogt
  • Date: 2011-04-04 08:35:59 UTC
  • Revision ID: michael.vogt@ubuntu.com-20110404083559-7usgqbncrtmp9k35
add tests around the distro end of life handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import apt
 
4
import apt_pkg
 
5
import glib
 
6
import gtk
 
7
import hashlib
 
8
import mock
 
9
import os
 
10
import unittest
 
11
import shutil
 
12
import subprocess
 
13
import sys
 
14
import tempfile
 
15
 
 
16
sys.path.insert(0,"../")
 
17
 
 
18
class TestDistroEndOfLife(unittest.TestCase):
 
19
 
 
20
    # we need to test two cases:
 
21
    # - the current distro is end of life
 
22
    # - the next release (the upgrade target) is end of life
 
23
 
 
24
    def test_distro_current_distro_end_of_life(self):
 
25
        """ this code tests that check-new-release-gtk shows a 
 
26
            dist-no-longer-supported dialog when it detects that the 
 
27
            running distribution is no longer supported
 
28
        """
 
29
        def _nag_dialog_close_helper(checker):
 
30
            # this helper is called to verify that the nag dialog appears
 
31
            # and that it 
 
32
            dialog = checker.window_main.get_data("no-longer-supported-nag")
 
33
            self.assertNotEqual(dialog, None)
 
34
            dialog.response(gtk.RESPONSE_DELETE_EVENT)
 
35
            self.dialog_called = True
 
36
        # ----
 
37
        from check_new_release_gtk import CheckNewReleaseGtk
 
38
        options = mock.Mock()
 
39
        options.datadir = "../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).communicate()[0].strip()
 
47
        # build new release mock
 
48
        new_dist = mock.Mock()
 
49
        new_dist.name = "zaphod"
 
50
        new_dist.version = "127.0"
 
51
        new_dist.supported = True
 
52
        new_dist.releaseNotesHtmlUri = "http://www.ubuntu.com/html"
 
53
        new_dist.releaseNotesURI = "http://www.ubuntu.com/text"
 
54
        # schedule a close event in 1 s
 
55
        glib.timeout_add_seconds(1, _nag_dialog_close_helper, checker)
 
56
        # run the dialog, this will also run a gtk mainloop so that the 
 
57
        # timeout works
 
58
        self.dialog_called = False
 
59
        checker.new_dist_available(meta_release, new_dist)
 
60
        self.assertTrue(self.dialog_called, True)
 
61
 
 
62
 
 
63
    def _p(self):
 
64
        while gtk.events_pending():
 
65
            gtk.main_iteration()
 
66
 
 
67
if __name__ == "__main__":
 
68
    import logging
 
69
    logging.basicConfig(level=logging.DEBUG)
 
70
    unittest.main()