Explorar o código

更新测试脚本

James Iter %!s(int64=9) %!d(string=hai) anos
pai
achega
60fc0e9103
Modificáronse 2 ficheiros con 38 adicións e 54 borrados
  1. 36 36
      tests/test_os_init.py
  2. 2 18
      tests/test_os_init_write.py

+ 36 - 36
tests/test_os_init.py

@@ -24,19 +24,19 @@ class TestOSInit(unittest.TestCase):
     def tearDown(self):
         pass
 
-    # # 创建系统初始化组
-    # def test_11_create(self):
-    #     payload = {
-    #         "name": 'CentOS-Systemd',
-    #         "remark": u'用作红帽 Systemd 系列的系统初始化。初始化操作依据 CentOS 7 来实现。'
-    #     }
-    #
-    #     url = TestOSInit.base_url + '/os_init'
-    #     headers = {'content-type': 'application/json'}
-    #     r = requests.post(url, data=json.dumps(payload), headers=headers)
-    #     j_r = json.loads(r.content)
-    #     print json.dumps(j_r, ensure_ascii=False)
-    #     self.assertEqual('200', j_r['state']['code'])
+    # 创建系统初始化组
+    def test_11_create(self):
+        payload = {
+            "name": 'CentOS-Systemd',
+            "remark": u'用作红帽 Systemd 系列的系统初始化。初始化操作依据 CentOS 7 来实现。'
+        }
+
+        url = TestOSInit.base_url + '/os_init'
+        headers = {'content-type': 'application/json'}
+        r = requests.post(url, data=json.dumps(payload), headers=headers)
+        j_r = json.loads(r.content)
+        print json.dumps(j_r, ensure_ascii=False)
+        self.assertEqual('200', j_r['state']['code'])
 
     # 获取系统初始化组列表
     def test_12_get(self):
@@ -48,29 +48,29 @@ class TestOSInit(unittest.TestCase):
         TestOSInit.os_init_id = j_r['data'][0]['id']
         self.assertEqual('200', j_r['state']['code'])
 
-    # # 创建更新系统初始化组
-    # def test_13_update(self):
-    #     payload = {
-    #         "name": 'RedHat-Systemd'
-    #     }
-    #
-    #     url = TestOSInit.base_url + '/os_init/' + TestOSInit.os_init_id.__str__()
-    #     headers = {'content-type': 'application/json'}
-    #     r = requests.patch(url, data=json.dumps(payload), headers=headers)
-    #     j_r = json.loads(r.content)
-    #     print json.dumps(j_r, ensure_ascii=False)
-    #     self.assertEqual('200', j_r['state']['code'])
-    #
-    # # 校验系统初始化组列表更新结果
-    # def test_14_get(self):
-    #     url = TestOSInit.base_url + '/os_inits'
-    #     headers = {'content-type': 'application/json'}
-    #     r = requests.get(url, headers=headers)
-    #     j_r = json.loads(r.content)
-    #     print json.dumps(j_r, ensure_ascii=False)
-    #     self.assertEqual('200', j_r['state']['code'])
-    #     self.assertEqual('RedHat-Systemd', j_r['data'][0]['name'])
-    #
+    # 创建更新系统初始化组
+    def test_13_update(self):
+        payload = {
+            "name": 'RedHat-Systemd'
+        }
+
+        url = TestOSInit.base_url + '/os_init/' + TestOSInit.os_init_id.__str__()
+        headers = {'content-type': 'application/json'}
+        r = requests.patch(url, data=json.dumps(payload), headers=headers)
+        j_r = json.loads(r.content)
+        print json.dumps(j_r, ensure_ascii=False)
+        self.assertEqual('200', j_r['state']['code'])
+
+    # 校验系统初始化组列表更新结果
+    def test_14_get(self):
+        url = TestOSInit.base_url + '/os_inits'
+        headers = {'content-type': 'application/json'}
+        r = requests.get(url, headers=headers)
+        j_r = json.loads(r.content)
+        print json.dumps(j_r, ensure_ascii=False)
+        self.assertEqual('200', j_r['state']['code'])
+        self.assertEqual('RedHat-Systemd', j_r['data'][0]['name'])
+
     # 删除系统初始化组列表更新结果
     def test_15_delete(self):
         url = TestOSInit.base_url + '/os_init/' + TestOSInit.os_init_id.__str__()

+ 2 - 18
tests/test_os_init_write.py

@@ -16,7 +16,7 @@ __copyright__ = '(c) 2017 by James Iter.'
 class TestOSInitWrite(unittest.TestCase):
 
     base_url = 'http://127.0.0.1:8008/api'
-    os_init_id = 0
+    os_init_id = 3
     os_init_write_id = 0
 
     def setUp(self):
@@ -101,22 +101,7 @@ class TestOSInitWrite(unittest.TestCase):
         TestOSInitWrite.os_init_write_id = j_r['data']['id']
         self.assertEqual('200', j_r['state']['code'])
 
-    # 添加系统初始化操作
-    def test_24_create(self):
-        payload = {
-            "os_init_id": TestOSInitWrite.os_init_id,
-            "path": "/etc/hostname",
-            "content": "{HOSTNAME}"
-        }
-
-        url = TestOSInitWrite.base_url + '/os_init_write'
-        headers = {'content-type': 'application/json'}
-        r = requests.post(url, data=json.dumps(payload), headers=headers)
-        j_r = json.loads(r.content)
-        print json.dumps(j_r, ensure_ascii=False)
-        self.assertEqual('40901', j_r['state']['sub']['code'])
-
-    def test_25_get(self):
+    def test_25_get_list(self):
         url = TestOSInitWrite.base_url + '/os_init_writes'
         headers = {'content-type': 'application/json'}
         r = requests.get(url, headers=headers)
@@ -126,7 +111,6 @@ class TestOSInitWrite(unittest.TestCase):
 
     def test_26_update(self):
         payload = {
-            "os_init_id": TestOSInitWrite.os_init_id,
             "path": "/etc/hostname",
             "content": "{HOSTNAME}"
         }