提交 20de8b73 编写于 作者: S solarhu 提交者: Gitee

!21 Add test cases and modify functional code

Merge pull request !21 from 包成强/master
......@@ -127,10 +127,6 @@ class BeDepend:
source_name = obj.source_name
if obj.bebuild_src_name:
# Determine if the source package has been checked
if obj.bebuild_src_name not in self.source_name_set:
self.source_name_set.add(obj.bebuild_src_name)
source_id_list.append(obj.bebuild_src_id)
parent_node = obj.bebuild_src_name
be_type = "build"
# Call the spell dictionary function
......@@ -141,12 +137,12 @@ class BeDepend:
parent_node,
be_type)
if obj.bebuild_src_name not in self.source_name_set:
self.source_name_set.add(obj.bebuild_src_name)
source_id_list.append(obj.bebuild_src_id)
if obj.bin_name:
# Determine if the bin package has been checked
if obj.bin_name not in self.bin_name_set:
self.bin_name_set.add(obj.bin_name)
bin_id_list.append(obj.bin_id)
parent_node = obj.bin_name
be_type = "install"
# Call the spell dictionary function
......@@ -156,6 +152,11 @@ class BeDepend:
obj.search_bin_version,
parent_node,
be_type)
if obj.bin_name not in self.bin_name_set:
self.bin_name_set.add(obj.bin_name)
bin_id_list.append(obj.bin_id)
# withsubpack=1
if self.with_sub_pack == "1":
if obj.install_depend_src_name not in self.source_name_set:
......@@ -190,6 +191,7 @@ class BeDepend:
]
]
else:
if [parent_node,be_type] not in self.result_dict[key][-1]:
self.result_dict[key][-1].append([
parent_node,
be_type
......
[
{
"input": {
"packagename": "A",
"dbname":"openEuler-20.03-LTS"
},
"output": {
"code": "2001",
"data": {
"A1": [
"A",
"0.0.23b",
"openEuler-20.03-LTS",
[
[
"B",
"build"
],
[
"D",
"build"
],
[
"D1",
"install"
],
[
"B1",
"install"
]
]
],
"A2": [
"A",
"0.0.23b",
"openEuler-20.03-LTS",
[
[
"C",
"build"
],
[
"C1",
"install"
],
[
"A1",
"install"
]
]
],
"A_src": [
"source",
"0.0.23b",
"openEuler-20.03-LTS",
[
[
"root",
null
]
]
],
"B1": [
"B",
"0.0.2",
"openEuler-20.03-LTS",
[
[
"A",
"build"
],
[
"D",
"build"
]
]
],
"B2": [
"B",
"0.0.2",
"openEuler-20.03-LTS",
[
[
"C",
"build"
]
]
],
"C1": [
"C",
"0.1",
"openEuler-20.03-LTS",
[
[
"A",
"build"
],
[
"B",
"build"
],
[
"A2",
"install"
],
[
"B2",
"install"
]
]
],
"D1": [
"D",
"0.11",
"openEuler-20.03-LTS",
[
[
"D2",
"install"
],
[
"A2",
"install"
]
]
]
},
"msg": "Successful Operation!"
}}
]
......@@ -9,9 +9,10 @@ def execute_operate():
# Import test cases and calls related to query database
from test.test_module.dependent_query_tests.test_build_depend import test_build_depend_suit
from test.test_module.packages_tests.test_packages import test_packages_suit
from test.test_module.dependent_query_tests.test_be_depend import test_be_depend_suit
test_build_depend_suit()
test_packages_suit()
test_be_depend_suit()
# Import test cases and calls related to the operation database
# like update database
......
# -*- coding:utf-8 -*-
"""
Less transmission is always parameter transmission
"""
import unittest
import json
from test.base_code.read_data_base import ReadTestBase
from test.base_code.common_test_code import compare_two_values, get_correct_json_by_filename
from packageship.application.apps.package.function.constants import ResponseCode
class TestBeDepend(ReadTestBase):
'''
The dependencies of the package are tested
'''
def test_lack_parameter(self):
"""
Less transmission is always parameter transmission
"""
# No arguments passed
resp = self.client.post("/packages/findBeDepend",
data='{}',
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.PARAM_ERROR,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(
ResponseCode.CODE_MSG_MAP.get(
ResponseCode.PARAM_ERROR),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNone(
resp_dict.get("data"),
msg="Error in data information return")
# Only the packagename
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"packagename": "CUnit",
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.PARAM_ERROR,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(
ResponseCode.CODE_MSG_MAP.get(
ResponseCode.PARAM_ERROR),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNone(
resp_dict.get("data"),
msg="Error in data information return")
# Only the withsubpack
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"withsubpack": "0",
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.PARAM_ERROR,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(
ResponseCode.CODE_MSG_MAP.get(
ResponseCode.PARAM_ERROR),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNone(
resp_dict.get("data"),
msg="Error in data information return")
# Only the dbname
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"dbname": "openEuler-20.03-LTS",
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.PARAM_ERROR,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(
ResponseCode.CODE_MSG_MAP.get(
ResponseCode.PARAM_ERROR),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNone(
resp_dict.get("data"),
msg="Error in data information return")
# Don't preach withsubpack
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"packagename": "A",
"dbname": "openEuler-20.03-LTS"
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.SUCCESS,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.CODE_MSG_MAP.get(ResponseCode.SUCCESS),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNotNone(
resp_dict.get("data"),
msg="Error in data information return")
# Don't preach dbname
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"packagename": "CUnit",
"withsubpack": "0"
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.PARAM_ERROR,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(
ResponseCode.CODE_MSG_MAP.get(
ResponseCode.PARAM_ERROR),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNone(
resp_dict.get("data"),
msg="Error in data information return")
# Don't preach packagename
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"dbname": "openEuler-20.03-LTS",
"withsubpack": "0"
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.PARAM_ERROR,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(
ResponseCode.CODE_MSG_MAP.get(
ResponseCode.PARAM_ERROR),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNone(
resp_dict.get("data"),
msg="Error in data information return")
# All incoming withsubpack=0
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"packagename": "A",
"dbname": "openEuler-20.03-LTS",
"withsubpack": "0"
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.SUCCESS,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.CODE_MSG_MAP.get(ResponseCode.SUCCESS),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNotNone(
resp_dict.get("data"),
msg="Error in data information return")
# All incoming withsubpack=1
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"packagename": "A",
"dbname": "openEuler-20.03-LTS",
"withsubpack": "1"
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.SUCCESS,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.CODE_MSG_MAP.get(ResponseCode.SUCCESS),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNotNone(
resp_dict.get("data"),
msg="Error in data information return")
def test_wrong_parameter(self):
"""
Parameter error
"""
# packagename Parameter error
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"packagename": "詹姆斯",
"dbname": "openEuler-20.03-LTS",
"withsubpack": "0"
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.PACK_NAME_NOT_FOUND,
resp_dict.get("code"),
msg="Error in status code return!")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(
ResponseCode.CODE_MSG_MAP.get(
ResponseCode.PACK_NAME_NOT_FOUND),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNone(
resp_dict.get("data"),
msg="Error in data information return")
# dbname Parameter error
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"packagename": "ATpy",
"dbname": "asdfgjhk",
"withsubpack": "0"
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.DB_NAME_ERROR,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(
ResponseCode.CODE_MSG_MAP.get(
ResponseCode.DB_NAME_ERROR),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNone(
resp_dict.get("data"),
msg="Error in data information return")
# withsubpack Parameter error
resp = self.client.post("/packages/findBeDepend",
data=json.dumps({
"packagename": "CUnit",
"dbname": "openEuler-20.03-LTS",
"withsubpack": "3"
}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.PARAM_ERROR,
resp_dict.get("code"),
msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(
ResponseCode.CODE_MSG_MAP.get(
ResponseCode.PARAM_ERROR),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNone(
resp_dict.get("data"),
msg="Error in data information return")
def test_true_params_result(self):
"""
Results contrast
"""
correct_list = get_correct_json_by_filename("be_depend")
self.assertNotEqual([], correct_list, msg="Error reading JSON file")
for correct_data in correct_list:
input_value = correct_data["input"]
resp = self.client.post("/packages/findBeDepend",
data=json.dumps(input_value),
content_type="application/json")
output_for_input = correct_data["output"]
resp_dict = json.loads(resp.data)
self.assertTrue(compare_two_values(output_for_input, resp_dict),
msg="The answer is not correct")
def test_be_depend_suit():
"""
Start the test case function
"""
print("---TestBeDepend START---")
suite = unittest.TestSuite()
suite.addTest(TestBeDepend("test_lack_parameter"))
suite.addTest(TestBeDepend("test_wrong_parameter"))
suite.addTest(TestBeDepend("test_true_params_result"))
unittest.TextTestRunner().run(suite)
# if __name__ == '__main__':
# unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册