コード例 #1
0
    def test_out_list_valid_array_complex(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(
            CommandResultItem([{
                'active': True,
                'id': '783yesdf'
            }, {
                'active': False,
                'id': '3hjnme32'
            }, {
                'active': False,
                'id': '23hiujbs'
            }]))
        self.assertEqual(
            util.normalize_newlines(self.io.getvalue()),
            util.normalize_newlines("""Active : True
Id     : 783yesdf

Active : False
Id     : 3hjnme32

Active : False
Id     : 23hiujbs


"""))
コード例 #2
0
 def test_out_table_bad_query(self):
     output_producer = OutputProducer(formatter=format_table, file=self.io)
     result_item = CommandResultItem([{'name': 'qwerty', 'id': '0b1f6472qwerty'},
                                      {'name': 'asdf', 'id': '0b1f6472asdf'}],
                                           simple_output_query='[*].{Name:name')
     with self.assertRaises(util.CLIError):
         output_producer.out(result_item)
コード例 #3
0
 def test_out_table_no_query(self):
     output_producer = OutputProducer(formatter=format_table, file=self.io)
     with self.assertRaises(util.CLIError):
         output_producer.out(
             CommandResultItem({
                 'active': True,
                 'id': '0b1f6472'
             }))
コード例 #4
0
    def test_out_list_valid_none_val(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(CommandResultItem({'active': None, 'id': '0b1f6472'}))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
"""Active : None
Id     : 0b1f6472


"""))
コード例 #5
0
    def test_out_json_byte_empty(self):
        output_producer = OutputProducer(formatter=format_json, file=self.io)
        output_producer.out(CommandResultItem({'active': True, 'contents': b''}))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
"""{
  "active": true,
  "contents": ""
}
"""))
コード例 #6
0
 def test_out_table_complex_obj(self):
     output_producer = OutputProducer(formatter=format_table, file=self.io)
     result_item = CommandResultItem([{
         'name': 'qwerty',
         'id': '0b1f6472qwerty',
         'sub': {'1'}
     }])
     with self.assertRaises(util.CLIError):
         output_producer.out(result_item)
コード例 #7
0
    def test_out_table_complex_obj_with_query_ok(self):
        output_producer = OutputProducer(formatter=format_table, file=self.io)
        result_item = CommandResultItem([{'name': 'qwerty', 'id': '0b1f6472qwerty', 'sub': {'1'}}],
                                        simple_output_query='[*].{Name:name}')
        output_producer.out(result_item)
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
""" Name 
------
qwerty
"""))
コード例 #8
0
 def test_out_table_complex_obj_with_query_still_complex(self):
     output_producer = OutputProducer(formatter=format_table, file=self.io)
     result_item = CommandResultItem(
         [{
             'name': 'qwerty',
             'id': '0b1f6472qwerty',
             'sub': {'1'}
         }],
         simple_output_query='[*].{Name:name, Sub:sub}')
     with self.assertRaises(util.CLIError):
         output_producer.out(result_item)
コード例 #9
0
 def test_out_table_bad_query(self):
     output_producer = OutputProducer(formatter=format_table, file=self.io)
     result_item = CommandResultItem([{
         'name': 'qwerty',
         'id': '0b1f6472qwerty'
     }, {
         'name': 'asdf',
         'id': '0b1f6472asdf'
     }],
                                     simple_output_query='[*].{Name:name')
     with self.assertRaises(util.CLIError):
         output_producer.out(result_item)
コード例 #10
0
    def test_out_table_valid_query2(self):
        output_producer = OutputProducer(formatter=format_table, file=self.io)
        result_item = CommandResultItem([{'name': 'qwerty', 'id': '0b1f6472qwerty'},
                                         {'name': 'asdf', 'id': '0b1f6472asdf'}],
                                              simple_output_query='[*].{Name:name}')
        output_producer.out(result_item)
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
""" Name 
------
qwerty
asdf  
"""))
コード例 #11
0
    def test_out_json_valid(self):
        """
        The JSON output when the input is a dict should be the dict serialized to JSON
        """
        output_producer = OutputProducer(formatter=format_json, file=self.io)
        output_producer.out(CommandResultItem({'active': True, 'id': '0b1f6472'}))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
