test_config.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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/3'
  8. __contact__ = 'james.iter.cn@gmail.com'
  9. __copyright__ = '(c) 2017 by James Iter.'
  10. class TestConfig(unittest.TestCase):
  11. base_url = 'http://127.0.0.1:8008/api'
  12. config_id = 0
  13. def setUp(self):
  14. pass
  15. def tearDown(self):
  16. pass
  17. # # 创建 JimV 配置
  18. # def test_11_create(self):
  19. # payload = {
  20. # "glusterfs_volume": "gv0",
  21. # "vm_network": "net-br0",
  22. # "vm_manage_network": "net-br0",
  23. # "start_ip": "10.10.3.1",
  24. # "end_ip": "10.10.6.254",
  25. # "start_vnc_port": 15900,
  26. # "netmask": "255.255.240.0",
  27. # "gateway": "10.10.15.254",
  28. # "dns1": "10.1.17.1",
  29. # "dns2": "223.5.5.5",
  30. # "rsa_private": "",
  31. # "rsa_public": ""
  32. # }
  33. #
  34. # url = TestConfig.base_url + '/config'
  35. # headers = {'content-type': 'application/json'}
  36. # r = requests.post(url, data=json.dumps(payload), headers=headers)
  37. # j_r = json.loads(r.content)
  38. # print json.dumps(j_r, ensure_ascii=False)
  39. # TestConfig.config_id = j_r['data']['id']
  40. # self.assertEqual('200', j_r['state']['code'])
  41. # 获取配置
  42. # def test_12_get(self):
  43. # url = TestConfig.base_url + '/config'
  44. # headers = {'content-type': 'application/json'}
  45. # r = requests.get(url, 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_13_update(self):
  51. # payload = {
  52. # "glusterfs_volume": "gv0",
  53. # "vm_network": "net-br0",
  54. # "vm_manage_network": "net-br0",
  55. # "start_ip": "10.10.7.1",
  56. # "end_ip": "10.10.9.254",
  57. # "start_vnc_port": 15900,
  58. # "netmask": "255.255.240.0",
  59. # "gateway": "10.10.15.254",
  60. # "dns1": "223.5.5.5",
  61. # "dns2": "8.8.8.8",
  62. # "rsa_public": "what?",
  63. # "rsa_private": ""
  64. # }
  65. #
  66. # url = TestConfig.base_url + '/config'
  67. # headers = {'content-type': 'application/json'}
  68. # r = requests.patch(url, data=json.dumps(payload), headers=headers)
  69. # j_r = json.loads(r.content)
  70. # print json.dumps(j_r, ensure_ascii=False)
  71. # self.assertEqual('200', j_r['state']['code'])
  72. # # 校验更新结果
  73. # def test_14_get(self):
  74. # url = TestConfig.base_url + '/config'
  75. # headers = {'content-type': 'application/json'}
  76. # r = requests.get(url, headers=headers)
  77. # j_r = json.loads(r.content)
  78. # print json.dumps(j_r, ensure_ascii=False)
  79. # self.assertEqual('200', j_r['state']['code'])
  80. # self.assertEqual('what?', j_r['data']['rsa_public'])
  81. #
  82. # # 删除配置
  83. # def test_15_delete(self):
  84. # url = TestConfig.base_url + '/config'
  85. # headers = {'content-type': 'application/json'}
  86. # r = requests.delete(url, headers=headers)
  87. # self.assertEqual(405, r.status_code)
  88. if __name__ == '__main__':
  89. unittest.main()