# Path: cloudify_agent/installer/runners/winrm_runner.py
# DEFAULT_WINRM_PORT = '5985'
# DEFAULT_WINRM_URI = 'wsman'
# DEFAULT_WINRM_PROTOCOL = 'http'
# DEFAULT_TRANSPORT = 'basic'
# def validate(session_config):
#     def _validate(prop):
#     def __init__(self,
#                  user,
#                  password=None,
#                  protocol=None,
#                  host=None,
#                  port=None,
#                  uri=None,
#                  transport=None,
#                  validate_connection=True,
#                  logger=None,
#                  tmpdir=None):
#     def validate_connection(self):
#     def _create_session(self):
#     def run(self, command, raise_on_failure=True, execution_env=None,
#             powershell=False):
#         def _chk(res):
#     def ping(self):
#     def delete(self, path, ignore_missing=False):
#     def mktemp(self):
#     def get_temp_dir(self):
#     def new_dir(self, path):
#     def machine_distribution(self):
#     def python(self, imports_line, command):
#     def put(self, contents, path):
#     def put_file(self, src, dst=None):
#     def close(self):
#     def run_script(self, script_path):
# def split_into_chunks(contents, max_size=2000, separator='\r\n'):
#     def join_lines(lines, line):
# class WinRMRunner(object):
# class WinRMCommandExecutionError(CommandExecutionError):
# class WinRMCommandExecutionException(CommandExecutionException):
# class WinRMCommandExecutionResponse(CommandExecutionResponse):
# 
# Path: cloudify_agent/installer/runners/winrm_runner.py
# def split_into_chunks(contents, max_size=2000, separator='\r\n'):
#     """Split content into chunks to avoid command line too long error.
# 
#     Maximum allowed commmand line length should be 2047 in old windows:
#     https://support.microsoft.com/en-us/help/830473/command-prompt-cmd--exe-command-line-string-limitation
# 
#     :param contents:
#         The contents of a file that exceeds the maximum command line length in
#         windows.
#     :type content: str
#     :returns: The same content in chunks that won't exceed the limit
#     :rtype: list[str]
# 
#     """
#     def join_lines(lines, line):
#         if len(line) > max_size:
#             raise ValueError('Line too long (%d characters)' % len(line))
# 
#         if (
#             lines and
#             len(lines[-1]) + len(line) + len(separator) <= max_size
#         ):
#             lines[-1] += '{0}{1}'.format(separator, line)
#         else:
#             lines.append(line)
#         return lines
# 
#     if contents:
#         chunks = reduce(join_lines, contents.splitlines(), [])
#     else:
#         chunks = ['']
#     return chunks


import pytest
from cloudify_agent.installer.runners import winrm_runner
from cloudify_agent.installer.runners.winrm_runner import split_into_chunks


##############################################################################
# note that this file only tests validation and defaults of the winrm runner.
# it does not test the actual functionality because that requires starting
# a vm. functional tests are executed as local workflow tests in the system
# tests framework
##############################################################################


def test_validate_host():
    # Missing host
    session_config = {
        'user': 'test_user',
        'password': 'test_password'
    }
    with pytest.raises(ValueError, match='.*Invalid host.*'):
        winrm_runner.validate(session_config)


def test_validate_user():
    # Missing user
    session_config = {
        'host': 'test_host',
        'password': 'test_password'
    }
    with pytest.raises(ValueError, match='.*Invalid user.*'):

# Path: cloudify_agent/installer/runners/winrm_runner.py
# DEFAULT_WINRM_PORT = '5985'
# DEFAULT_WINRM_URI = 'wsman'
# DEFAULT_WINRM_PROTOCOL = 'http'
# DEFAULT_TRANSPORT = 'basic'
# def validate(session_config):
#     def _validate(prop):
#     def __init__(self,
#                  user,
#                  password=None,
#                  protocol=None,
#                  host=None,
#                  port=None,
#                  uri=None,
#                  transport=None,
#                  validate_connection=True,
#                  logger=None,
#                  tmpdir=None):
#     def validate_connection(self):
#     def _create_session(self):
#     def run(self, command, raise_on_failure=True, execution_env=None,
#             powershell=False):
#         def _chk(res):
#     def ping(self):
#     def delete(self, path, ignore_missing=False):
#     def mktemp(self):
#     def get_temp_dir(self):
#     def new_dir(self, path):
#     def machine_distribution(self):
#     def python(self, imports_line, command):
#     def put(self, contents, path):
#     def put_file(self, src, dst=None):
#     def close(self):
#     def run_script(self, script_path):
# def split_into_chunks(contents, max_size=2000, separator='\r\n'):
#     def join_lines(lines, line):
# class WinRMRunner(object):
# class WinRMCommandExecutionError(CommandExecutionError):
# class WinRMCommandExecutionException(CommandExecutionException):
# class WinRMCommandExecutionResponse(CommandExecutionResponse):
# 
# Path: cloudify_agent/installer/runners/winrm_runner.py
# def split_into_chunks(contents, max_size=2000, separator='\r\n'):
#     """Split content into chunks to avoid command line too long error.
# 
#     Maximum allowed commmand line length should be 2047 in old windows:
#     https://support.microsoft.com/en-us/help/830473/command-prompt-cmd--exe-command-line-string-limitation
# 
#     :param contents:
#         The contents of a file that exceeds the maximum command line length in
#         windows.
#     :type content: str
#     :returns: The same content in chunks that won't exceed the limit
#     :rtype: list[str]
# 
#     """
#     def join_lines(lines, line):
#         if len(line) > max_size:
#             raise ValueError('Line too long (%d characters)' % len(line))
# 
#         if (
#             lines and
#             len(lines[-1]) + len(line) + len(separator) <= max_size
#         ):
#             lines[-1] += '{0}{1}'.format(separator, line)
#         else:
#             lines.append(line)
#         return lines
# 
#     if contents:
#         chunks = reduce(join_lines, contents.splitlines(), [])
#     else:
#         chunks = ['']
#     return chunks


# Path: cloudify_agent/tests/installer/runners/test_winrm_runner.py
import pytest
from cloudify_agent.installer.runners import winrm_runner
from cloudify_agent.installer.runners.winrm_runner import split_into_chunks



##############################################################################
# note that this file only tests validation and defaults of the winrm runner.
# it does not test the actual functionality because that requires starting
# a vm. functional tests are executed as local workflow tests in the system
# tests framework
##############################################################################


def test_validate_host():
    # Missing host
    session_config = {
        'user': 'test_user',
        'password': 'test_password'
    }
    with pytest.raises(ValueError, match='.*Invalid host.*'):
        winrm_runner.validate(session_config)


def test_validate_user():
    # Missing user
    session_config = {
        'host': 'test_host',
        'password': 'test_password'
    }
    with pytest.raises(ValueError, match='.*Invalid user.*'):

        winrm_runner.validate(session_config)