test_guest.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import requests
  4. import json
  5. import unittest
  6. __author__ = 'James Iter'
  7. __date__ = '2017/4/4'
  8. __contact__ = 'james.iter.cn@gmail.com'
  9. __copyright__ = '(c) 2017 by James Iter.'
  10. class TestGuest(unittest.TestCase):
  11. base_url = 'http://127.0.0.1:8008/api'
  12. os_init_id = 0
  13. def setUp(self):
  14. pass
  15. def tearDown(self):
  16. pass
  17. # 创建Guest
  18. def test_11_create(self):
  19. payload = {
  20. "cpu": 4,
  21. "memory": 4,
  22. "os_template_id": 1,
  23. "quantity": 2,
  24. "name": "",
  25. "password": "pswd.com",
  26. "lease_term": 100
  27. }
  28. url = TestGuest.base_url + '/guest'
  29. headers = {'content-type': 'application/json'}
  30. r = requests.post(url, data=json.dumps(payload), headers=headers)
  31. j_r = json.loads(r.content)
  32. print json.dumps(j_r, ensure_ascii=False)
  33. self.assertEqual('200', j_r['state']['code'])
  34. # 获取Guest列表
  35. def test_12_get(self):
  36. pass
  37. # 更新Guest属性
  38. def test_13_update(self):
  39. pass
  40. # 校验更新结果
  41. def test_14_get(self):
  42. pass
  43. # 删除Guest
  44. def test_15_delete(self):
  45. pass
  46. if __name__ == '__main__':
  47. unittest.main()