class TestSystemModel(unittest.TestCase): def setUp(self): self.model = SystemModel() def test_get_system_data(self): active_checks = ["cpu"] # Delete everything in the cpu collection cpu = self.model.mongo.get_collection("cpu") cpu.remove() empty_result = self.model.get_system_data(active_checks, minute_ago, now) eq_(len(empty_result), 1) # Should return only the cpu field {cpu: pymongoobject} # Nothing in the cpu field for cpu in empty_result["cpu"]: eq_(cpu, False) cpu.insert({"system": 1, "idle": 98, "user": 0, "time": minute_ago}) cpu.insert({"system": 1, "idle": 98, "user": 0, "time": two_minutes_ago}) cpu.insert({"system": 1, "idle": 98, "user": 0, "time": now}) result = self.model.get_system_data(active_checks, two_minutes_ago, now) eq_(result["cpu"].count(), 3) result = self.model.get_system_data(active_checks, minute_ago, now) eq_(result["cpu"].count(), 2) # Cleanup the collection cpu.remove()
class TestSystemModel(unittest.TestCase): def setUp(self): self.model = SystemModel() def test_get_system_data(self): active_checks = ['cpu'] # Delete everything in the cpu collection cpu = self.model.mongo.get_collection('cpu') cpu.remove() empty_result = self.model.get_system_data(active_checks, minute_ago, now) eq_(len(empty_result), 1) # Should return only the cpu field {cpu: pymongoobject} # Nothing in the cpu field for cpu in empty_result['cpu']: eq_(cpu, False) cpu.insert({"system": 1, "idle": 98, "user": 0, "time": minute_ago}) cpu.insert({ "system": 1, "idle": 98, "user": 0, "time": two_minutes_ago }) cpu.insert({"system": 1, "idle": 98, "user": 0, "time": now}) result = self.model.get_system_data(active_checks, two_minutes_ago, now) eq_(result['cpu'].count(), 3) result = self.model.get_system_data(active_checks, minute_ago, now) eq_(result['cpu'].count(), 2) # Cleanup the collection cpu.remove()
def setUp(self): self.model = SystemModel()