957.1.5
by Julian Andres Klode
Add changelog entry and test case |
1 |
#!/usr/bin/python3
|
2 |
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
|
|
3 |
||
4 |
import apt_check |
|
5 |
import io |
|
6 |
import unittest |
|
7 |
import textwrap |
|
8 |
||
9 |
||
10 |
def get_message(*args, **kwds): |
|
11 |
with io.StringIO() as stream: |
|
12 |
apt_check.write_human_readable_summary(stream, *args, **kwds) |
|
13 |
return stream.getvalue() |
|
14 |
||
15 |
||
16 |
class TestMotd(unittest.TestCase): |
|
17 |
""" ensure that the tree is pep8 clean """
|
|
18 |
||
19 |
def test_esm_disabled_upto_date_esm_avail(self): |
|
20 |
self.assertEqual( |
|
21 |
get_message(upgrades=0, security_updates=0, |
|
22 |
esm_updates=0, have_esm=False, |
|
23 |
disabled_esm_updates=23), |
|
24 |
textwrap.dedent( |
|
25 |
"""
|
|
26 |
Extended Security Maintenance (ESM) is not enabled.
|
|
27 |
||
28 |
0 updates can be installed immediately.
|
|
29 |
0 of these updates are security updates.
|
|
30 |
||
31 |
Enable ESM to receive 23 additional security updates.
|
|
32 |
See 'ua enable esm' or https://ubuntu.com/esm
|
|
33 |
""").lstrip()) |
|
34 |
||
35 |
def test_esm_disabled_security_esm_avail(self): |
|
36 |
self.assertEqual( |
|
37 |
get_message(upgrades=15, security_updates=7, |
|
38 |
esm_updates=0, have_esm=False, |
|
39 |
disabled_esm_updates=23), |
|
40 |
textwrap.dedent( |
|
41 |
"""
|
|
42 |
Extended Security Maintenance (ESM) is not enabled.
|
|
43 |
||
44 |
15 updates can be installed immediately.
|
|
45 |
7 of these updates are security updates.
|
|
46 |
||
47 |
Enable ESM to receive 23 additional security updates.
|
|
48 |
See 'ua enable esm' or https://ubuntu.com/esm
|
|
49 |
""").lstrip()) |
|
50 |
||
51 |
def test_esm_disabled_security_no_esm_avail(self): |
|
52 |
self.assertEqual( |
|
53 |
get_message(upgrades=15, security_updates=7, |
|
54 |
esm_updates=0, have_esm=False, |
|
55 |
disabled_esm_updates=0), |
|
56 |
textwrap.dedent( |
|
57 |
"""
|
|
58 |
Extended Security Maintenance (ESM) is not enabled.
|
|
59 |
||
60 |
15 updates can be installed immediately.
|
|
61 |
7 of these updates are security updates.
|
|
963
by Julian Andres Klode
We told people ESM is not enabled, but not how to enable it. |
62 |
|
63 |
Enable ESM to receive additional future security updates.
|
|
64 |
See 'ua enable esm' or https://ubuntu.com/esm
|
|
957.1.5
by Julian Andres Klode
Add changelog entry and test case |
65 |
""").lstrip()) |
66 |
||
67 |
def test_esm_disabled_nosecurity(self): |
|
68 |
self.assertEqual( |
|
69 |
get_message(upgrades=15, security_updates=0, |
|
70 |
esm_updates=0, have_esm=False, |
|
71 |
disabled_esm_updates=0), |
|
72 |
textwrap.dedent( |
|
73 |
"""
|
|
74 |
Extended Security Maintenance (ESM) is not enabled.
|
|
75 |
||
76 |
15 updates can be installed immediately.
|
|
77 |
0 of these updates are security updates.
|
|
963
by Julian Andres Klode
We told people ESM is not enabled, but not how to enable it. |
78 |
|
79 |
Enable ESM to receive additional future security updates.
|
|
80 |
See 'ua enable esm' or https://ubuntu.com/esm
|
|
957.1.5
by Julian Andres Klode
Add changelog entry and test case |
81 |
""").lstrip()) |
82 |
||
83 |
def test_esm_disabled_noupdates(self): |
|
84 |
self.assertEqual( |
|
85 |
get_message(upgrades=0, security_updates=0, |
|
86 |
esm_updates=0, have_esm=False, |
|
87 |
disabled_esm_updates=0), |
|
88 |
textwrap.dedent( |
|
89 |
"""
|
|
90 |
Extended Security Maintenance (ESM) is not enabled.
|
|
91 |
||
92 |
0 updates can be installed immediately.
|
|
93 |
0 of these updates are security updates.
|
|
963
by Julian Andres Klode
We told people ESM is not enabled, but not how to enable it. |
94 |
|
95 |
Enable ESM to receive additional future security updates.
|
|
96 |
See 'ua enable esm' or https://ubuntu.com/esm
|
|
957.1.5
by Julian Andres Klode
Add changelog entry and test case |
97 |
""").lstrip()) |
98 |
||
99 |
def test_esm_enabled_nosecurity(self): |
|
100 |
self.assertEqual( |
|
101 |
get_message(upgrades=35, security_updates=0, |
|
102 |
esm_updates=13, have_esm=True, |
|
103 |
disabled_esm_updates=0), |
|
104 |
textwrap.dedent( |
|
105 |
"""
|
|
106 |
Extended Security Maintenance (ESM) is enabled.
|
|
107 |
||
108 |
35 updates can be installed immediately.
|
|
109 |
13 of these updates are provided through ESM.
|
|
110 |
0 of these updates are security updates.
|
|
111 |
""").lstrip()) |
|
112 |
||
113 |
def test_esm_enabled_somesecurity(self): |
|
114 |
self.assertEqual( |
|
115 |
get_message(upgrades=47, security_updates=7, |
|
116 |
esm_updates=13, have_esm=True, |
|
117 |
disabled_esm_updates=0), |
|
118 |
textwrap.dedent( |
|
119 |
"""
|
|
120 |
Extended Security Maintenance (ESM) is enabled.
|
|
121 |
||
122 |
47 updates can be installed immediately.
|
|
123 |
13 of these updates are provided through ESM.
|
|
124 |
7 of these updates are security updates.
|
|
125 |
""").lstrip()) |
|
126 |
||
127 |
def test_esm_enabled_noupdates(self): |
|
128 |
self.assertEqual( |
|
129 |
get_message(upgrades=0, security_updates=0, |
|
130 |
esm_updates=0, have_esm=True, |
|
131 |
disabled_esm_updates=0), |
|
132 |
textwrap.dedent( |
|
133 |
"""
|
|
134 |
Extended Security Maintenance (ESM) is enabled.
|
|
135 |
||
136 |
0 updates can be installed immediately.
|
|
137 |
0 of these updates are security updates.
|
|
138 |
""").lstrip()) |
|
139 |
||
140 |
||
141 |
if __name__ == "__main__": |
|
142 |
import logging |
|
143 |
logging.basicConfig(level=logging.DEBUG) |
|
144 |
unittest.main() |