class TestClickHeatLog(unittest.TestCase): def setUp(self): currentDir = os.path.dirname(__file__) self.fileLog = fileLog = os.path.realpath(currentDir) + '/1msource.log' self.descDir = descDir = os.path.realpath(os.path.realpath(currentDir) + '/../test') trackPointStoreStrategy = TrackPointFileStore(descDir) trackPointLineParseStrategy = ParserLine() self.heatClickLog = ClickHeatLog(fileLog, trackPointLineParseStrategy, trackPointStoreStrategy) def testCreateDescDirByDayFromSourceLog(self): 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' self.assertFalse(os.path.exists(self.descDir+'/mimo,homenonlogin')) self.assertFalse(os.path.exists(self.descDir+'/mimo,profile')) self.heatClickLog.parserFileLog() 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)) fileUrlOpen = io.open( urlFilePath, 'r') self.assertEqual('http://cms.local:8080/index/varnish>0>0>0', fileUrlOpen.readline()) fileUrlOpen.close() fileUrlOpen = io.open( urlProfileFilePath, 'r') self.assertEqual('http://dantri.com>0>0>0', fileUrlOpen.readline()) fileUrlOpen.close() fileLogProccesed = io.open(processLogFilePath) lines = fileLogProccesed.readlines() fileLogProccesed.close() self.assertTrue(any(self.fileLog in item for item in lines)) # lastLine = linecache.getline(dailyLogFilePath, 100) # firstLine = linecache.getline(dailyLogFilePath, 1) # self.assertEqual('1001|456|1265|chrome|1\n', lastLine) # self.assertEqual('1001|456|1265|chrome|1\n', firstLine) # # lastLine = linecache.getline(dailyProfileLogFilePath, 100) # firstLine = linecache.getline(dailyProfileLogFilePath, 1) # self.assertEqual('998|512|1265|chrome|1\n', lastLine) # self.assertEqual('998|512|1265|chrome|1\n', firstLine) def tearDown(self): shutil.rmtree(self.descDir + '/mimo,homenonlogin') shutil.rmtree(self.descDir + '/mimo,profile') os.remove(self.descDir + '/logproccesed.txt') pass
def setUp(self): currentDir = os.path.dirname(__file__) self.fileLog = fileLog = os.path.realpath(currentDir) + '/1msource.log' self.descDir = descDir = os.path.realpath( os.path.realpath(currentDir) + '/../test') trackPointStoreStrategy = TrackPointFileStore(descDir) trackPointLineParseStrategy = ParserLine() self.heatClickLog = ClickHeatLog(fileLog, trackPointLineParseStrategy, trackPointStoreStrategy)
def setUp(self): currentDir = os.path.dirname(__file__) self.fileLog = fileLog = os.path.realpath(currentDir) + '/1msource.log' self.descDir = descDir = os.path.realpath(os.path.realpath(currentDir) + '/../test') trackPointStoreStrategy = TrackPointFileStore(descDir) trackPointLineParseStrategy = ParserLine() self.heatClickLog = ClickHeatLog(fileLog, trackPointLineParseStrategy, trackPointStoreStrategy)
class TestClickHeatLog(unittest.TestCase): def setUp(self): currentDir = os.path.dirname(__file__) self.fileLog = fileLog = os.path.realpath(currentDir) + '/1msource.log' self.descDir = descDir = os.path.realpath( os.path.realpath(currentDir) + '/../test') trackPointStoreStrategy = TrackPointFileStore(descDir) trackPointLineParseStrategy = ParserLine() self.heatClickLog = ClickHeatLog(fileLog, trackPointLineParseStrategy, trackPointStoreStrategy) def testCreateDescDirByDayFromSourceLog(self): 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' self.assertFalse(os.path.exists(self.descDir + '/mimo,homenonlogin')) self.assertFalse(os.path.exists(self.descDir + '/mimo,profile')) self.heatClickLog.parserFileLog() 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)) fileUrlOpen = io.open(urlFilePath, 'r') self.assertEqual('http://cms.local:8080/index/varnish>0>0>0', fileUrlOpen.readline()) fileUrlOpen.close() fileUrlOpen = io.open(urlProfileFilePath, 'r') self.assertEqual('http://dantri.com>0>0>0', fileUrlOpen.readline()) fileUrlOpen.close() fileLogProccesed = io.open(processLogFilePath) lines = fileLogProccesed.readlines() fileLogProccesed.close() self.assertTrue(any(self.fileLog in item for item in lines)) # lastLine = linecache.getline(dailyLogFilePath, 100) # firstLine = linecache.getline(dailyLogFilePath, 1) # self.assertEqual('1001|456|1265|chrome|1\n', lastLine) # self.assertEqual('1001|456|1265|chrome|1\n', firstLine) # # lastLine = linecache.getline(dailyProfileLogFilePath, 100) # firstLine = linecache.getline(dailyProfileLogFilePath, 1) # self.assertEqual('998|512|1265|chrome|1\n', lastLine) # self.assertEqual('998|512|1265|chrome|1\n', firstLine) def tearDown(self): shutil.rmtree(self.descDir + '/mimo,homenonlogin') shutil.rmtree(self.descDir + '/mimo,profile') os.remove(self.descDir + '/logproccesed.txt') pass