# Path: elem/host/assessor.py
# class YumAssessor(Assessor):
#     def __init__(self):
#         super(YumAssessor, self).__init__()
# 
#     def assess(self):
#         lines = []
#         error_lines = []
#         
#         command = ["yum", "updateinfo", "list", "cves"]
#         p = subprocess.Popen(command,
#                              stdout=subprocess.PIPE,
#                              stderr=subprocess.PIPE)
#         out, err = p.communicate()
# 
#         if p.returncode != 0:
#             raise OSError((p.returncode, err))
# 
#         lines = out.split('\n')
# 
#         pattern = re.compile(r'\s(.*CVE-\d{4}-\d{4,})')
#         for line in lines:
#             result = re.findall(pattern, line)
#             if result and result[0] not in self.cves:
#                 self.cves.append(result[0])
# 
#         self.cves = list(set(self.cves))


import unittest
import os
import mock
from elem.host import YumAssessor


class TestYumAssessor(unittest.TestCase):

    def setUp(self):
        test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                      '..',
                                      'test_data',
                                      'assess',
                                      'cve_list.txt')
        with open(test_data_path, 'r') as cve_file:
            self.test_cves = cve_file.readlines()
        self.test_cves = [cve.replace('\n', '') for cve in self.test_cves]

        yum_output_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                       '..',
                                       'test_data',
                                       'assess',
                                       'yum_output.txt')
        with open(yum_output_path, 'r') as yum_file:
            self.yum_output = yum_file.read()

        yum_error_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                      '..',
                                      'test_data',
                                      'assess',
                                      'yum_errors.txt')
        with open(yum_error_path, 'r') as yum_file:
            self.yum_error = yum_file.read()


# Path: elem/host/assessor.py
# class YumAssessor(Assessor):
#     def __init__(self):
#         super(YumAssessor, self).__init__()
# 
#     def assess(self):
#         lines = []
#         error_lines = []
#         
#         command = ["yum", "updateinfo", "list", "cves"]
#         p = subprocess.Popen(command,
#                              stdout=subprocess.PIPE,
#                              stderr=subprocess.PIPE)
#         out, err = p.communicate()
# 
#         if p.returncode != 0:
#             raise OSError((p.returncode, err))
# 
#         lines = out.split('\n')
# 
#         pattern = re.compile(r'\s(.*CVE-\d{4}-\d{4,})')
#         for line in lines:
#             result = re.findall(pattern, line)
#             if result and result[0] not in self.cves:
#                 self.cves.append(result[0])
# 
#         self.cves = list(set(self.cves))


# Path: tests/host/test_assessor.py
import unittest
import os
import mock
from elem.host import YumAssessor



class TestYumAssessor(unittest.TestCase):

    def setUp(self):
        test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                      '..',
                                      'test_data',
                                      'assess',
                                      'cve_list.txt')
        with open(test_data_path, 'r') as cve_file:
            self.test_cves = cve_file.readlines()
        self.test_cves = [cve.replace('\n', '') for cve in self.test_cves]

        yum_output_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                       '..',
                                       'test_data',
                                       'assess',
                                       'yum_output.txt')
        with open(yum_output_path, 'r') as yum_file:
            self.yum_output = yum_file.read()

        yum_error_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                      '..',
                                      'test_data',
                                      'assess',
                                      'yum_errors.txt')
        with open(yum_error_path, 'r') as yum_file:
            self.yum_error = yum_file.read()


        self.yum_assessor = YumAssessor()