示例#1
0
    def test_check_drive_invalid_path(self):
        root = '/srv/'
        with mock_check_drive() as mocks:
            drive = 'foo?bar'
            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_dir(root, drive)
            self.assertEqual(str(exc_mgr.exception),
                             '%s is not a valid drive name' % drive)

            drive = 'foo bar'
            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_mount(root, drive)
            self.assertEqual(str(exc_mgr.exception),
                             '%s is not a valid drive name' % drive)

            drive = 'foo/bar'
            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_drive(root, drive, True)
            self.assertEqual(str(exc_mgr.exception),
                             '%s is not a valid drive name' % drive)

            drive = 'foo%bar'
            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_drive(root, drive, False)
            self.assertEqual(str(exc_mgr.exception),
                             '%s is not a valid drive name' % drive)
        self.assertEqual([], mocks['isdir'].call_args_list)
        self.assertEqual([], mocks['ismount'].call_args_list)
示例#2
0
    def test_check_drive_ismount(self):
        root = '/srv'
        path = 'sdb1'
        with mock_check_drive(ismount=True) as mocks:
            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_dir(root, path)
            self.assertEqual(str(exc_mgr.exception),
                             '/srv/sdb1 is not a directory')

            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_drive(root, path, False)
            self.assertEqual(str(exc_mgr.exception),
                             '/srv/sdb1 is not a directory')

            self.assertEqual([mock.call('/srv/sdb1'),
                              mock.call('/srv/sdb1')],
                             mocks['isdir'].call_args_list)
            self.assertEqual([], mocks['ismount'].call_args_list)

        with mock_check_drive(ismount=True) as mocks:
            self.assertEqual('/srv/sdb1', constraints.check_mount(root, path))
            self.assertEqual('/srv/sdb1',
                             constraints.check_drive(root, path, True))
            self.assertEqual([], mocks['isdir'].call_args_list)
            self.assertEqual([mock.call('/srv/sdb1'),
                              mock.call('/srv/sdb1')],
                             mocks['ismount'].call_args_list)
示例#3
0
    def test_check_drive_ismount(self):
        root = '/srv'
        path = 'sdb1'
        with mock_check_drive(ismount=True) as mocks:
            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_dir(root, path)
            self.assertEqual(str(exc_mgr.exception),
                             '/srv/sdb1 is not a directory')

            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_drive(root, path, False)
            self.assertEqual(str(exc_mgr.exception),
                             '/srv/sdb1 is not a directory')

            self.assertEqual([mock.call('/srv/sdb1'), mock.call('/srv/sdb1')],
                             mocks['isdir'].call_args_list)
            self.assertEqual([], mocks['ismount'].call_args_list)

        with mock_check_drive(ismount=True) as mocks:
            self.assertEqual('/srv/sdb1', constraints.check_mount(root, path))
            self.assertEqual('/srv/sdb1', constraints.check_drive(
                root, path, True))
            self.assertEqual([], mocks['isdir'].call_args_list)
            self.assertEqual([mock.call('/srv/sdb1'), mock.call('/srv/sdb1')],
                             mocks['ismount'].call_args_list)
示例#4
0
    def test_check_drive_invalid_path(self):
        root = '/srv/'
        with mock_check_drive() as mocks:
            drive = 'foo?bar'
            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_dir(root, drive)
            self.assertEqual(str(exc_mgr.exception),
                             '%s is not a valid drive name' % drive)

            drive = 'foo bar'
            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_mount(root, drive)
            self.assertEqual(str(exc_mgr.exception),
                             '%s is not a valid drive name' % drive)

            drive = 'foo/bar'
            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_drive(root, drive, True)
            self.assertEqual(str(exc_mgr.exception),
                             '%s is not a valid drive name' % drive)

            drive = 'foo%bar'
            with self.assertRaises(ValueError) as exc_mgr:
                constraints.check_drive(root, drive, False)
            self.assertEqual(str(exc_mgr.exception),
                             '%s is not a valid drive name' % drive)
        self.assertEqual([], mocks['isdir'].call_args_list)
        self.assertEqual([], mocks['ismount'].call_args_list)
