salt/tests/integration/output/output.py

114 lines
3.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Nicole Thomas <nicole@saltstack.com>`
'''
# Import Salt Libs
from __future__ import absolute_import
2014-10-11 16:37:24 +00:00
import os
import traceback
# Import Salt Testing Libs
from salttesting.helpers import ensure_in_syspath
2015-08-27 19:46:29 +00:00
from salttesting.mixins import RUNTIME_VARS
ensure_in_syspath('../../')
# Import Salt libs
import integration
import salt.config
2015-02-25 09:50:53 +00:00
from salt.output import display_output
2015-08-27 19:46:29 +00:00
import salt.config
class OutputReturnTest(integration.ShellCase):
'''
Integration tests to ensure outputters return their expected format.
Tests against situations where the loader might not be returning the
right outputter even though it was explicitly requested.
'''
def test_output_json(self):
'''
Tests the return of json-formatted data
'''
ret = self.run_call('test.ping --out=json')
self.assertIn('{', ret)
self.assertIn('"local": true', ''.join(ret))
self.assertIn('}', ''.join(ret))
def test_output_nested(self):
'''
Tests the return of nested-formatted data
'''
expected = ['local:', ' True']
ret = self.run_call('test.ping --out=nested')
self.assertEqual(ret, expected)
def test_output_quiet(self):
'''
Tests the return of an out=quiet query
'''
expected = []
ret = self.run_call('test.ping --out=quiet')
self.assertEqual(ret, expected)
def test_output_pprint(self):
'''
Tests the return of pprint-formatted data
'''
expected = ["{'local': True}"]
ret = self.run_call('test.ping --out=pprint')
self.assertEqual(ret, expected)
def test_output_raw(self):
'''
Tests the return of raw-formatted data
'''
expected = ["{'local': True}"]
ret = self.run_call('test.ping --out=raw')
self.assertEqual(ret, expected)
def test_output_txt(self):
'''
Tests the return of txt-formatted data
'''
expected = ['local: True']
ret = self.run_call('test.ping --out=txt')
self.assertEqual(ret, expected)
def test_output_yaml(self):
'''
Tests the return of yaml-formatted data
'''
expected = ['local: true']
ret = self.run_call('test.ping --out=yaml')
self.assertEqual(ret, expected)
2014-10-11 16:37:24 +00:00
def test_output_unicodebad(self):
'''
Tests outputter reliability with utf8
'''
opts = salt.config.minion_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'minion'))
2014-10-11 16:37:24 +00:00
opts['output_file'] = os.path.join(
integration.SYS_TMP_DIR,
'salt-tests-tmpdir',
'outputtest'
)
2014-10-11 16:37:24 +00:00
data = {'foo': {'result': False,
'aaa': 'azerzaeréééé',
'comment': u'ééééàààà'}}
try:
# this should not raises UnicodeEncodeError
display_output(data, opts=opts)
2014-10-11 16:37:24 +00:00
self.assertTrue(True)
2014-10-12 10:15:58 +00:00
except Exception:
2014-10-12 09:37:17 +00:00
# display trace in error message for debugging on jenkins
2014-10-12 10:15:58 +00:00
trace = traceback.format_exc()
2014-10-12 09:37:17 +00:00
self.assertEqual(trace, '')
2014-10-11 16:37:24 +00:00
if __name__ == '__main__':
from integration import run_tests
run_tests(OutputReturnTest)