# Path: es_stats_zabbix/helpers/utils.py
# def open_port(host, port):
#     """Test whether a port is open at host.  Return boolean"""
#     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#     try:
#         sock.connect((host, port))
#         sock.shutdown(2)
#         return True
#     except:
#         return False
# 
# def status_map(state):
#     """Return a numeric value in place of the string value for state"""
#     if state == 'green':
#         retval = 0
#     elif state == 'yellow':
#         retval = 1
#     elif state == 'red':
#         retval = 2
#     else:
#         retval = 3 # fail
#     return retval


import socket
from unittest import TestCase
from es_stats_zabbix.helpers.utils import open_port, status_map
"""Unit tests for es_stats_zabbix/helpers/utils.py"""

class TestStatusMap(TestCase):
    """StatusMap test class"""
    def test_expected(self):
        """Test the Zabbix mapping of Elasticsearch health status"""
        status_dict = {
            'green': 0,
            'yellow': 1,
            'red': 2,
        }
        for k in list(status_dict.keys()):
            self.assertEqual(status_dict[k], status_map(k))
    def test_unexpected(self):
        """Test that a 3 is reported for anything not 'green', 'yellow', or 'red'"""

# Path: es_stats_zabbix/helpers/utils.py
# def open_port(host, port):
#     """Test whether a port is open at host.  Return boolean"""
#     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#     try:
#         sock.connect((host, port))
#         sock.shutdown(2)
#         return True
#     except:
#         return False
# 
# def status_map(state):
#     """Return a numeric value in place of the string value for state"""
#     if state == 'green':
#         retval = 0
#     elif state == 'yellow':
#         retval = 1
#     elif state == 'red':
#         retval = 2
#     else:
#         retval = 3 # fail
#     return retval


# Path: tests/unit/test_helpers_utils.py
import socket
from unittest import TestCase
from es_stats_zabbix.helpers.utils import open_port, status_map

"""Unit tests for es_stats_zabbix/helpers/utils.py"""

class TestStatusMap(TestCase):
    """StatusMap test class"""
    def test_expected(self):
        """Test the Zabbix mapping of Elasticsearch health status"""
        status_dict = {
            'green': 0,
            'yellow': 1,
            'red': 2,
        }
        for k in list(status_dict.keys()):
            self.assertEqual(status_dict[k], status_map(k))
    def test_unexpected(self):
        """Test that a 3 is reported for anything not 'green', 'yellow', or 'red'"""

        self.assertEqual(3, status_map('anything_else'))