# Path: auto_forensicate/recipes/base.py
# class BaseArtifact(object):
# class StringArtifact(BaseArtifact):
# class FileArtifact(BaseArtifact):
# class ProcessOutputArtifact(BaseArtifact):
# class BaseRecipe(object):
#   def __init__(self, name):
#   def _GetStream(self):
#   def CloseStream(self):
#   def OpenStream(self):
#   def size(self):
#   def readable_size(self):
#   def __init__(self, path, string_content):
#   def _GetStream(self):
#   def CloseStream(self):
#   def __init__(self, path):
#   def _GetStream(self):
#   def __init__(self, command, path, ignore_failure=False):
#   def _RunCommand(self):
#   def _GetStream(self):
#   def __init__(self, name, options=None):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def GetArtifacts(self):
# 
# Path: auto_forensicate/recipes/sysinfo.py
# class SysinfoRecipe(base.BaseRecipe):
#   _SYSTEM_PROFILER_CMD = [
#       '/usr/sbin/system_profiler', 'SPHardwareDataType', 'SPSoftwareDataType']
#   _NETWORKSETUP_CMD = [
#       '/usr/sbin/networksetup', '-listallhardwareports']
#   def GetArtifacts(self):


import unittest
import mock
from auto_forensicate.recipes import base
from auto_forensicate.recipes import sysinfo
    """

  def testGetArtifactsFail(self):
    sysinfo_recipe = sysinfo.SysinfoRecipe('failsysinfo')
    # pylint: disable=protected-access
    sysinfo_recipe._platform = 'linux'
    # pylint: disable=line-too-long
    with mock.patch('auto_forensicate.recipes.base.ProcessOutputArtifact._RunCommand') as patched_run:
      patched_run.return_value = self._DMIDECODE_OUTPUT_FAIL_STRING
      artifacts = sysinfo_recipe.GetArtifacts()
      self.assertEqual(len(artifacts), 2)

      artifact = artifacts[0]
      self.assertIsInstance(artifact, base.ProcessOutputArtifact)
      self.assertEqual(artifact.name, 'system_info.txt')
      self.assertEqual(artifact.remote_path, 'system_info.txt')
      artifact_content = artifact.OpenStream().read()
      self.assertEqual(artifact_content, self._DMIDECODE_OUTPUT_FAIL_STRING)

  def testGetArtifacts(self):
    sysinfo_recipe = sysinfo.SysinfoRecipe('sysinfo')
    # pylint: disable=protected-access
    sysinfo_recipe._platform = 'linux'
    # pylint: disable=line-too-long
    with mock.patch('auto_forensicate.recipes.base.ProcessOutputArtifact._RunCommand') as patched_run:
      patched_run.return_value = self._DMIDECODE_OUTPUT_STRING
      artifacts = sysinfo_recipe.GetArtifacts()
      self.assertEqual(len(artifacts), 2)

      artifact = artifacts[0]

# Path: auto_forensicate/recipes/base.py
# class BaseArtifact(object):
# class StringArtifact(BaseArtifact):
# class FileArtifact(BaseArtifact):
# class ProcessOutputArtifact(BaseArtifact):
# class BaseRecipe(object):
#   def __init__(self, name):
#   def _GetStream(self):
#   def CloseStream(self):
#   def OpenStream(self):
#   def size(self):
#   def readable_size(self):
#   def __init__(self, path, string_content):
#   def _GetStream(self):
#   def CloseStream(self):
#   def __init__(self, path):
#   def _GetStream(self):
#   def __init__(self, command, path, ignore_failure=False):
#   def _RunCommand(self):
#   def _GetStream(self):
#   def __init__(self, name, options=None):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def GetArtifacts(self):
# 
# Path: auto_forensicate/recipes/sysinfo.py
# class SysinfoRecipe(base.BaseRecipe):
#   _SYSTEM_PROFILER_CMD = [
#       '/usr/sbin/system_profiler', 'SPHardwareDataType', 'SPSoftwareDataType']
#   _NETWORKSETUP_CMD = [
#       '/usr/sbin/networksetup', '-listallhardwareports']
#   def GetArtifacts(self):


# Path: tests/sysinfo_tests.py
import unittest
import mock
from auto_forensicate.recipes import base
from auto_forensicate.recipes import sysinfo

    """

  def testGetArtifactsFail(self):
    sysinfo_recipe = sysinfo.SysinfoRecipe('failsysinfo')
    # pylint: disable=protected-access
    sysinfo_recipe._platform = 'linux'
    # pylint: disable=line-too-long
    with mock.patch('auto_forensicate.recipes.base.ProcessOutputArtifact._RunCommand') as patched_run:
      patched_run.return_value = self._DMIDECODE_OUTPUT_FAIL_STRING
      artifacts = sysinfo_recipe.GetArtifacts()
      self.assertEqual(len(artifacts), 2)

      artifact = artifacts[0]
      self.assertIsInstance(artifact, base.ProcessOutputArtifact)
      self.assertEqual(artifact.name, 'system_info.txt')
      self.assertEqual(artifact.remote_path, 'system_info.txt')
      artifact_content = artifact.OpenStream().read()
      self.assertEqual(artifact_content, self._DMIDECODE_OUTPUT_FAIL_STRING)

  def testGetArtifacts(self):
    sysinfo_recipe = sysinfo.SysinfoRecipe('sysinfo')
    # pylint: disable=protected-access
    sysinfo_recipe._platform = 'linux'
    # pylint: disable=line-too-long
    with mock.patch('auto_forensicate.recipes.base.ProcessOutputArtifact._RunCommand') as patched_run:
      patched_run.return_value = self._DMIDECODE_OUTPUT_STRING
      artifacts = sysinfo_recipe.GetArtifacts()
      self.assertEqual(len(artifacts), 2)

      artifact = artifacts[0]

      self.assertIsInstance(artifact, base.ProcessOutputArtifact)