test_os_template.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/3/31'
  8. __contact__ = 'james.iter.cn@gmail.com'
  9. __copyright__ = '(c) 2017 by James Iter.'
  10. class TestOSTemplate(unittest.TestCase):
  11. base_url = 'http://127.0.0.1:8008/api'
  12. os_template_id = 0
  13. def setUp(self):
  14. pass
  15. def tearDown(self):
  16. pass
  17. # # 创建系统模板
  18. # def test_11_create(self):
  19. # payload = {
  20. # "label": "CentOS-7.2",
  21. # "path": "template_pool/centos72_multi-user_2016-09-15_128G.qcow2",
  22. # "active": True,
  23. # "os_init_id": 3
  24. # }
  25. #
  26. # url = TestOSTemplate.base_url + '/os_template'
  27. # headers = {'content-type': 'application/json'}
  28. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  29. # j_r = json.loads(r.content)
  30. # print json.dumps(j_r, ensure_ascii=False)
  31. # TestOSTemplate.os_template_id = j_r['data']['id']
  32. # self.assertEqual('200', j_r['state']['code'])
  33. #
  34. # # 获取系统模板列表
  35. # def test_12_get(self):
  36. # url = TestOSTemplate.base_url + '/os_templates'
  37. # headers = {'content-type': 'application/json'}
  38. # r = requests.get(url, headers=headers)
  39. # j_r = json.loads(r.content)
  40. # print json.dumps(j_r, ensure_ascii=False)
  41. # self.assertEqual('200', j_r['state']['code'])
  42. #
  43. # # 更新系统模板
  44. # def test_13_update(self):
  45. # payload = {
  46. # "label": 'CentOS-72'
  47. # }
  48. #
  49. # url = TestOSTemplate.base_url + '/os_template/' + TestOSTemplate.os_template_id.__str__()
  50. # headers = {'content-type': 'application/json'}
  51. # r = requests.patch(url, data=json.dumps(payload), headers=headers)
  52. # j_r = json.loads(r.content)
  53. # print json.dumps(j_r, ensure_ascii=False)
  54. # self.assertEqual('200', j_r['state']['code'])
  55. #
  56. # # 校验系统模板更新结果
  57. # def test_14_get(self):
  58. # url = TestOSTemplate.base_url + '/os_templates'
  59. # headers = {'content-type': 'application/json'}
  60. # r = requests.get(url, headers=headers)
  61. # j_r = json.loads(r.content)
  62. # print json.dumps(j_r, ensure_ascii=False)
  63. # self.assertEqual('200', j_r['state']['code'])
  64. # self.assertEqual('CentOS-72', j_r['data'][0]['label'])
  65. #
  66. # @unittest.skip('skip delete os template!')
  67. # # 删除系统模板
  68. # def test_15_delete(self):
  69. # url = TestOSTemplate.base_url + '/os_templates/' + TestOSTemplate.os_template_id.__str__()
  70. # headers = {'content-type': 'application/json'}
  71. # r = requests.delete(url, headers=headers)
  72. # j_r = json.loads(r.content)
  73. # print json.dumps(j_r, ensure_ascii=False)
  74. # self.assertEqual('200', j_r['state']['code'])
  75. #
  76. # def test_21_create(self):
  77. # payload = {
  78. # "label": "Gentoo",
  79. # "path": "template_pool/gentoo_2016-08-12_128G.qcow2",
  80. # "active": True,
  81. # "os_init_id": 7
  82. # }
  83. #
  84. # url = TestOSTemplate.base_url + '/os_template'
  85. # headers = {'content-type': 'application/json'}
  86. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  87. # j_r = json.loads(r.content)
  88. # print json.dumps(j_r, ensure_ascii=False)
  89. # TestOSTemplate.os_template_id = j_r['data']['id']
  90. # self.assertEqual('200', j_r['state']['code'])
  91. #
  92. # def test_22_create(self):
  93. # payload = {
  94. # "label": "CentOS-6.8",
  95. # "path": "template_pool/P_centos68_multi-user_2016-09-28_128G.qcow2",
  96. # "active": True,
  97. # "os_init_id": 8
  98. # }
  99. #
  100. # url = TestOSTemplate.base_url + '/os_template'
  101. # headers = {'content-type': 'application/json'}
  102. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  103. # j_r = json.loads(r.content)
  104. # print json.dumps(j_r, ensure_ascii=False)
  105. # TestOSTemplate.os_template_id = j_r['data']['id']
  106. # self.assertEqual('200', j_r['state']['code'])
  107. if __name__ == '__main__':
  108. unittest.main()