test_os_init.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 TestOSInit(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. # # 创建系统初始化组
  18. # def test_11_create(self):
  19. # payload = {
  20. # "name": 'CentOS-Systemd',
  21. # "remark": u'用作红帽 Systemd 系列的系统初始化。初始化操作依据 CentOS 7 来实现。'
  22. # }
  23. #
  24. # url = TestOSInit.base_url + '/os_init'
  25. # headers = {'content-type': 'application/json'}
  26. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  27. # j_r = json.loads(r.content)
  28. # print json.dumps(j_r, ensure_ascii=False)
  29. # self.assertEqual('200', j_r['state']['code'])
  30. # 获取系统初始化组列表
  31. def test_12_get(self):
  32. url = TestOSInit.base_url + '/os_inits'
  33. headers = {'content-type': 'application/json'}
  34. r = requests.get(url, headers=headers)
  35. j_r = json.loads(r.content)
  36. print json.dumps(j_r, ensure_ascii=False)
  37. TestOSInit.os_init_id = j_r['data'][0]['id']
  38. self.assertEqual('200', j_r['state']['code'])
  39. # # 创建更新系统初始化组
  40. # def test_13_update(self):
  41. # payload = {
  42. # "name": 'RedHat-Systemd'
  43. # }
  44. #
  45. # url = TestOSInit.base_url + '/os_init/' + TestOSInit.os_init_id.__str__()
  46. # headers = {'content-type': 'application/json'}
  47. # r = requests.patch(url, data=json.dumps(payload), headers=headers)
  48. # j_r = json.loads(r.content)
  49. # print json.dumps(j_r, ensure_ascii=False)
  50. # self.assertEqual('200', j_r['state']['code'])
  51. #
  52. # # 校验系统初始化组列表更新结果
  53. # def test_14_get(self):
  54. # url = TestOSInit.base_url + '/os_inits'
  55. # headers = {'content-type': 'application/json'}
  56. # r = requests.get(url, headers=headers)
  57. # j_r = json.loads(r.content)
  58. # print json.dumps(j_r, ensure_ascii=False)
  59. # self.assertEqual('200', j_r['state']['code'])
  60. # self.assertEqual('RedHat-Systemd', j_r['data'][0]['name'])
  61. #
  62. # # 删除系统初始化组列表更新结果
  63. # def test_15_delete(self):
  64. # url = TestOSInit.base_url + '/os_inits/' + TestOSInit.os_init_id.__str__()
  65. # headers = {'content-type': 'application/json'}
  66. # r = requests.delete(url, headers=headers)
  67. # j_r = json.loads(r.content)
  68. # print json.dumps(j_r, ensure_ascii=False)
  69. # self.assertEqual('200', j_r['state']['code'])
  70. #
  71. # def test_21_create(self):
  72. # payload = {
  73. # "name": 'Gentoo-OpenRC',
  74. # "remark": u'Gentoo startup process。'
  75. # }
  76. #
  77. # url = TestOSInit.base_url + '/os_init'
  78. # headers = {'content-type': 'application/json'}
  79. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  80. # j_r = json.loads(r.content)
  81. # print json.dumps(j_r, ensure_ascii=False)
  82. # self.assertEqual('200', j_r['state']['code'])
  83. #
  84. # # 创建系统初始化组
  85. # def test_22_create(self):
  86. # payload = {
  87. # "name": 'Ubuntu-Upstart',
  88. # "remark": u'Ubuntu startup process。'
  89. # }
  90. #
  91. # url = TestOSInit.base_url + '/os_init'
  92. # headers = {'content-type': 'application/json'}
  93. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  94. # j_r = json.loads(r.content)
  95. # print json.dumps(j_r, ensure_ascii=False)
  96. # self.assertEqual('200', j_r['state']['code'])
  97. #
  98. # # 创建系统初始化组
  99. # def test_23_create(self):
  100. # payload = {
  101. # "name": 'CentOS-SysV',
  102. # "remark": u'用作CentOS SysV 系列的系统初始化。初始化操作依据 CentOS 6.8 来实现。'
  103. # }
  104. #
  105. # url = TestOSInit.base_url + '/os_init'
  106. # headers = {'content-type': 'application/json'}
  107. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  108. # j_r = json.loads(r.content)
  109. # print json.dumps(j_r, ensure_ascii=False)
  110. # self.assertEqual('200', j_r['state']['code'])
  111. if __name__ == '__main__':
  112. unittest.main()