def test_remove_error_conditions(self):
        """fileops:Remove verify error conditions"""

        # missing "path"
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'Remove',
        }

        with self.assertRaises(TypeError):
            fileops._parse_ChangeOwnership(params, self.app_logger)
    def test_change_ownership_error_conditions(self):
        """fileops:ChangeOwnership verify error conditions"""

        # path as a list
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'ChangeOwnership',
            'to': '/tmp/file',
            'user': '******',
            'group': 'group',
            'path': ['/a/path/to/file'],
        }

        with self.assertRaises(TypeError):
            fileops._parse_ChangeOwnership(params, self.app_logger)

        # missing "user"
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'ChangeOwnership',
            'to': '/tmp/file',
            'group': 'group',
            'path': '/a/path/to/file',
        }

        with self.assertRaises(TypeError):
            fileops._parse_ChangeOwnership(params, self.app_logger)

        # missing "group"
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'ChangeOwnership',
            'to': '/tmp/file',
            'user': '******',
            'path': '/a/path/to/file',
        }

        with self.assertRaises(TypeError):
            fileops._parse_ChangeOwnership(params, self.app_logger)

        # missing path
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'ChangeOwnership',
            'to': '/tmp/file',
            'user': '******',
            'group': 'group',
        }

        with self.assertRaises(TypeError):
            fileops._parse_ChangeOwnership(params, self.app_logger)
 def test_change_ownership(self):
     """fileops:ChangeOwnership with params parses correctly"""
     expected = ['chown user.group /tmp/file']
     params = {
         'hosts': ['testhost.example.com'],
         'command': 'fileops',
         'subcommand': 'ChangeOwnership',
         'path': '/tmp/file',
         'user': '******',
         'group': 'group'
     }
     (update, cmd) = fileops._parse_ChangeOwnership(params, self.app_logger)
     self.assertEqual(cmd, expected)
    def test_find_in_files_error_conditions(self):
        """fileops:FindInFiles verify error conditions"""

        # missing "path"
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'ChangeOwnership',
            'regexp': 'test',
        }

        with self.assertRaises(TypeError):
            fileops._parse_ChangeOwnership(params, self.app_logger)

        # missing "regexp"
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'ChangeOwnership',
            'path': '/tmp/file',
        }

        with self.assertRaises(TypeError):
            fileops._parse_ChangeOwnership(params, self.app_logger)
    def test_change_permissions_error_conditions(self):
        """fileops:ChangePermissions verify error conditions"""

        # Missing "path"
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'ChangePermissions',
            'mode': '0644',
        }

        with self.assertRaises(TypeError):
            fileops._parse_ChangePermissions(params, self.app_logger)

        # Missing "mode"
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'ChangePermissions',
            'path': '/a/path/to/file',
        }

        with self.assertRaises(TypeError):
            fileops._parse_ChangeOwnership(params, self.app_logger)