"""{
  "active": true,
  "id": "0b1f6472"
}
"""))
コード例 #12
0
    def test_out_list_valid_none_val(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(
            CommandResultItem({
                'active': None,
                'id': '0b1f6472'
            }))
        self.assertEqual(
            util.normalize_newlines(self.io.getvalue()),
            util.normalize_newlines("""Active : None
Id     : 0b1f6472


"""))
コード例 #13
0
    def test_out_list_valid_str_array(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(CommandResultItem(['location', 'id', 'host', 'server']))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
"""location

id

host

server


"""))
コード例 #14
0
    def test_out_table_complex_obj_with_query_ok(self):
        output_producer = OutputProducer(formatter=format_table, file=self.io)
        result_item = CommandResultItem([{
            'name': 'qwerty',
            'id': '0b1f6472qwerty',
            'sub': {'1'}
        }],
                                        simple_output_query='[*].{Name:name}')
        output_producer.out(result_item)
        self.assertEqual(util.normalize_newlines(self.io.getvalue()),
                         util.normalize_newlines(""" Name 
------
qwerty
"""))
コード例 #15
0
    def test_out_json_byte_empty(self):
        output_producer = OutputProducer(formatter=format_json, file=self.io)
        output_producer.out(
            CommandResultItem({
                'active': True,
                'contents': b''
            }))
        self.assertEqual(
            util.normalize_newlines(self.io.getvalue()),
            util.normalize_newlines("""{
  "active": true,
  "contents": ""
}
"""))
コード例 #16
0
    def test_out_list_valid_complex_array(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(CommandResultItem({'active': True, 'id': '0b1f6472',
                                        'myarray': ['1', '2', '3', '4']}))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
"""Active  : True
Id      : 0b1f6472
Myarray :
   1
   2
   3
   4


"""))
コード例 #17
0
    def test_out_list_valid_str_array(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(
            CommandResultItem(['location', 'id', 'host', 'server']))
        self.assertEqual(
            util.normalize_newlines(self.io.getvalue()),
            util.normalize_newlines("""location

id

host

server


"""))
コード例 #18
0
    def test_out_json_valid(self):
        """
        The JSON output when the input is a dict should be the dict serialized to JSON
        """
        output_producer = OutputProducer(formatter=format_json, file=self.io)
        output_producer.out(
            CommandResultItem({
                'active': True,
                'id': '0b1f6472'
            }))
        self.assertEqual(
            util.normalize_newlines(self.io.getvalue()),
            util.normalize_newlines("""{
  "active": true,
  "id": "0b1f6472"
}
"""))
コード例 #19
0
    def test_out_list_valid_array_complex(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(CommandResultItem([
                             {'active': True, 'id': '783yesdf'},
                             {'active': False, 'id': '3hjnme32'},
                             {'active': False, 'id': '23hiujbs'}]))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
"""Active : True
Id     : 783yesdf

Active : False
Id     : 3hjnme32

Active : False
Id     : 23hiujbs


"""))
コード例 #20
0
    def test_out_table_valid_query2(self):
        output_producer = OutputProducer(formatter=format_table, file=self.io)
        result_item = CommandResultItem([{
            'name': 'qwerty',
            'id': '0b1f6472qwerty'
        }, {
            'name': 'asdf',
            'id': '0b1f6472asdf'
        }],
                                        simple_output_query='[*].{Name:name}')
        output_producer.out(result_item)
        self.assertEqual(
            util.normalize_newlines(self.io.getvalue()),
            util.normalize_newlines(""" Name 
------
qwerty
asdf  
"""))
コード例 #21
0
    def test_out_list_valid_complex_array(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(
            CommandResultItem({
                'active': True,
                'id': '0b1f6472',
                'myarray': ['1', '2', '3', '4']
            }))
        self.assertEqual(
            util.normalize_newlines(self.io.getvalue()),
            util.normalize_newlines("""Active  : True
Id      : 0b1f6472
Myarray :
   1
   2
   3
   4


"""))
コード例 #22
0
 def test_out_table_complex_obj(self):
     output_producer = OutputProducer(formatter=format_table, file=self.io)
     result_item = CommandResultItem([{'name': 'qwerty', 'id': '0b1f6472qwerty', 'sub': {'1'}}])
     with self.assertRaises(util.CLIError):
         output_producer.out(result_item)
コード例 #23
0
 def test_out_table_no_query(self):
     output_producer = OutputProducer(formatter=format_table, file=self.io)
     with self.assertRaises(util.CLIError):
         output_producer.out(CommandResultItem({'active': True, 'id': '0b1f6472'}))
コード例 #24
0
 def test_out_boolean_valid(self):
     output_producer = OutputProducer(formatter=format_list, file=self.io)
     output_producer.out(CommandResultItem(True))
     self.assertEqual(util.normalize_newlines(self.io.getvalue()),
                      util.normalize_newlines("""True\n\n\n"""))
コード例 #25
0
 def test_out_table_complex_obj_with_query_still_complex(self):
     output_producer = OutputProducer(formatter=format_table, file=self.io)
     result_item = CommandResultItem([{'name': 'qwerty', 'id': '0b1f6472qwerty', 'sub': {'1'}}],
                                     simple_output_query='[*].{Name:name, Sub:sub}')
     with self.assertRaises(util.CLIError):
         output_producer.out(result_item)
コード例 #26
0
 def test_out_boolean_valid(self):
     output_producer = OutputProducer(formatter=format_list, file=self.io)
     output_producer.out(CommandResultItem(True))
     self.assertEqual(util.normalize_newlines(self.io.getvalue()),
                      util.normalize_newlines("""True\n\n\n"""))