Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
openEuler-Advisor
提交
a2bba5ca
O
openEuler-Advisor
项目概览
openeuler
/
openEuler-Advisor
通知
30
Star
4
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
openEuler-Advisor
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a2bba5ca
编写于
7月 02, 2020
作者:
J
jiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modify the packages interface and add test cases
上级
20de8b73
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
781 addition
and
50 deletion
+781
-50
packageship/packageship/application/apps/package/view.py
packageship/packageship/application/apps/package/view.py
+6
-7
packageship/test/common_files/correct_test_result_json/get_repodatas.json
.../common_files/correct_test_result_json/get_repodatas.json
+9
-0
packageship/test/common_files/correct_test_result_json/get_single_package.json
...on_files/correct_test_result_json/get_single_package.json
+15
-0
packageship/test/common_files/correct_test_result_json/packages.json
.../test/common_files/correct_test_result_json/packages.json
+91
-0
packageship/test/run_init_system_tests.py
packageship/test/run_init_system_tests.py
+12
-0
packageship/test/run_read_tests.py
packageship/test/run_read_tests.py
+22
-0
packageship/test/run_tests.py
packageship/test/run_tests.py
+0
-21
packageship/test/run_write_test.py
packageship/test/run_write_test.py
+14
-0
packageship/test/test_module/init_system_tests/test_importdata.py
...hip/test/test_module/init_system_tests/test_importdata.py
+108
-22
packageship/test/test_module/repodatas_test/__init__.py
packageship/test/test_module/repodatas_test/__init__.py
+0
-0
packageship/test/test_module/repodatas_test/test_delete_repodatas.py
.../test/test_module/repodatas_test/test_delete_repodatas.py
+108
-0
packageship/test/test_module/repodatas_test/test_get_repodatas.py
...hip/test/test_module/repodatas_test/test_get_repodatas.py
+73
-0
packageship/test/test_module/single_package_tests/__init__.py
...ageship/test/test_module/single_package_tests/__init__.py
+0
-0
packageship/test/test_module/single_package_tests/test_get_singlepack.py
...t/test_module/single_package_tests/test_get_singlepack.py
+161
-0
packageship/test/test_module/single_package_tests/test_update_singlepack.py
...est_module/single_package_tests/test_update_singlepack.py
+162
-0
未找到文件。
packageship/packageship/application/apps/package/view.py
浏览文件 @
a2bba5ca
...
...
@@ -81,8 +81,13 @@ class Packages(Resource):
return
jsonify
(
ResponseCode
.
response_json
(
ResponseCode
.
SUCCESS
,
response
)
)
if
dbname
not
in
dbpreority
:
return
jsonify
(
ResponseCode
.
response_json
(
ResponseCode
.
DB_NAME_ERROR
)
)
response
=
get_packages
(
dbname
)
return
jsonify
(
ResponseCode
.
response_json
(
ResponseCode
.
DB_NAME_ERROR
)
ResponseCode
.
response_json
(
ResponseCode
.
SUCCESS
,
response
)
)
# Database queries data and catches exceptions
except
DisconnectionError
as
dis_connection_error
:
...
...
@@ -90,12 +95,6 @@ class Packages(Resource):
return
jsonify
(
ResponseCode
.
response_json
(
ResponseCode
.
DIS_CONNECTION_DB
))
except
(
AttributeError
,
Error
)
as
attri_error
:
current_app
.
logger
.
error
(
attri_error
)
return
jsonify
(
ResponseCode
.
response_json
(
ResponseCode
.
PACK_NAME_NOT_FOUND
)
)
class
SinglePack
(
Resource
):
'''
...
...
packageship/test/common_files/correct_test_result_json/get_repodatas.json
0 → 100644
浏览文件 @
a2bba5ca
[{
"database_name"
:
"openEuler-20.03-LTS"
,
"priority"
:
1
,
"status"
:
"enable"
},
{
"database_name"
:
"openEuler-20.04-LTS"
,
"priority"
:
2
,
"status"
:
"enable"
}]
\ No newline at end of file
packageship/test/common_files/correct_test_result_json/get_single_package.json
0 → 100644
浏览文件 @
a2bba5ca
[{
"buildDep"
:
[
"B1"
,
"C1"
],
"dbname"
:
"openEuler-20.03-LTS"
,
"downloadURL"
:
null
,
"license"
:
"GPLv2+ and BSD and MIT and IBM"
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"A"
,
"sourceURL"
:
"http://play0ad.com"
,
"subpack"
:
{
"A1"
:
[
"A2"
],
"A2"
:
[
"C1"
,
"D1"
]
},
"version"
:
"0.0.23b"
}]
\ No newline at end of file
packageship/test/common_files/correct_test_result_json/packages.json
0 → 100644
浏览文件 @
a2bba5ca
[{
"dbname"
:
"openEuler-20.03-LTS"
,
"downloadURL"
:
null
,
"license"
:
"GPLv2+ and BSD and MIT and IBM"
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"A"
,
"sourceURL"
:
"http://play0ad.com"
,
"version"
:
"0.0.23b"
},
{
"dbname"
:
"openEuler-20.03-LTS"
,
"downloadURL"
:
null
,
"license"
:
null
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"B"
,
"sourceURL"
:
null
,
"version"
:
"0.0.2"
},
{
"dbname"
:
"openEuler-20.03-LTS"
,
"downloadURL"
:
null
,
"license"
:
null
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"C"
,
"sourceURL"
:
null
,
"version"
:
"0.1"
},
{
"dbname"
:
"openEuler-20.03-LTS"
,
"downloadURL"
:
null
,
"license"
:
null
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"D"
,
"sourceURL"
:
null
,
"version"
:
"0.11"
},
{
"dbname"
:
"openEuler-20.04-LTS"
,
"downloadURL"
:
null
,
"license"
:
"GPLv2+ and BSD and MIT and IBM"
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"A"
,
"sourceURL"
:
"http://play0ad.com"
,
"version"
:
"0.0.23b"
},
{
"dbname"
:
"openEuler-20.04-LTS"
,
"downloadURL"
:
null
,
"license"
:
null
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"B"
,
"sourceURL"
:
null
,
"version"
:
"0.0.3"
},
{
"dbname"
:
"openEuler-20.04-LTS"
,
"downloadURL"
:
null
,
"license"
:
null
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"C"
,
"sourceURL"
:
null
,
"version"
:
"0.1"
},
{
"dbname"
:
"openEuler-20.04-LTS"
,
"downloadURL"
:
null
,
"license"
:
null
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"D"
,
"sourceURL"
:
null
,
"version"
:
"0.12"
},
{
"dbname"
:
"openEuler-20.04-LTS"
,
"downloadURL"
:
null
,
"license"
:
null
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"E"
,
"sourceURL"
:
null
,
"version"
:
"0.4"
},
{
"dbname"
:
"openEuler-20.04-LTS"
,
"downloadURL"
:
null
,
"license"
:
null
,
"maintainer"
:
null
,
"maintainlevel"
:
null
,
"sourceName"
:
"F"
,
"sourceURL"
:
null
,
"version"
:
"1"
}]
packageship/test/run_init_system_tests.py
0 → 100644
浏览文件 @
a2bba5ca
# -*- coding:utf-8 -*-
"""Test case of init data"""
from
test.test_module.init_system_tests.test_importdata
import
test_import_data_suit
def
execute_init
():
"""Test case of init data"""
test_import_data_suit
()
if
__name__
==
'__main__'
:
execute_init
()
packageship/test/run_read_tests.py
0 → 100644
浏览文件 @
a2bba5ca
# -*- coding:utf-8 -*-
"""
Test case of reading data
"""
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.single_package_tests.test_get_singlepack
import
test_get_single_package_suit
from
test.test_module.repodatas_test.test_get_repodatas
import
test_get_repodatas_suit
from
test.test_module.dependent_query_tests.test_be_depend
import
test_be_depend_suit
def
execute_read
():
"""Test case of reading data"""
test_build_depend_suit
()
test_packages_suit
()
test_get_single_package_suit
()
test_get_repodatas_suit
()
test_be_depend_suit
()
if
__name__
==
'__main__'
:
execute_read
()
packageship/test/run_tests.py
已删除
100644 → 0
浏览文件 @
20de8b73
# -*- coding:utf-8 -*-
def
execute_operate
():
# put import_data_test first
from
test.test_module.init_system_tests.test_importdata
import
test_import_data_suit
test_import_data_suit
()
# 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
if
__name__
==
'__main__'
:
execute_operate
()
packageship/test/run_write_test.py
0 → 100644
浏览文件 @
a2bba5ca
# -*- coding:utf-8 -*-
"""Test case of writing data"""
from
test.test_module.repodatas_test.test_delete_repodatas
import
test_delete_repodatas_suit
from
test.test_module.single_package_tests.test_update_singlepack
import
test_updata_single_package_suit
def
execute_operate
():
"""Test case of writing data"""
test_updata_single_package_suit
()
test_delete_repodatas_suit
()
if
__name__
==
'__main__'
:
execute_operate
()
packageship/test/test_module/init_system_tests/test_importdata.py
浏览文件 @
a2bba5ca
...
...
@@ -10,20 +10,22 @@ from packageship import system_config
try
:
system_config
.
SYS_CONFIG_PATH
=
os
.
path
.
join
(
os
.
path
.
dirname
(
system_config
.
BASE_PATH
),
'test'
,
'common_files'
,
'package.ini'
)
system_config
.
DATABASE_FILE_INFO
=
os
.
path
.
join
(
os
.
path
.
dirname
(
system_config
.
BASE_PATH
),
'test'
,
'init_system_files'
,
'database_file_info.yaml'
)
system_config
.
DATABASE_FOLDER_PATH
=
os
.
path
.
join
(
os
.
path
.
dirname
(
system_config
.
BASE_PATH
),
'test'
,
'init_system_files'
,
'dbs'
)
system_config
.
SYS_CONFIG_PATH
=
os
.
path
.
join
(
os
.
path
.
dirname
(
system_config
.
BASE_PATH
),
'test'
,
'common_files'
,
'package.ini'
)
system_config
.
DATABASE_FILE_INFO
=
os
.
path
.
join
(
os
.
path
.
dirname
(
system_config
.
BASE_PATH
),
'test'
,
'init_system_files'
,
'database_file_info.yaml'
)
system_config
.
DATABASE_FOLDER_PATH
=
os
.
path
.
join
(
os
.
path
.
dirname
(
system_config
.
BASE_PATH
),
'test'
,
'init_system_files'
,
'dbs'
)
from
test.base_code.init_config_path
import
init_config
...
...
@@ -105,7 +107,9 @@ class ImportData(unittest.TestCase):
# path is incorrect
try
:
# Back up source files
shutil
.
copyfile
(
system_config
.
SYS_CONFIG_PATH
,
system_config
.
SYS_CONFIG_PATH
+
".bak"
)
shutil
.
copyfile
(
system_config
.
SYS_CONFIG_PATH
,
system_config
.
SYS_CONFIG_PATH
+
".bak"
)
# Modify dbtype to "test"_ dbtype"
config
=
ConfigParser
()
config
.
read
(
system_config
.
SYS_CONFIG_PATH
)
...
...
@@ -122,12 +126,16 @@ class ImportData(unittest.TestCase):
finally
:
# To restore a file, delete the file first and then rename it back
os
.
remove
(
system_config
.
SYS_CONFIG_PATH
)
os
.
rename
(
system_config
.
SYS_CONFIG_PATH
+
".bak"
,
system_config
.
SYS_CONFIG_PATH
)
os
.
rename
(
system_config
.
SYS_CONFIG_PATH
+
".bak"
,
system_config
.
SYS_CONFIG_PATH
)
# Dbtype error
try
:
# Back up source files
shutil
.
copyfile
(
system_config
.
SYS_CONFIG_PATH
,
system_config
.
SYS_CONFIG_PATH
+
".bak"
)
shutil
.
copyfile
(
system_config
.
SYS_CONFIG_PATH
,
system_config
.
SYS_CONFIG_PATH
+
".bak"
)
# Modify dbtype to "test"_ dbtype"
config
=
ConfigParser
()
config
.
read
(
system_config
.
SYS_CONFIG_PATH
)
...
...
@@ -144,7 +152,84 @@ class ImportData(unittest.TestCase):
finally
:
# To restore a file, delete the file first and then rename it back
os
.
remove
(
system_config
.
SYS_CONFIG_PATH
)
os
.
rename
(
system_config
.
SYS_CONFIG_PATH
+
".bak"
,
system_config
.
SYS_CONFIG_PATH
)
os
.
rename
(
system_config
.
SYS_CONFIG_PATH
+
".bak"
,
system_config
.
SYS_CONFIG_PATH
)
def
test_dbname
(
self
):
try
:
_config_path
=
ReadConfig
().
get_system
(
'init_conf_path'
)
shutil
.
copyfile
(
_config_path
,
_config_path
+
'.bak'
)
with
open
(
_config_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
origin_yaml
=
yaml
.
load
(
f
.
read
(),
Loader
=
yaml
.
FullLoader
)
for
obj
in
origin_yaml
:
obj
[
"dbname"
]
=
""
with
open
(
_config_path
,
'w'
,
encoding
=
'utf-8'
)
as
w_f
:
yaml
.
dump
(
origin_yaml
,
w_f
)
InitDataBase
(
config_file_path
=
_config_path
).
init_data
()
with
open
(
system_config
.
DATABASE_FILE_INFO
,
'r'
,
encoding
=
'utf-8'
)
as
file_context
:
init_database_date
=
yaml
.
load
(
file_context
.
read
(),
Loader
=
yaml
.
FullLoader
)
self
.
assertEqual
(
init_database_date
,
None
,
msg
=
" Priority must be a positive integer between 0 and 100 "
)
except
Exception
as
e
:
return
finally
:
# Restore files
os
.
remove
(
_config_path
)
os
.
rename
(
_config_path
+
'.bak'
,
_config_path
)
def
test_src_db_file
(
self
):
try
:
_config_path
=
ReadConfig
().
get_system
(
'init_conf_path'
)
shutil
.
copyfile
(
_config_path
,
_config_path
+
'.bak'
)
with
open
(
_config_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
origin_yaml
=
yaml
.
load
(
f
.
read
(),
Loader
=
yaml
.
FullLoader
)
for
obj
in
origin_yaml
:
obj
[
"src_db_file"
]
=
""
with
open
(
_config_path
,
'w'
,
encoding
=
'utf-8'
)
as
w_f
:
yaml
.
dump
(
origin_yaml
,
w_f
)
InitDataBase
(
config_file_path
=
_config_path
).
init_data
()
with
open
(
system_config
.
DATABASE_FILE_INFO
,
'r'
,
encoding
=
'utf-8'
)
as
file_context
:
init_database_date
=
yaml
.
load
(
file_context
.
read
(),
Loader
=
yaml
.
FullLoader
)
self
.
assertEqual
(
init_database_date
,
None
,
msg
=
" Priority must be a positive integer between 0 and 100 "
)
except
Exception
as
e
:
return
finally
:
# Restore files
os
.
remove
(
_config_path
)
os
.
rename
(
_config_path
+
'.bak'
,
_config_path
)
def
test_priority
(
self
):
try
:
_config_path
=
ReadConfig
().
get_system
(
'init_conf_path'
)
shutil
.
copyfile
(
_config_path
,
_config_path
+
'.bak'
)
with
open
(
_config_path
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
origin_yaml
=
yaml
.
load
(
f
.
read
(),
Loader
=
yaml
.
FullLoader
)
for
obj
in
origin_yaml
:
obj
[
"priority"
]
=
"-1"
with
open
(
_config_path
,
'w'
,
encoding
=
'utf-8'
)
as
w_f
:
yaml
.
dump
(
origin_yaml
,
w_f
)
InitDataBase
(
config_file_path
=
_config_path
).
init_data
()
with
open
(
system_config
.
DATABASE_FILE_INFO
,
'r'
,
encoding
=
'utf-8'
)
as
file_context
:
init_database_date
=
yaml
.
load
(
file_context
.
read
(),
Loader
=
yaml
.
FullLoader
)
self
.
assertEqual
(
init_database_date
,
None
,
msg
=
" Priority must be a positive integer between 0 and 100 "
)
except
Exception
as
e
:
return
finally
:
# Restore files
os
.
remove
(
_config_path
)
os
.
rename
(
_config_path
+
'.bak'
,
_config_path
)
def
test_true_init_data
(
self
):
'''
...
...
@@ -192,12 +277,13 @@ class ImportData(unittest.TestCase):
def
test_import_data_suit
():
"""test_import_data_suit"""
print
(
"-----ImportData START----"
)
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
ImportData
(
"test_empty_param"
))
suite
.
addTest
(
ImportData
(
"test_wrong_param"
))
suite
.
addTest
(
ImportData
(
"test_dbname"
))
suite
.
addTest
(
ImportData
(
"test_src_db_file"
))
suite
.
addTest
(
ImportData
(
"test_priority"
))
suite
.
addTest
(
ImportData
(
"test_true_init_data"
))
unittest
.
TextTestRunner
().
run
(
suite
)
if
__name__
==
"__main__"
:
unittest
.
main
()
packageship/test/test_module/repodatas_test/__init__.py
0 → 100644
浏览文件 @
a2bba5ca
packageship/test/test_module/repodatas_test/test_delete_repodatas.py
0 → 100644
浏览文件 @
a2bba5ca
# -*- coding:utf-8 -*-
"""
test delete repodatas
"""
import
os
import
shutil
from
test.base_code.operate_data_base
import
OperateTestBase
import
unittest
import
json
from
packageship
import
system_config
# from test.base_code.operate_data_base import system_config
from
packageship.application.apps.package.function.constants
import
ResponseCode
class
TestDeleteRepodatas
(
OperateTestBase
):
"""
test delete repodata
"""
def
test_wrong_dbname
(
self
):
"""Test simulation scenario, dbname is not transmitted"""
# Scenario 1: the value passed by dbname is empty
resp
=
self
.
client
.
delete
(
"/repodatas?dbName="
)
resp_dict
=
json
.
loads
(
resp
.
data
)
# assert
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 prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertIsNone
(
resp_dict
.
get
(
"data"
),
msg
=
"Error in data information return"
)
resp
=
self
.
client
.
delete
(
"/repodatas?dbName=rr"
)
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 prompt 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_dbname
(
self
):
"""
Returns:
"""
try
:
shutil
.
copyfile
(
system_config
.
DATABASE_FILE_INFO
,
system_config
.
DATABASE_FILE_INFO
+
'.bak'
)
shutil
.
copytree
(
system_config
.
DATABASE_FOLDER_PATH
,
system_config
.
DATABASE_FOLDER_PATH
+
'.bak'
)
resp
=
self
.
client
.
delete
(
"/repodatas?dbName=openEuler-20.04-LTS"
)
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 prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertIsNone
(
resp_dict
.
get
(
"data"
),
msg
=
"Error in data information return"
)
except
Exception
as
e
:
return
None
finally
:
os
.
remove
(
system_config
.
DATABASE_FILE_INFO
)
os
.
rename
(
system_config
.
DATABASE_FILE_INFO
+
'.bak'
,
system_config
.
DATABASE_FILE_INFO
)
shutil
.
rmtree
(
system_config
.
DATABASE_FOLDER_PATH
)
os
.
rename
(
system_config
.
DATABASE_FOLDER_PATH
+
'.bak'
,
system_config
.
DATABASE_FOLDER_PATH
)
def
test_delete_repodatas_suit
():
"""unit testing"""
print
(
"---TestDeleteRepodatas START---"
)
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
TestDeleteRepodatas
(
"test_wrong_dbname"
))
suite
.
addTest
(
TestDeleteRepodatas
(
"test_true_dbname"
))
unittest
.
TextTestRunner
().
run
(
suite
)
packageship/test/test_module/repodatas_test/test_get_repodatas.py
0 → 100644
浏览文件 @
a2bba5ca
# -*- coding:utf-8 -*-
"""
test get repodatas
"""
from
test.base_code.common_test_code
import
get_correct_json_by_filename
from
test.base_code.common_test_code
import
compare_two_values
from
test.base_code.read_data_base
import
ReadTestBase
import
unittest
import
json
from
packageship.application.apps.package.function.constants
import
ResponseCode
class
TestGetRepodatas
(
ReadTestBase
):
"""
test get repodatas
"""
def
test_dbname
(
self
):
"""no dbName"""
correct_list
=
get_correct_json_by_filename
(
"get_repodatas"
)
self
.
assertNotEqual
([],
correct_list
,
msg
=
"Error reading JSON file"
)
resp
=
self
.
client
.
get
(
"/repodatas"
)
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 prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertTrue
(
compare_two_values
(
resp_dict
.
get
(
"data"
),
correct_list
),
msg
=
"Error in data information return"
)
resp
=
self
.
client
.
get
(
"/repodatas?ddd"
)
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 prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertTrue
(
compare_two_values
(
resp_dict
.
get
(
"data"
),
correct_list
),
msg
=
"Error in data information return"
)
def
test_get_repodatas_suit
():
"""unit testing"""
print
(
"---TestGetRepodatas START---"
)
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
TestGetRepodatas
(
"test_dbname"
))
unittest
.
TextTestRunner
().
run
(
suite
)
if
__name__
==
'__main__'
:
unittest
.
main
()
packageship/test/test_module/single_package_tests/__init__.py
0 → 100644
浏览文件 @
a2bba5ca
packageship/test/test_module/single_package_tests/test_get_singlepack.py
0 → 100644
浏览文件 @
a2bba5ca
# -*- coding:utf-8 -*-
"""
test_get_single_packages
"""
from
test.base_code.common_test_code
import
get_correct_json_by_filename
from
test.base_code.common_test_code
import
compare_two_values
from
test.base_code.read_data_base
import
ReadTestBase
import
unittest
import
json
from
packageship.application.apps.package.function.constants
import
ResponseCode
class
TestGetSinglePack
(
ReadTestBase
):
"""
Single package test case
"""
def
test_error_sourcename
(
self
):
"""sourceName is none or err"""
resp
=
self
.
client
.
get
(
"packages/findByPackName?dbName=openeuler-20.03-lts"
)
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 prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertIsNone
(
resp_dict
.
get
(
"data"
),
msg
=
"Error in data information return"
)
resp
=
self
.
client
.
get
(
"packages/findByPackName?sourceName=&dbName=openEuler-20.03-LTS"
)
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 prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertIsNone
(
resp_dict
.
get
(
"data"
),
msg
=
"Error in data information return"
)
resp
=
self
.
client
.
get
(
"packages/findByPackName?sourceName=test&dbName=for"
)
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 prompt 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_dbname
(
self
):
"""dbName is null or err"""
resp
=
self
.
client
.
get
(
"packages/findByPackName?sourceName=A"
)
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 prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertIsNotNone
(
resp_dict
.
get
(
"data"
),
msg
=
"Error in data information return"
)
correct_list
=
get_correct_json_by_filename
(
"get_single_package"
)
self
.
assertNotEqual
([],
correct_list
,
msg
=
"Error reading JSON file"
)
resp
=
self
.
client
.
get
(
"/packages/findByPackName?sourceName=A&dbName=openEuler-20.03-LTS"
)
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 prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertTrue
(
compare_two_values
(
resp_dict
.
get
(
"data"
),
correct_list
),
msg
=
"Error in data information return"
)
def
test_wrong_dbname
(
self
):
"""test_wrong_dbname"""
resp
=
self
.
client
.
get
(
"/packages/findByPackName?sourceName=CUnit&dbName=openEuler-20.03-lts"
)
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 prompt 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_get_single_package_suit
():
"""unit testing"""
print
(
"---TestSinglePack START---"
)
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
TestGetSinglePack
(
"test_error_sourcename"
))
suite
.
addTest
(
TestGetSinglePack
(
"test_true_dbname"
))
suite
.
addTest
(
TestGetSinglePack
(
"test_wrong_dbname"
))
unittest
.
TextTestRunner
().
run
(
suite
)
if
__name__
==
'__main__'
:
unittest
.
main
()
packageship/test/test_module/single_package_tests/test_update_singlepack.py
0 → 100644
浏览文件 @
a2bba5ca
"""TestUpdatePackage"""
# -*- coding:utf-8 -*-
from
test.base_code.operate_data_base
import
OperateTestBase
import
unittest
import
json
from
packageship.application.apps.package.function.constants
import
ResponseCode
class
TestUpdatePackage
(
OperateTestBase
):
"""TestUpdatePackage"""
def
test_empty_dbname
(
self
):
"""Parameter error"""
resp
=
self
.
client
.
put
(
"/packages/findByPackName"
,
data
=
json
.
dumps
({
"dbName"
:
""
,
"sourceName"
:
"xx"
,
"maintainer"
:
""
,
"maintainlevel"
:
"1"
}),
content_type
=
"application/json"
)
resp_dict
=
json
.
loads
(
resp
.
data
)
resp_dict
.
get
(
"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 prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertIsNone
(
resp_dict
.
get
(
"data"
),
msg
=
"Error in data information return"
)
# wrong dbname
resp
=
self
.
client
.
put
(
"/packages/findByPackName"
,
data
=
json
.
dumps
({
"dbName"
:
"xx"
,
"sourceName"
:
"xx"
,
"maintainer"
:
""
,
"maintainlevel"
:
"1"
}),
content_type
=
"application/json"
)
resp_dict
=
json
.
loads
(
resp
.
data
)
resp_dict
.
get
(
"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 prompt 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_empty_sourcename
(
self
):
"""Parameter error"""
resp
=
self
.
client
.
put
(
"/packages/findByPackName"
,
data
=
json
.
dumps
({
"dbName"
:
"openEuler-20.04-LTS"
,
"sourceName"
:
"xx"
,
"maintainer"
:
"1"
}),
content_type
=
"application/json"
)
resp_dict
=
json
.
loads
(
resp
.
data
)
resp_dict
.
get
(
"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 prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertIsNone
(
resp_dict
.
get
(
"data"
),
msg
=
"Error in data information return"
)
# miss maintainer maintainlevel
resp
=
self
.
client
.
put
(
"/packages/findByPackName"
,
data
=
json
.
dumps
({
"dbName"
:
"openEuler-20.04-LTS"
,
"sourceName"
:
"xx"
}),
content_type
=
"application/json"
)
resp_dict
=
json
.
loads
(
resp
.
data
)
resp_dict
.
get
(
"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 prompt 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_parram
(
self
):
"""
Returns:
"""
resp
=
self
.
client
.
put
(
"/packages/findByPackName"
,
data
=
json
.
dumps
({
"dbName"
:
"openEuler-20.04-LTS"
,
"sourceName"
:
"A"
,
"maintainer"
:
"x"
,
"maintainlevel"
:
"1"
}),
content_type
=
"application/json"
)
resp_dict
=
json
.
loads
(
resp
.
data
)
resp_dict
.
get
(
"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 prompt 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_updata_single_package_suit
():
"""unit testing"""
print
(
"---TestUpdatePackage START---"
)
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
TestUpdatePackage
(
"test_empty_dbname"
))
suite
.
addTest
(
TestUpdatePackage
(
"test_empty_sourcename"
))
suite
.
addTest
(
TestUpdatePackage
(
"test_true_parram"
))
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录