test_os_init.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_init/' + 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. if __name__ == '__main__':
  71. unittest.main()