def setUp(self):
     currentDir = os.path.dirname(__file__)
     environment = 'testing'
     self.configFile = os.path.realpath(currentDir) + '/config.ini'
     self.app = Application(environment, self.configFile, '2012-10-12')
 def setUp(self):
     currentDir = os.path.dirname(__file__)
     environment = 'testing'
     self.configFile = os.path.realpath(currentDir) + '/config.ini'
     self.app = Application(environment, self.configFile, '2012-10-12')
class TestApplicationSuccess(unittest.TestCase):
    def setUp(self):
        currentDir = os.path.dirname(__file__)
        environment = 'testing'
        self.configFile = os.path.realpath(currentDir) + '/config.ini'
        self.app = Application(environment, self.configFile, '2012-10-12')
        
    def testGetConfigFile(self):
        config = self.app.getConfigs()
        espected = {'source':'/home/guitar/Zend1/workspaces/DefaultWorkspace/clickheat/src',\
                    'desc':'/home/guitar/Zend1/workspaces/DefaultWorkspace/clickheat/test'}
        self.assertDictEqual(espected, config)
        
    def testChooseYesterdayLogFileSuccess(self):
        logFilePath = self.app.getYesterdayLogFile('')
        
        yesterday = datetime.today() - timedelta(1)
        yesterdayLogFileExpected = '/home/guitar/Zend1/workspaces/DefaultWorkspace/clickheat/src/' + yesterday.strftime('%Y-%m-%d') + '.log'
        self.assertEqual(yesterdayLogFileExpected, logFilePath)
        
        logFilePath = self.app.getYesterdayLogFile()
        self.assertEqual(yesterdayLogFileExpected, logFilePath)
        
        logFilePath = self.app.getYesterdayLogFile('2012-10-09')
        yesterdayLogFileExpected = '/home/guitar/Zend1/workspaces/DefaultWorkspace/clickheat/src/2012-10-08.log'
        self.assertEqual(yesterdayLogFileExpected, logFilePath)
    
    def testRun(self):
        
        
        self.descDir = self.app.getConfigs()['desc']
        
        dailyLogFilePath = self.descDir + '/mimo,homenonlogin/2012-10-02.log'
        urlFilePath = self.descDir + '/mimo,homenonlogin/url.txt'
        urlProfileFilePath = self.descDir + '/mimo,profile/url.txt'
        processLogFilePath = self.descDir + '/logproccesed.txt'
        dailyProfileLogFilePath = self.descDir + '/mimo,profile/2012-10-03.log'
        
        #before run app
        self.assertFalse(os.path.exists(self.descDir+'/mimo,homenonlogin'))
        self.assertFalse(os.path.exists(self.descDir+'/mimo,profile'))
        
        #first run app
        self.app.run()
        file = open(dailyProfileLogFilePath)
        profileLines = file.readlines()
        file.close()
        
        file = open(dailyLogFilePath)
        homeLines = open(dailyLogFilePath)
        file.close()

        self.assertTrue(os.path.isdir(self.descDir+'/mimo,homenonlogin'))
        self.assertTrue(os.path.isdir(self.descDir+'/mimo,profile'))
        self.assertTrue(os.path.isfile(dailyLogFilePath))
        self.assertTrue(os.path.isfile(dailyProfileLogFilePath))

        self.assertTrue(os.path.isfile(urlProfileFilePath))
        self.assertTrue(os.path.isfile(urlFilePath))
        
        self.assertTrue(os.path.isfile(processLogFilePath))
        
        #second run app
        self.app.run()
        
        file = open(dailyProfileLogFilePath)
        profileLines2 = file.readlines()
        file.close()
        
        file = open(dailyLogFilePath)
        homeLines2 = open(dailyLogFilePath)
        file.close()
#        
        self.assertEqual(profileLines, profileLines2)
#        self.assertEqual(homeLines, homeLines2)
        
        #delete all test resource
        descDir = self.app.getConfigs()['desc']
        shutil.rmtree(descDir + '/mimo,homenonlogin')
        shutil.rmtree(descDir + '/mimo,profile')
        os.remove(descDir + '/logproccesed.txt')
class TestApplicationSuccess(unittest.TestCase):
    def setUp(self):
        currentDir = os.path.dirname(__file__)
        environment = 'testing'
        self.configFile = os.path.realpath(currentDir) + '/config.ini'
        self.app = Application(environment, self.configFile, '2012-10-12')

    def testGetConfigFile(self):
        config = self.app.getConfigs()
        espected = {'source':'/home/guitar/Zend1/workspaces/DefaultWorkspace/clickheat/src',\
                    'desc':'/home/guitar/Zend1/workspaces/DefaultWorkspace/clickheat/test'}
        self.assertDictEqual(espected, config)

    def testChooseYesterdayLogFileSuccess(self):
        logFilePath = self.app.getYesterdayLogFile('')

        yesterday = datetime.today() - timedelta(1)
        yesterdayLogFileExpected = '/home/guitar/Zend1/workspaces/DefaultWorkspace/clickheat/src/' + yesterday.strftime(
            '%Y-%m-%d') + '.log'
        self.assertEqual(yesterdayLogFileExpected, logFilePath)

        logFilePath = self.app.getYesterdayLogFile()
        self.assertEqual(yesterdayLogFileExpected, logFilePath)

        logFilePath = self.app.getYesterdayLogFile('2012-10-09')
        yesterdayLogFileExpected = '/home/guitar/Zend1/workspaces/DefaultWorkspace/clickheat/src/2012-10-08.log'
        self.assertEqual(yesterdayLogFileExpected, logFilePath)

    def testRun(self):

        self.descDir = self.app.getConfigs()['desc']

        dailyLogFilePath = self.descDir + '/mimo,homenonlogin/2012-10-02.log'
        urlFilePath = self.descDir + '/mimo,homenonlogin/url.txt'
        urlProfileFilePath = self.descDir + '/mimo,profile/url.txt'
        processLogFilePath = self.descDir + '/logproccesed.txt'
        dailyProfileLogFilePath = self.descDir + '/mimo,profile/2012-10-03.log'

        #before run app
        self.assertFalse(os.path.exists(self.descDir + '/mimo,homenonlogin'))
        self.assertFalse(os.path.exists(self.descDir + '/mimo,profile'))

        #first run app
        self.app.run()
        file = open(dailyProfileLogFilePath)
        profileLines = file.readlines()
        file.close()

        file = open(dailyLogFilePath)
        homeLines = open(dailyLogFilePath)
        file.close()

        self.assertTrue(os.path.isdir(self.descDir + '/mimo,homenonlogin'))
        self.assertTrue(os.path.isdir(self.descDir + '/mimo,profile'))
        self.assertTrue(os.path.isfile(dailyLogFilePath))
        self.assertTrue(os.path.isfile(dailyProfileLogFilePath))

        self.assertTrue(os.path.isfile(urlProfileFilePath))
        self.assertTrue(os.path.isfile(urlFilePath))

        self.assertTrue(os.path.isfile(processLogFilePath))

        #second run app
        self.app.run()

        file = open(dailyProfileLogFilePath)
        profileLines2 = file.readlines()
        file.close()

        file = open(dailyLogFilePath)
        homeLines2 = open(dailyLogFilePath)
        file.close()
        #
        self.assertEqual(profileLines, profileLines2)
        #        self.assertEqual(homeLines, homeLines2)

        #delete all test resource
        descDir = self.app.getConfigs()['desc']
        shutil.rmtree(descDir + '/mimo,homenonlogin')
        shutil.rmtree(descDir + '/mimo,profile')
        os.remove(descDir + '/logproccesed.txt')