~jamesodhunt/ubuntu/wily/ubuntu-core-upgrader/call-upgrader-directly

« back to all changes in this revision

Viewing changes to ubuntucoreupgrader/tests/test_upgrader.py

mergedĀ lp:~jamesodhunt/ubuntu/vivid/ubuntu-core-upgrader/implement-format-command

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import tarfile
28
28
import tempfile
29
29
import unittest
 
30
from unittest.mock import patch
30
31
import os
31
32
import shutil
32
33
import sys
242
243
 
243
244
        shutil.rmtree(root_dir)
244
245
 
 
246
    @patch('ubuntucoreupgrader.upgrader.get_mount_details')
 
247
    @patch('ubuntucoreupgrader.upgrader.mount')
 
248
    @patch('ubuntucoreupgrader.upgrader.unmount')
 
249
    def test_no_format_in_cmd(self, mock_umount, mock_mount,
 
250
                              mock_mount_details):
 
251
 
 
252
        # If the command file does not contain the format command, mkfs
 
253
        # should not be called.
 
254
        with patch('ubuntucoreupgrader.upgrader.mkfs') as mock_mkfs:
 
255
            args = ['cmdfile']
 
256
            options = parse_args(args=args)
 
257
            commands = make_commands([self.TARFILE])
 
258
            upgrader = Upgrader(options, commands, [])
 
259
            upgrader.TIMESTAMP_FILE = '/dev/null'
 
260
            upgrader.MOUNTPOINT_CMD = "true"
 
261
            upgrader.run()
 
262
 
 
263
        # No format command in command file, so should not have been
 
264
        # called.
 
265
        self.assertFalse(mock_mkfs.called)
 
266
 
 
267
    @patch('ubuntucoreupgrader.upgrader.get_mount_details')
 
268
    @patch('ubuntucoreupgrader.upgrader.mount')
 
269
    @patch('ubuntucoreupgrader.upgrader.unmount')
 
270
    def test_format(self, mock_umount, mock_mount, mock_mount_details):
 
271
        MOCK_FS_TUPLE = ("device", "fstype", "label")
 
272
        mock_mount_details.return_value = MOCK_FS_TUPLE
 
273
 
 
274
        # mkfs should be called if the format command is specified in
 
275
        # the command file.
 
276
        with patch('ubuntucoreupgrader.upgrader.mkfs') as mock_mkfs:
 
277
            args = ['cmdfile']
 
278
            options = parse_args(args=args)
 
279
            commands = make_commands([self.TARFILE])
 
280
 
 
281
            # add format command to command file
 
282
            commands.insert(0, 'format system')
 
283
 
 
284
            upgrader = Upgrader(options, commands, [])
 
285
            upgrader.TIMESTAMP_FILE = '/dev/null'
 
286
            upgrader.MOUNTPOINT_CMD = "true"
 
287
            upgrader.run()
 
288
 
 
289
        mock_mkfs.assert_called_with(*MOCK_FS_TUPLE)
245
290
 
246
291
if __name__ == "__main__":
247
292
    unittest.main()