nagios-http-json/test/test_main.py

45 lines
1010 B
Python
Raw Normal View History

2020-03-15 10:53:00 +01:00
#!/usr/bin/env python3
import unittest
import unittest.mock as mock
import sys
2020-03-15 11:04:50 +01:00
import os
2020-03-15 10:53:00 +01:00
sys.path.append('..')
from check_http_json import debugPrint
class MainTest(unittest.TestCase):
"""
Tests for main
"""
2020-03-15 11:04:50 +01:00
def setUp(self):
"""
Defining the exitcodes
"""
self.exit_0 = 0 << 8
self.exit_1 = 1 << 8
self.exit_2 = 2 << 8
self.exit_3 = 3 << 8
2020-03-15 10:53:00 +01:00
def test_debugprint(self):
with mock.patch('builtins.print') as mock_print:
debugPrint(True, 'debug')
mock_print.assert_called_once_with('debug')
def test_debugprint_pprint(self):
with mock.patch('check_http_json.pprint') as mock_pprint:
debugPrint(True, 'debug', True)
mock_pprint.assert_called_once_with('debug')
2020-03-15 11:04:50 +01:00
def test_cli_without_params(self):
command = '/usr/bin/env python3 check_http_json.py > /dev/null 2>&1'
status = os.system(command)
self.assertEqual(status, self.exit_2)