def test_tar_single(self):
     """fileops:Tar with one location parses correctly"""
     expected = ['tar -c -f file.tar /a/path/to/file']
     params = {
         'hosts': ['testhost.example.com'],
         'command': 'fileops',
         'subcommand': 'Tar',
         'to': 'file.tar',
         'path': '/a/path/to/file'
     }
     (update, cmd) = fileops._parse_Tar(params, self.app_logger)
     self.assertEqual(cmd, expected)
 def test_tar_multiple(self):
     """fileops:Tar verify tar with multiple locations"""
     expected = ['tar -c -z -f file.tar.gz /a/path/to/file /and/this']
     params = {
         'hosts': ['testhost.example.com'],
         'command': 'fileops',
         'subcommand': 'Touch',
         'to': 'file.tar.gz',
         'compression': 'gzip',
         'path': ['/a/path/to/file', '/and/this']
     }
     (update, cmd) = fileops._parse_Tar(params, self.app_logger)
     self.assertEqual(cmd, expected)
    def test_tar_error_conditions(self):
        """fileops:Tar verify error conditions"""
        # bad compression
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'Touch',
            'to': 'file.tar.gz',
            'compression': 'failure',
            'path': ['/a/path/to/file', '/and/this']
        }

        with self.assertRaises(TypeError):
            fileops._parse_Tar(params, self.app_logger)
            
        # missing "to"
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'Touch',
            'compression': 'gzip',
            'path': ['/a/path/to/file', '/and/this']
        }

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

        # missing "path"
        params = {
            'hosts': ['testhost.example.com'],
            'command': 'fileops',
            'subcommand': 'Touch',
            'to': 'file.tar.gz',
            'compression': 'gzip'
        }

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