Example #1
0
	def setUp(self):
		self.collector = MaCollector()
Example #2
0
class TestMaCollector(unittest.TestCase):
	'''
	Test case for MaCollector
	'''
	def setUp(self):
		self.collector = MaCollector()
	
	
	def test_getSwapInfo(self):
		swap_info_json = self.collector.getSwapInfo()
		
		self.assertTrue(type(swap_info_json) is dict)
		self.assertTrue('total' in swap_info_json)
		self.assertTrue('used' in swap_info_json)
		self.assertTrue('free' in swap_info_json)
		
		print
		print "Swap info: \n---\n", swap_info_json, "\n---"
	
	
	def test_getLoadAvg(self):
		load_avg_json = self.collector.getLoadAvg()
		
		self.assertTrue(type(load_avg_json) is dict)
		self.assertEqual(len(load_avg_json.keys()), 3)
		self.assertTrue('load_one' in load_avg_json)
		self.assertTrue('load_five' in load_avg_json)
		self.assertTrue('load_fifteen' in load_avg_json)
	
	
	def test_getServerUptime(self):
		uptime = self.collector.getServerUptime()
		
		#TODO more checks
		#print
		#print "Returned uptime: \n---\n", uptime, "\n---"
	
	
	def test_getDiskUsage(self):
		disk_usage = self.collector.getDiskUsage()
		
		self.assertTrue(type(disk_usage) is list)
		#TODO more checks
		#print
		#print "DiskUsage: \n---\n", disk_usage, "\n---"
	
	
	def test_getProcessesSnapshot(self):
		proc_snp = self.collector.getProcessesSnapshot()
		
		#TODO more checks
		#print
		#print "ProcSnapshoot: \n---\n", proc_snp, "\n---"
	
	
	def test_getCpuInfo(self):
		cpu_info = self.collector.getCpuInfo()
		
		self.assertTrue(type(cpu_info) is dict)
		#TODO more checks
		#print
		#print "CPU info: \n---\n", cpu_info, "\n---"
	
	
	def test_getCpuCheck(self):
		cpu_check_json = self.collector.getCpuCheck()
		
		self.assertTrue(type(cpu_check_json) is dict)
		self.assertEqual(len(cpu_check_json.keys()), 4)
		self.assertTrue('cpu_system' in cpu_check_json)
		self.assertTrue('cpu_used' in cpu_check_json)
		self.assertTrue('cpu_user' in cpu_check_json)
		self.assertTrue('cpu_free' in cpu_check_json)
		#TODO more checks (floats, used vs. free, .... )
		#print
		#print "CPU info: \n---\n", cpu_check_json, "\n---"
	
	
	def test_getAppleInfo(self):
		apple_info = self.collector.getAppleInfo()
		
		if (sys.platform == 'darwin'):
			#TODO DO TESTS
			pass
		else:
			self.assertFalse(apple_info)
		
		#print
		#print "COMP info: \n---\n", apple_info, "\n---"
	
	
	def test_getMemoryCheck(self):
		mem_check_json = self.collector.getMemoryCheck()
		
		self.assertTrue(type(mem_check_json) is dict)
		self.assertEqual(len(mem_check_json.keys()), 4)
		self.assertTrue('mem_system' in mem_check_json)
		self.assertTrue('mem_used' in mem_check_json)
		self.assertTrue('mem_user' in mem_check_json)
		self.assertTrue('mem_free' in mem_check_json)
		
		#print
		#print "Memory check info: \n---\n", mem_check_json, "\n---"
	
	
	def test_getNetworkTraffic(self):
		net_traff_json = self.collector.getNetworkTraffic()
		
		self.assertTrue(type(net_traff_json) is dict)
		k = net_traff_json.keys()
		if k > 0:
			#TODO do test of key values validity
			pass
		
		#print
		#print "Network traffic info: \n---\n", net_traff_json, "\n---"
	
	
	def test_readSystemOs(self):
		sys_os_json = self.collector.readSystemOs()
		
		self.assertTrue(type(sys_os_json) is dict)
		self.assertEqual(len(sys_os_json.keys()), 6)
		self.assertTrue('platform' in sys_os_json)
		self.assertTrue('machine' in sys_os_json)
		self.assertTrue('processor' in sys_os_json)
		self.assertTrue('cpu_cores' in sys_os_json)
		self.assertTrue('dist' in sys_os_json)
		self.assertTrue('pythonV' in sys_os_json)