# Path: zabby/core/exceptions.py
# class WrongArgumentError(Exception):
#     """ Wrong argument was passed to a function"""
# 
# Path: zabby/core/six.py
# def b(s):
#     return s.encode('utf-8')
# 
# Path: zabby/items/net/tcp.py
# LOG = logging.getLogger(__name__)
# SERVICES = {
#     'ssh': 22,
# }
# def service(service_name, ip='127.0.0.1', port=None, timeout=1.0):
# def _check_ssh(ip, port, timeout):


from mock import patch
from nose.tools import assert_true, assert_false, assert_raises
from zabby.core.exceptions import WrongArgumentError
from zabby.core.six import b
from zabby.items.net import tcp



class TestServiceSSH():
    def setup(self):
        self._patcher_tcp_communication = patch(
            'zabby.items.net.tcp.tcp_communication')
        self.mock_tcp_communication = self._patcher_tcp_communication.start()

        self.service_name = 'ssh'

    def teardown(self):
        self._patcher_tcp_communication.stop()

    def test_running_if_server_message_matches_expectations(self):
        self.mock_tcp_communication.return_value = [
            b('SSH-2.0-OpenSSH_6.0p1 Debian-4\n')]
        running = bool(tcp.service(self.service_name))
        assert_true(running)

    def test_not_running_if_server_message_does_not_match_expectations(self):

# Path: zabby/core/exceptions.py
# class WrongArgumentError(Exception):
#     """ Wrong argument was passed to a function"""
# 
# Path: zabby/core/six.py
# def b(s):
#     return s.encode('utf-8')
# 
# Path: zabby/items/net/tcp.py
# LOG = logging.getLogger(__name__)
# SERVICES = {
#     'ssh': 22,
# }
# def service(service_name, ip='127.0.0.1', port=None, timeout=1.0):
# def _check_ssh(ip, port, timeout):


# Path: zabby/tests/items/net/test_tcp.py
from mock import patch
from nose.tools import assert_true, assert_false, assert_raises
from zabby.core.exceptions import WrongArgumentError
from zabby.core.six import b
from zabby.items.net import tcp




class TestServiceSSH():
    def setup(self):
        self._patcher_tcp_communication = patch(
            'zabby.items.net.tcp.tcp_communication')
        self.mock_tcp_communication = self._patcher_tcp_communication.start()

        self.service_name = 'ssh'

    def teardown(self):
        self._patcher_tcp_communication.stop()

    def test_running_if_server_message_matches_expectations(self):
        self.mock_tcp_communication.return_value = [
            b('SSH-2.0-OpenSSH_6.0p1 Debian-4\n')]
        running = bool(tcp.service(self.service_name))
        assert_true(running)

    def test_not_running_if_server_message_does_not_match_expectations(self):

        self.mock_tcp_communication.return_value = [b('SSH\n')]