示例#5
0
 def test_check_drive_invalid_path(self):
     root = '/srv/'
     with mock_check_drive() as mocks:
         self.assertIsNone(constraints.check_dir(root, 'foo?bar'))
         self.assertIsNone(constraints.check_mount(root, 'foo bar'))
         self.assertIsNone(constraints.check_drive(root, 'foo/bar', True))
         self.assertIsNone(constraints.check_drive(root, 'foo%bar', False))
     self.assertEqual([], mocks['isdir'].call_args_list)
     self.assertEqual([], mocks['ismount'].call_args_list)
示例#6
0
 def test_check_drive_invalid_path(self):
     root = '/srv/'
     with mock_check_drive() as mocks:
         self.assertIsNone(constraints.check_dir(root, 'foo?bar'))
         self.assertIsNone(constraints.check_mount(root, 'foo bar'))
         self.assertIsNone(constraints.check_drive(root, 'foo/bar', True))
         self.assertIsNone(constraints.check_drive(root, 'foo%bar', False))
     self.assertEqual([], mocks['isdir'].call_args_list)
     self.assertEqual([], mocks['ismount'].call_args_list)
示例#7
0
 def test_check_drive_isdir(self):
     root = '/srv'
     path = 'sdb2'
     with mock_check_drive(isdir=True) as mocks:
         self.assertEqual('/srv/sdb2', constraints.check_dir(root, path))
         self.assertEqual('/srv/sdb2', constraints.check_drive(
             root, path, False))
         self.assertEqual([mock.call('/srv/sdb2'), mock.call('/srv/sdb2')],
                          mocks['isdir'].call_args_list)
         self.assertEqual([], mocks['ismount'].call_args_list)
     with mock_check_drive(isdir=True) as mocks:
         self.assertIsNone(constraints.check_mount(root, path))
         self.assertIsNone(constraints.check_drive(root, path, True))
         self.assertEqual([], mocks['isdir'].call_args_list)
         self.assertEqual([mock.call('/srv/sdb2'), mock.call('/srv/sdb2')],
                          mocks['ismount'].call_args_list)
示例#8
0
 def test_check_drive_isdir(self):
     root = '/srv'
     path = 'sdb2'
     with mock_check_drive(isdir=True) as mocks:
         self.assertEqual('/srv/sdb2', constraints.check_dir(root, path))
         self.assertEqual('/srv/sdb2',
                          constraints.check_drive(root, path, False))
         self.assertEqual([mock.call('/srv/sdb2'),
                           mock.call('/srv/sdb2')],
                          mocks['isdir'].call_args_list)
         self.assertEqual([], mocks['ismount'].call_args_list)
     with mock_check_drive(isdir=True) as mocks:
         self.assertIsNone(constraints.check_mount(root, path))
         self.assertIsNone(constraints.check_drive(root, path, True))
         self.assertEqual([], mocks['isdir'].call_args_list)
         self.assertEqual([mock.call('/srv/sdb2'),
                           mock.call('/srv/sdb2')],
                          mocks['ismount'].call_args_list)
示例#9
0
 def test_check_dir(self):
     self.assertFalse(constraints.check_dir('', ''))
     with mock.patch("os.path.isdir", MockTrue()):
         self.assertTrue(constraints.check_dir('/srv', 'foo/bar'))
示例#10
0
 def test_check_dir(self):
     self.assertFalse(constraints.check_dir('', ''))
     with mock.patch("os.path.isdir", MockTrue()):
         self.assertTrue(constraints.check_dir('/srv', 'foo/bar'))
示例#11
0
 def test_check_dir(self):
     self.assertFalse(constraints.check_dir("", ""))
     with mock.patch("os.path.isdir", MockTrue()):
         self.assertTrue(constraints.check_dir("/srv", "foo/bar"))