Debian Codegraph @

tests/test_customize.py

raw
1 # vim: set ft=python ts=4 sw=4 expandtab:
2 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
3 #
4 # C E D A R
5 # S O L U T I O N S "Software done right."
6 # S O F T W A R E
7 #
8 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
9 #
10 # Copyright (c) 2010,2015 Kenneth J. Pronovici.
11 # All rights reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License,
15 # Version 2, as published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 #
21 # Copies of the GNU General Public License are available from
22 # the Free Software Foundation website, http://www.gnu.org/.
23 #
24 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
25 #
26 # Author : Kenneth J. Pronovici <[email protected]>
27 # Language : Python 3
28 # Project : Cedar Backup, release 3
29 # Purpose : Tests customization functionality.
30 #
31 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
32
33 ########################################################################
34 # Module documentation
35 ########################################################################
36
37 """
38 Unit tests for CedarBackup3/customize.py.
39 @author Kenneth J. Pronovici <[email protected]>
40 """
41
42
43 ########################################################################
44 # Import modules and do runtime validations
45 ########################################################################
46
47 import unittest
48
49 from CedarBackup3.config import CommandOverride, Config, OptionsConfig
50 from CedarBackup3.customize import PLATFORM, customizeOverrides
51 from CedarBackup3.testutil import configureLogging
52
53 #######################################################################
54 # Test Case Classes
55 #######################################################################
56
57 ######################
58 # TestFunctions class
59 ######################
60
61
62 class TestFunctions(unittest.TestCase):
63 """Tests for the various public functions."""
64
65 ################
66 # Setup methods
67 ################
68
69 @classmethod
70 def setUpClass(cls):
71 configureLogging()
72
73 ############################
74 # Test customizeOverrides()
75 ############################
76
77 def testCustomizeOverrides_001(self):
78 """
79 Test platform=standard, no existing overrides.
80 """
81 config = Config()
82 options = OptionsConfig()
83 if PLATFORM == "standard":
84 config.options = options
85 customizeOverrides(config)
86 self.assertEqual(None, options.overrides)
87 config.options = options
88 customizeOverrides(config, platform="standard")
89 self.assertEqual(None, options.overrides)
90
91 def testCustomizeOverrides_002(self):
92 """
93 Test platform=standard, existing override for cdrecord.
94 """
95 config = Config()
96 options = OptionsConfig()
97 options.overrides = [
98 CommandOverride("cdrecord", "/blech"),
99 ]
100 if PLATFORM == "standard":
101 config.options = options
102 customizeOverrides(config)
103 self.assertEqual([CommandOverride("cdrecord", "/blech")], options.overrides)
104 config.options = options
105 customizeOverrides(config, platform="standard")
106 self.assertEqual([CommandOverride("cdrecord", "/blech")], options.overrides)
107
108 def testCustomizeOverrides_003(self):
109 """
110 Test platform=standard, existing override for mkisofs.
111 """
112 config = Config()
113 options = OptionsConfig()
114 options.overrides = [
115 CommandOverride("mkisofs", "/blech"),
116 ]
117 if PLATFORM == "standard":
118 config.options = options
119 customizeOverrides(config)
120 self.assertEqual([CommandOverride("mkisofs", "/blech")], options.overrides)
121 config.options = options
122 customizeOverrides(config, platform="standard")
123 self.assertEqual([CommandOverride("mkisofs", "/blech")], options.overrides)
124
125 def testCustomizeOverrides_004(self):
126 """
127 Test platform=standard, existing override for cdrecord and mkisofs.
128 """
129 config = Config()
130 options = OptionsConfig()
131 options.overrides = [
132 CommandOverride("cdrecord", "/blech"),
133 CommandOverride("mkisofs", "/blech2"),
134 ]
135 if PLATFORM == "standard":
136 config.options = options
137 customizeOverrides(config)
138 self.assertEqual([CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2")], options.overrides)
139 config.options = options
140 customizeOverrides(config, platform="standard")
141 self.assertEqual([CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2")], options.overrides)
142
143 def testCustomizeOverrides_005(self):
144 """
145 Test platform=debian, no existing overrides.
146 """
147 config = Config()
148 options = OptionsConfig()
149 if PLATFORM == "debian":
150 config.options = options
151 customizeOverrides(config)
152 self.assertEqual(
153 [CommandOverride("cdrecord", "/usr/bin/wodim"), CommandOverride("mkisofs", "/usr/bin/genisoimage")],
154 options.overrides,
155 )
156 config.options = options
157 customizeOverrides(config, platform="debian")
158 self.assertEqual(
159 [CommandOverride("cdrecord", "/usr/bin/wodim"), CommandOverride("mkisofs", "/usr/bin/genisoimage")], options.overrides
160 )
161
162 def testCustomizeOverrides_006(self):
163 """
164 Test platform=debian, existing override for cdrecord.
165 """
166 config = Config()
167 options = OptionsConfig()
168 options.overrides = [
169 CommandOverride("cdrecord", "/blech"),
170 ]
171 if PLATFORM == "debian":
172 config.options = options
173 customizeOverrides(config)
174 self.assertEqual(
175 [CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/usr/bin/genisoimage")], options.overrides
176 )
177 config.options = options
178 customizeOverrides(config, platform="debian")
179 self.assertEqual(
180 [CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/usr/bin/genisoimage")], options.overrides
181 )
182
183 def testCustomizeOverrides_007(self):
184 """
185 Test platform=debian, existing override for mkisofs.
186 """
187 config = Config()
188 options = OptionsConfig()
189 options.overrides = [
190 CommandOverride("mkisofs", "/blech"),
191 ]
192 if PLATFORM == "debian":
193 config.options = options
194 customizeOverrides(config)
195 self.assertEqual(
196 [CommandOverride("cdrecord", "/usr/bin/wodim"), CommandOverride("mkisofs", "/blech")], options.overrides
197 )
198 config.options = options
199 customizeOverrides(config, platform="debian")
200 self.assertEqual([CommandOverride("cdrecord", "/usr/bin/wodim"), CommandOverride("mkisofs", "/blech")], options.overrides)
201
202 def testCustomizeOverrides_008(self):
203 """
204 Test platform=debian, existing override for cdrecord and mkisofs.
205 """
206 config = Config()
207 options = OptionsConfig()
208 options.overrides = [
209 CommandOverride("cdrecord", "/blech"),
210 CommandOverride("mkisofs", "/blech2"),
211 ]
212 if PLATFORM == "debian":
213 config.options = options
214 customizeOverrides(config)
215 self.assertEqual([CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2")], options.overrides)
216 config.options = options
217 customizeOverrides(config, platform="debian")
218 self.assertEqual([CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2")], options.overrides)