from __future__ import print_function

import os
import unittest
import globals
import parseScreenIOCS

class TestScreenIOCParse(unittest.TestCase):
    '''Tests for parsing the screeniocs'''
    
    def test_parseScreenIOCs(self):
        iocs = parseScreenIOCS.parseScreenIOCs('testData/sampleScreenIOCs')
        self.assertTrue(len(iocs) == 290, "Total IOCs from sample file is {0}".format(len(iocs)))
        if globals.verbose:
            print('Total number of IOCS in testData/sampleScreenIOCs {0}'.format(len(iocs)))
        # Make sure all ioc's have a type
        for ioc in iocs:
            self.assertTrue('type' in iocs[ioc]);
        hardIOCCount = 0
        softIOCCount = 0
        viocCount = 0
        for ioc in iocs:
            info = iocs[ioc]
            self.assertTrue('name' in info)
            self.assertTrue('type' in info)
            # Make sure all hard ioc's have a terminal server and a port and a screen host
            if info['type'] == 'HIOC':
                self.assertTrue('port' in info, "For IOC {0}".format(ioc))
                self.assertTrue(int(info['port']) > 0, "For IOC {0}".format(ioc))
                self.assertTrue('terminalserver' in info, "For IOC {0}".format(ioc))
                self.assertTrue('screenhost' in info, "For IOC {0}".format(ioc))
                hardIOCCount = hardIOCCount + 1
            elif info['type'] == 'SIOC':
                self.assertTrue('executable' in info, "For IOC {0}".format(ioc))
                self.assertTrue('screenhost' in info, "For IOC {0}".format(ioc))
                softIOCCount = softIOCCount + 1
            elif info['type'] == 'VIOC':
                self.assertTrue('terminalserver' in info, "For IOC {0}".format(ioc))
                self.assertTrue('user' in info, "For IOC {0}".format(ioc))
                viocCount = viocCount + 1
                
        if globals.verbose:
            print('Hard IOCS = {0}, Soft IOCS = {1}, VIOCS = {2}'.format(hardIOCCount, softIOCCount, viocCount))
        self.assertTrue(hardIOCCount > 10);
        self.assertTrue(softIOCCount > 10);
        self.assertTrue(viocCount > 10);
