Ejemplo n.º 1
0
    def test_disk_get_specified_filesystems(self):
        """Tests `Disk._get_specified_filesystems`."""
        # This minimal `_disk_dict` contains everything this method touches.
        self.disk_instance_mock._disk_dict = {  # pylint: disable=protected-access
            '/very/good/mountpoint': {
                'device_path': '/dev/sda1'
            },
            '/mounted/here/too': {
                'device_path': '/dev/sda1'
            },
            '/less/good/mountpoint': {
                'device_path': '/dev/sda2'
            },
            '/a/samba/share': {
                'device_path': '//server.local/cool_share'
            }
        }

        with self.subTest('Get all filesystems with mount points.'):
            # pylint: disable=protected-access
            self.assertDictEqual(
                Disk._get_specified_filesystems(
                    self.disk_instance_mock,
                    self.disk_instance_mock._disk_dict  # recall dicts are iterables of their keys.
                ),
                self.disk_instance_mock._disk_dict
            )
            # pylint: enable=protected-access

        with self.subTest('Get only `/dev/sda1` filesystems.'):
            self.assertDictEqual(
                Disk._get_specified_filesystems(  # pylint: disable=protected-access
                    self.disk_instance_mock,
                    ('/dev/sda1',)
                ),
                {
                    '/very/good/mountpoint': {
                        'device_path': '/dev/sda1'
                    }
                }
            )
Ejemplo n.º 2
0
    def test_disk_get_specified_filesystems(self):
        """Tests `Disk._get_specified_filesystems`."""
        # This minimal `_disk_dict` contains everything this method touches.
        self.disk_instance_mock._disk_dict = {  # pylint: disable=protected-access
            '/very/good/mountpoint': {
                'device_path': '/dev/sda1'
            },
            '/mounted/here/too': {
                'device_path': '/dev/sda1'
            },
            '/less/good/mountpoint': {
                'device_path': '/dev/sda2'
            },
            '/a/samba/share': {
                'device_path': '//server.local/cool_share'
            }
        }

        with self.subTest('Get all filesystems with mount points.'):
            # pylint: disable=protected-access
            self.assertDictEqual(
                Disk._get_specified_filesystems(
                    self.disk_instance_mock,
                    self.disk_instance_mock.
                    _disk_dict  # recall dicts are iterables of their keys.
                ),
                self.disk_instance_mock._disk_dict)
            # pylint: enable=protected-access

        with self.subTest('Get only `/dev/sda1` filesystems.'):
            result_disk_dict = Disk._get_specified_filesystems(  # pylint: disable=protected-access
                self.disk_instance_mock, ('/dev/sda1', ))

            # With Python < 3.6, dict ordering isn't guaranteed,
            # so we don't know which disk will be selected.
            self.assertEqual(len(result_disk_dict), 1)
            # As long as `device_path` is also correct, this passes.
            self.assertEqual(
                result_disk_dict[list(
                    result_disk_dict.keys())[0]]['device_path'], '/dev/sda1')