TestServerMonitor.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from __future__ import division
  2. import unittest
  3. from monitor import Env, DetailProcess, ProcessCounter, Sandbox
  4. import os
  5. class TestMonitorServer(unittest.TestCase):
  6. def test_Environment(self):
  7. """
  8. This test case is designed to test the existance of a resource set as an environment variable. This applies to files, folders (not values)
  9. """
  10. p = Env(['PATH','HOME','SHELL'])
  11. r = p.composite()
  12. value = r['value']
  13. self.assertTrue(value > 0 and value == 2/3)
  14. self.assertTrue(p.evaluate('PATH') == 0)
  15. def test_RunningProcess(self):
  16. p = DetailProcess(['rabbitmq-server','python','apache2'])
  17. r = p.composite()
  18. print r
  19. self.assertTrue(r)
  20. def test_ProcessCount(self):
  21. p= ProcessCounter(['apache2','VBoxClient','rabbitmq-server','foo'])
  22. r = p.composite()
  23. self.assertTrue( sum(r.values()) > 0 )
  24. self.assertTrue( r['foo'] == 0)
  25. def test_VirtualEnv(self):
  26. requirements_path = os.sep.join([os.environ['PYTHONPATH'],"..","requirements.txt"])
  27. sandbox_path = os.sep.join([os.environ['PYTHONPATH'],"..",'sandbox'])
  28. p = Sandbox({"sandbox":sandbox_path,"requirements":requirements_path})
  29. print p.composite()
  30. if __name__ == '__main__' :
  31. unittest.main()