test_os_init.py 2.7 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. url = TestOSInit.base_url + '/os_init'
  24. headers = {'content-type': 'application/json'}
  25. r = requests.post(url, data=json.dumps(payload), headers=headers)
  26. j_r = json.loads(r.content)
  27. print json.dumps(j_r, ensure_ascii=False)
  28. self.assertEqual('200', j_r['state']['code'])
  29. # 获取系统初始化组列表
  30. def test_12_get(self):
  31. url = TestOSInit.base_url + '/os_init'
  32. headers = {'content-type': 'application/json'}
  33. r = requests.get(url, headers=headers)
  34. j_r = json.loads(r.content)
  35. print json.dumps(j_r, ensure_ascii=False)
  36. TestOSInit.os_init_id = j_r['data'][0]['id']
  37. self.assertEqual('200', j_r['state']['code'])
  38. # 创建更新系统初始化组
  39. def test_13_update(self):
  40. payload = {
  41. "name": 'RedHat-Systemd'
  42. }
  43. url = TestOSInit.base_url + '/os_init/' + TestOSInit.os_init_id.__str__()
  44. headers = {'content-type': 'application/json'}
  45. r = requests.patch(url, data=json.dumps(payload), headers=headers)
  46. j_r = json.loads(r.content)
  47. print json.dumps(j_r, ensure_ascii=False)
  48. self.assertEqual('200', j_r['state']['code'])
  49. # 校验系统初始化组列表更新结果
  50. def test_14_get(self):
  51. url = TestOSInit.base_url + '/os_init'
  52. headers = {'content-type': 'application/json'}
  53. r = requests.get(url, headers=headers)
  54. j_r = json.loads(r.content)
  55. print json.dumps(j_r, ensure_ascii=False)
  56. self.assertEqual('200', j_r['state']['code'])
  57. self.assertEqual('RedHat-Systemd', j_r['data'][0]['name'])
  58. # 删除系统初始化组列表更新结果
  59. def test_15_delete(self):
  60. url = TestOSInit.base_url + '/os_init/' + TestOSInit.os_init_id.__str__()
  61. headers = {'content-type': 'application/json'}
  62. r = requests.delete(url, headers=headers)
  63. j_r = json.loads(r.content)
  64. print json.dumps(j_r, ensure_ascii=False)
  65. self.assertEqual('200', j_r['state']['code'])
  66. if __name__ == '__main__':
  67. unittest.main()