提交 2b7a59c1 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!70 文档补充删除 tracking 用法,补充删除接口测试用例

Merge pull request !70 from chenyanpanHW/master
......@@ -261,7 +261,21 @@ patch-tracking-cli query --server <LISTEN> --table issue
patch-tracking-cli query --server 127.0.0.1:5001 --table issue
```
### 4.4 码云查看 issue 及 PR
### 4.4 删除 Tracking 跟踪项数据
```shell script
patch-tracking-cli delete --server SERVER --user USER --password PWD --table TABLE --repo REPO [--branch BRANCH]
```
可以删除指定repo和branch的单条数据;也可直接删除指定repo下所有branch的数据。
例如:
```shell script
patch-tracking-cli delete --server 127.0.0.1:5001 --user admin --password Test@123 --repo testPatchTrack/testPatch1 --branch master
```
### 4.5 码云查看 issue 及 PR
登录Gitee上进行跟踪的软件项目,在该项目的Issues和Pull Requests页签下,可以查看到名为`[patch tracking] TIME`,例如` [patch tracking] 20200713101548`的条目。
......
......@@ -24,6 +24,7 @@ class ResponseCode:
DELETE_DB_ERROR = "6001"
CONFIGFILE_PATH_EMPTY = "6002"
DIS_CONNECTION_DB = "6003"
DELETE_DB_NOT_FOUND = "6005"
CODE_MSG_MAP = {
SUCCESS: "Successful Operation!",
......@@ -36,7 +37,8 @@ class ResponseCode:
GITEE_CONNECTION_ERROR: "Unable to connect to the gitee",
DELETE_DB_ERROR: "Failed to delete database",
CONFIGFILE_PATH_EMPTY: "Initialization profile does not exist or cannot be found",
DIS_CONNECTION_DB: "Unable to connect to the database, check the database configuration"
DIS_CONNECTION_DB: "Unable to connect to the database, check the database configuration",
DELETE_DB_NOT_FOUND: "The tracking you want to delete does not exist"
}
@classmethod
......
......@@ -30,14 +30,23 @@ def delete():
try:
if "branch" in keys:
if Tracking.query.filter(Tracking.repo == input_params['repo'], Tracking.branch == input_params['branch']):
if Tracking.query.filter(Tracking.repo == input_params['repo'],
Tracking.branch == input_params['branch']).first():
delete_tracking(input_params['repo'], input_params['branch'])
logger.info('Delete tracking repo: %s, branch: %s', input_params['repo'], input_params['branch'])
return ResponseCode.ret_message(code=ResponseCode.SUCCESS)
else:
logger.info('Delete tracking repo: %s, branch: %s not found.', input_params['repo'],
input_params['branch'])
return ResponseCode.ret_message(code=ResponseCode.DELETE_DB_NOT_FOUND)
else:
if Tracking.query.filter(Tracking.repo == input_params['repo']):
if Tracking.query.filter(Tracking.repo == input_params['repo']).first():
delete_tracking(input_params['repo'])
logger.info('Delete tracking repo: %s', input_params['repo'])
return ResponseCode.ret_message(code=ResponseCode.SUCCESS)
return ResponseCode.ret_message(code=ResponseCode.SUCCESS)
else:
logger.info('Delete tracking repo: %s not found.', input_params['repo'])
return ResponseCode.ret_message(code=ResponseCode.DELETE_DB_NOT_FOUND)
except SQLAlchemyError as err:
return ResponseCode.ret_message(code=ResponseCode.DELETE_DB_ERROR, data=err)
......
......@@ -2,6 +2,7 @@
flask app
"""
import logging.config
import os
import sys
from flask import Flask
from patch_tracking.api.issue import issue
......@@ -33,7 +34,8 @@ def check_settings_conf():
sys.exit()
app.config.from_pyfile("settings.conf")
settings_file = os.path.join(os.path.abspath(os.curdir), "settings.conf")
app.config.from_pyfile(settings_file)
check_settings_conf()
GITHUB_ACCESS_TOKEN = app.config['GITHUB_ACCESS_TOKEN']
......
......@@ -21,10 +21,7 @@ def query_table(args):
if args.table == "tracking":
url = '/'.join(['https:/', server, 'tracking'])
if args.branch and args.repo:
params = {'repo': args.repo, 'branch': args.branch}
else:
params = {'repo': args.repo}
params = {'repo': args.repo, 'branch': args.branch}
try:
ret = requests.get(url, params=params, verify=False)
if ret.status_code == 200 and ret.json()['code'] == '2001':
......@@ -119,6 +116,9 @@ def params_input_track(params, file_path=None):
"""
load tracking from command line arguments
"""
if not check_add_param(params):
return 'error', 'Check input params error'
if add_param_check_url(params, file_path) == 'error':
return 'error', 'Check input params error.'
......@@ -156,6 +156,19 @@ def params_input_track(params, file_path=None):
return 'error', 'Unexpected Error.'
def check_add_param(params):
success = True
required_params = ["repo", "branch", "scm_repo", "scm_branch", "version_control", "enabled"]
miss_params = list()
for param in required_params:
if param not in params or not params[param]:
miss_params.append(param)
success = False
if not success:
print("patch_tracking_cli add: error: the following arguments are required: --{}".format(", --".join(miss_params)))
return success
def add(args):
"""
add tracking
......@@ -212,20 +225,19 @@ def delete(args):
if ret.status_code == 200 and ret.json()['code'] == '2001':
print('Tracking delete successfully.')
return
elif ret.status_code == 200 and ret.json()['code'] == '6005':
print('Delete Nothing. Tracking not exist.')
return
print("Tracking delete failed. Error: %s", ret)
print("Tracking delete failed. Error: {}".format(ret.text))
except Exception as exception:
print('Error: Connect server error: %s', str(exception))
print('Connect server error: ' + str(exception))
def query(args):
"""
query table data
"""
if args.branch and not args.repo:
print(query_usage)
return
query table data
"""
status, ret = query_table(args)
if status == "success":
df = pandas.DataFrame.from_dict(ret.json()["data"], orient="columns")
......@@ -266,16 +278,16 @@ def dir_input_track(dir_path, args):
load tracking from dir
"""
if os.path.exists(dir_path) and os.path.isdir(dir_path):
for root, _, files in os.walk(dir_path):
if not files:
print('error: dir path empty')
return
for file in files:
if os.path.splitext(file)[-1] == ".yaml":
file_path = os.path.join(root, file)
file_input_track(file_path, args)
else:
print('Please input yaml file. Error in {}'.format(file))
dir_files = os.listdir(dir_path)
if not dir_files:
print('error: dir path empty')
return
for file in dir_files:
if os.path.isfile(os.path.join(dir_path, file)) and os.path.splitext(file)[-1] == ".yaml":
file_path = os.path.join(dir_path, file)
file_input_track(file_path, args)
else:
print('Please input yaml file. Error in {}'.format(file))
else:
print('error: dir path error. Params error in {}'.format(dir_path))
......@@ -304,7 +316,7 @@ add_usage = """
%(prog)s --server SERVER --user USER --password PASSWORD --file FILE
%(prog)s --server SERVER --user USER --password PASSWORD --dir DIR"""
parser_add = subparsers.add_parser(
'add', parents=[common_parser, authentication_parser], help="add tracking", usage=add_usage
'add', parents=[common_parser, authentication_parser], help="add tracking", usage=add_usage, allow_abbrev=False
)
parser_add.set_defaults(func=add)
parser_add.add_argument("--version_control", choices=['github'], help="upstream version control system")
......@@ -319,7 +331,7 @@ parser_add.add_argument('--dir', help='import patch tracking from files in direc
# delete
del_usage = """
%(prog)s --server SERVER --table TABLE --repo REPO [--branch BRANCH]"""
parser_delete = subparsers.add_parser('delete', parents=[common_parser, authentication_parser], help="delete tracking")
parser_delete = subparsers.add_parser('delete', parents=[common_parser, authentication_parser], help="delete tracking", allow_abbrev=False)
parser_delete.set_defaults(func=delete)
parser_delete.add_argument("--repo", required=True, help="source package repository")
parser_delete.add_argument("--branch", help="source package branch")
......@@ -327,7 +339,7 @@ parser_delete.add_argument("--branch", help="source package branch")
# query
query_usage = """
%(prog)s --server SERVER --table {tracking,issue} [--repo REPO] [--branch BRANCH]"""
parser_query = subparsers.add_parser('query', parents=[common_parser], help="query tracking/issue")
parser_query = subparsers.add_parser('query', parents=[common_parser], help="query tracking/issue", allow_abbrev=False)
parser_query.set_defaults(func=query)
parser_query.add_argument("--table", required=True, choices=["tracking", "issue"], help="query tracking or issue")
parser_query.add_argument("--repo", help="source package repository")
......
# server settings
LISTEN = "127.0.0.1:5001"
# GitHub API settings
GITHUB_ACCESS_TOKEN = "<GITHUB_ACCESS_TOKEN>"
# Gitee API settings
GITEE_ACCESS_TOKEN = "<GITEE_ACCESS_TOKEN>"
# Time interval
SCAN_DB_INTERVAL = 3600
# username
USER = "<USER>"
# password
PASSWORD = "<PASSWORD>"
......@@ -167,12 +167,12 @@ class TestTracking(unittest.TestCase):
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(
ResponseCode.INPUT_PARAMETERS_ERROR, resp_dict.get("code"), msg="Error in status code return"
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.INPUT_PARAMETERS_ERROR),
ResponseCode.CODE_MSG_MAP.get(ResponseCode.SUCCESS),
resp_dict.get("msg"),
msg="Error in status code return"
)
......@@ -395,6 +395,38 @@ class TestTracking(unittest.TestCase):
self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertEqual(resp_dict.get("data"), None, msg="Error in data information return")
def test_delete_data(self):
"""
The POST interface inserts data
:return:
"""
data = {
"version_control": "github",
"scm_repo": "test_delete",
"scm_branch": "test_delete",
"scm_commit": "test_delete",
"repo": "test_delete1",
"branch": "test_delete1",
"enabled": 0
}
self.client.post("/tracking", json=data, content_type="application/json", headers=self.auth)
resp = self.client.delete("/tracking?repo=test_delete1&branch=test_delete1", content_type="application/json", headers=self.auth)
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")
def test_delete_not_found(self):
"""
The POST interface inserts data
:return:
"""
resp = self.client.delete("/tracking?repo=not_found1&branch=not_found1", content_type="application/json", headers=self.auth)
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.DELETE_DB_NOT_FOUND, resp_dict.get("code"), msg="Error in status code return")
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册