test_guest.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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": 5,
  23. "disks": [],
  24. "quantity": 2,
  25. "name": "",
  26. "password": "pswd.com",
  27. "lease_term": 100
  28. }
  29. url = TestGuest.base_url + '/guest'
  30. headers = {'content-type': 'application/json'}
  31. r = requests.post(url, data=json.dumps(payload), headers=headers)
  32. j_r = json.loads(r.content)
  33. print json.dumps(j_r, ensure_ascii=False)
  34. self.assertEqual('200', j_r['state']['code'])
  35. # 获取Guest列表
  36. def test_12_get(self):
  37. pass
  38. # 更新Guest属性
  39. def test_13_update(self):
  40. pass
  41. # 校验更新结果
  42. def test_14_get(self):
  43. pass
  44. # 删除Guest
  45. def test_15_delete(self):
  46. pass
  47. if __name__ == '__main__':
  48. unittest.main()