提交 491d55f9 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!103 test单元测试新增新功能内容,修改spec check字段运行test方式.并加入对应的依赖

Merge pull request !103 from tomtao/master
...@@ -296,7 +296,7 @@ def provide_(tablename, bin_provides_set): ...@@ -296,7 +296,7 @@ def provide_(tablename, bin_provides_set):
bin_provides_dict['id'] = bin_provides_obj.id bin_provides_dict['id'] = bin_provides_obj.id
bin_provides_dict['name'] = bin_provides_obj.name bin_provides_dict['name'] = bin_provides_obj.name
reqired_set = data_name.session.query( reqired_set = data_name.session.query(
BinProvides).filter_by(name=bin_provides_obj.name).all() BinRequires).filter_by(name=bin_provides_obj.name).all()
required_pkgkey_list = [ required_pkgkey_list = [
reqired_obj.pkgKey for reqired_obj in reqired_set] reqired_obj.pkgKey for reqired_obj in reqired_set]
required_bin_set = data_name.session.query(BinPack).filter( required_bin_set = data_name.session.query(BinPack).filter(
......
...@@ -10,9 +10,11 @@ BuildArch: noarch ...@@ -10,9 +10,11 @@ BuildArch: noarch
BuildRequires: python3-flask-restful python3-flask python3 python3-pyyaml python3-sqlalchemy BuildRequires: python3-flask-restful python3-flask python3 python3-pyyaml python3-sqlalchemy
BuildRequires: python3-prettytable python3-requests python3-flask-session python3-flask-script python3-marshmallow BuildRequires: python3-prettytable python3-requests python3-flask-session python3-flask-script python3-marshmallow
BuildRequires: python3-Flask-APScheduler python3-pandas python3-retrying python3-xlrd python3-XlsxWriter
Requires: python3-pip python3-flask-restful python3-flask python3 python3-pyyaml Requires: python3-pip python3-flask-restful python3-flask python3 python3-pyyaml
Requires: python3-sqlalchemy python3-prettytable python3-requests Requires: python3-sqlalchemy python3-prettytable python3-requests
Requires: python3-pyinstaller python3-flask-session python3-flask-script python3-marshmallow python3-uWSGI Requires: python3-pyinstaller python3-flask-session python3-flask-script python3-marshmallow python3-uWSGI
Requires: python3-pandas python3-dateutil python3-XlsxWriter python3-xlrd python3-Flask-APScheduler python3-retrying
%description %description
Pkgship implements rpm package dependence ,maintainer, patch query and so no. Pkgship implements rpm package dependence ,maintainer, patch query and so no.
...@@ -28,10 +30,13 @@ Pkgship implements rpm package dependence ,maintainer, patch query and so no. ...@@ -28,10 +30,13 @@ Pkgship implements rpm package dependence ,maintainer, patch query and so no.
%check %check
export TZ=Asia/Shanghai
# change log_path to solve default log_path permission denied problem # change log_path to solve default log_path permission denied problem
log_path=`pwd`/tmp/ log_path=`pwd`/tmp/
sed -i "/\[LOG\]/a\log_path=$log_path" test/common_files/package.ini sed -i "/\[LOG\]/a\log_path=$log_path" test/common_files/package.ini
%{__python3} -m unittest test/run_tests.py %{__python3} -m unittest test/init_test.py
%{__python3} -m unittest test/read_test.py
%{__python3} -m unittest test/write_test.py
rm -rf $log_path rm -rf $log_path
%post %post
......
#!/usr/bin/python3
import unittest
class TestBase(unittest.TestCase):
"""
unittest unit test basic class
"""
def response_json_format(self, response):
"""
Json data judgment of corresponding content
"""
self.assertIn("code", response, msg="Error in data format return")
self.assertIn("msg", response, msg="Error in data format return")
self.assertIn("data", response, msg="Error in data format return")
...@@ -41,7 +41,7 @@ def get_correct_json_by_filename(filename): ...@@ -41,7 +41,7 @@ def get_correct_json_by_filename(filename):
"correct_test_result_json", "correct_test_result_json",
"{}.json".format(filename)) "{}.json".format(filename))
try: try:
with open(json_path, "r") as json_fp: with open(json_path, "r", encoding='utf-8') as json_fp:
correct_list = json.loads(json_fp.read()) correct_list = json.loads(json_fp.read())
except FileNotFoundError: except FileNotFoundError:
return [] return []
......
...@@ -24,32 +24,29 @@ class MyTestResult(unittest.TestResult): ...@@ -24,32 +24,29 @@ class MyTestResult(unittest.TestResult):
"""When the use case is executed successfully""" """When the use case is executed successfully"""
self.success_case_count += 1 self.success_case_count += 1
super(MyTestResult, self).addSuccess(test) super(MyTestResult, self).addSuccess(test)
if self.verbosity > 0: sys.stderr.write('Success ')
sys.stderr.write('Success ') sys.stderr.write(str(test))
sys.stderr.write(str(test)) sys.stderr.write('\n')
sys.stderr.write('\n')
def addError(self, test, err): def addError(self, test, err):
"""When a code error causes a use case to fail""" """When a code error causes a use case to fail"""
self.err_case_count += 1 self.err_case_count += 1
super(MyTestResult, self).addError(test, err) super(MyTestResult, self).addError(test, err)
if self.verbosity > 0: sys.stderr.write('Error ')
sys.stderr.write('Error ') sys.stderr.write(str(test)+'\n')
sys.stderr.write(str(test)+'\n') _,err_info = self.errors[-1]
_,err_info = self.errors[-1] sys.stderr.write(err_info)
sys.stderr.write(err_info) sys.stderr.write('\n')
sys.stderr.write('\n')
def addFailure(self, test, err): def addFailure(self, test, err):
"""When the assertion is false""" """When the assertion is false"""
self.failure_case_count += 1 self.failure_case_count += 1
super(MyTestResult, self).addFailure(test, err) super(MyTestResult, self).addFailure(test, err)
if self.verbosity > 0: sys.stderr.write('Failure ')
sys.stderr.write('Failure ') sys.stderr.write(str(test) + '\n')
sys.stderr.write(str(test)+'\n') _, err_info = self.failures[-1]
_, err_info = self.failures[-1] sys.stderr.write(err_info)
sys.stderr.write(err_info) sys.stderr.write('\n')
sys.stderr.write('\n')
class MyTestRunner(): class MyTestRunner():
...@@ -57,11 +54,8 @@ class MyTestRunner(): ...@@ -57,11 +54,8 @@ class MyTestRunner():
Run All TestCases Run All TestCases
""" """
def __init__(self, verbosity=0):
self.verbosity = verbosity
def run(self, test): def run(self, test):
"""run MyTestResult and return result""" """run MyTestResult and return result"""
result = MyTestResult(self.verbosity) result = MyTestResult()
test(result) test(result)
return result return result
...@@ -7,6 +7,7 @@ import os ...@@ -7,6 +7,7 @@ import os
import unittest import unittest
from packageship.libs.exception import Error from packageship.libs.exception import Error
try: try:
from packageship import system_config from packageship import system_config
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import os import os
import unittest import unittest
import json
from .basetest import TestBase
from packageship.libs.exception import Error from packageship.libs.exception import Error
try: try:
...@@ -28,6 +30,15 @@ except Error: ...@@ -28,6 +30,15 @@ except Error:
raise raise
class ReadTestBase(unittest.TestCase): class ReadTestBase(TestBase):
def client_request(self, url):
"""
Simulate client sending request
"""
response = self.client.get(url)
response_content = json.loads(response.data)
return response_content
def setUp(self): def setUp(self):
self.client = app.test_client() self.client = app.test_client()
[ [
{ {
"input": { "input": {
"packagename": "A", "packagename": "A",
"dbname": "mainline" "dbname": "mainline"
}, },
"output": { "output": {
"code": "2001", "code": "2001",
"data": { "data": {
"A1": [ "A1": [
"A", "A",
"0.0.23b", "0.0.23b",
"mainline", "mainline",
[ [
[ [
"B", "B",
"build" "build"
], ],
[ [
"D", "B1",
"build" "install"
], ],
[ [
"D1", "D",
"install" "build"
], ],
[ [
"B1", "D1",
"install" "install"
] ]
] ]
], ],
"A2": [ "A2": [
"A", "A",
"0.0.23b", "0.0.23b",
"mainline", "mainline",
[ [
[ [
"C", "A1",
"build" "install"
], ],
[ [
"C1", "C",
"install" "build"
], ],
[ [
"A1", "C1",
"install" "install"
] ]
] ]
], ],
"A_src": [ "A_src": [
"source", "source",
"0.0.23b", "0.0.23b",
"mainline", "mainline",
[ [
[ [
"root", "root",
null null
] ]
] ]
], ],
"B1": [ "B1": [
"B", "B",
"0.0.2", "0.0.2",
"mainline", "mainline",
[ [
[ [
"A", "A",
"build" "build"
], ],
[ [
"D", "D",
"build" "build"
] ]
] ]
], ],
"B2": [ "B2": [
"B", "B",
"0.0.2", "0.0.2",
"mainline", "mainline",
[ [
[ [
"C", "C",
"build" "build"
] ]
] ]
], ],
"C1": [ "C1": [
"C", "C",
"0.1", "0.1",
"mainline", "mainline",
[ [
[ [
"A", "A",
"build" "build"
], ],
[ [
"B", "A2",
"build" "install"
], ],
[ [
"A2", "B",
"install" "build"
], ],
[ [
"B2", "B2",
"install" "install"
] ]
] ]
], ],
"D1": [ "C2": [
"D", "C",
"0.11", "0.1",
"mainline", "mainline",
[ [
[ [
"D2", null,
"install" null
], ]
[ ]
"A2", ],
"install" "D1": [
] "D",
] "0.11",
] "mainline",
}, [
"msg": "Successful Operation!" [
} "A2",
"install"
],
[
"D2",
"install"
]
]
],
"D2": [
"D",
"0.11",
"mainline",
[
[
null,
null
]
]
]
},
"msg": "Successful Operation!"
} }
}
] ]
\ No newline at end of file
[ [
{ {
"database_name": "mainline", "database_name": "mainline",
"priority": 1, "priority": 1
"status": "enable"
}, },
{ {
"database_name": "fedora30", "database_name": "fedora30",
"priority": 2, "priority": 2
"status": "enable"
} }
] ]
\ No newline at end of file
[ {
{ "buildrequired": [
"url": "/packages/packageInfo?sourceName=A&dbName=mainline", "B1",
"data": [ "C1",
{ "C1"
"buildDep": [ ],
"B1", "description": "0 A.D. (pronounced \"zero ey-dee\") is a free, open-source, cross-platform\nreal-time strategy (RTS) game of ancient warfare. In short, it is a\nhistorically-based war/economy game that allows players to relive or rewrite\nthe history of Western civilizations, focusing on the years between 500 B.C.\nand 500 A.D. The project is highly ambitious, involving state-of-the-art 3D\ngraphics, detailed artwork, sound, and a flexible and powerful custom-built\ngame engine.\n\nThe game has been in development by Wildfire Games (WFG), a group of volunteer,\nhobbyist game developers, since 2001.",
"C1" "feature": 0,
], "gitee_url": "www.gitee.com/src-openeuler/A",
"dbname": "mainline", "issue": 0,
"license": "GPLv2+ and BSD and MIT and IBM", "license": "GPLv2+ and BSD and MIT and IBM",
"maintainer": null, "maintainer": null,
"maintainlevel": null, "maintainlevel": null,
"rpm_packager": "Fedora Project", "pkg_name": "A",
"sourceName": "A", "release": "1.fc29",
"sourceURL": "http://play0ad.com", "subpack": [
"subpack": { {
"A1": [ "id": 1,
"A2" "name": "A1",
], "provides": [
"A2": [ {
"C1", "id": 4,
"D1" "name": "Ba",
] "requiredby": [
}, "B1"
"version": "0.0.23b" ]
} },
] {
} "id": 7,
] "name": "Da",
\ No newline at end of file "requiredby": [
"D1"
]
}
],
"requires": [
{
"id": 1,
"name": "Ac",
"providedby": [
"C1",
"C1"
]
}
]
},
{
"id": 2,
"name": "A2",
"provides": [
{
"id": 6,
"name": "Ca",
"requiredby": []
}
],
"requires": [
{
"id": 2,
"name": "Ac",
"providedby": [
"C1",
"C1"
]
},
{
"id": 3,
"name": "Bc",
"providedby": [
"C1"
]
}
]
}
],
"summary": "Cross-Platform RTS Game of Ancient Warfare",
"url": "http://play0ad.com",
"version": "0.0.23b"
}
\ No newline at end of file
[
{
"issue_type": [
"需求",
"CVE和安全问题",
"缺陷"
]
},
{
"issue_status": [
"open",
"progressing",
"closed",
"rejected"
]
},
{
"input": {
"hook_name": "issue_hooks",
"password": "pwd",
"hook_id": 1,
"hook_url": "http://gitee.com/liwen/gitos/hooks/1/edit",
"timestamp": "1576754827988",
"sign": "rLEHLuZRIQHuTPeXMib9Czoq9dVXO4TsQcmQQHtjXHA=",
"issue": {
"html_url": "https://gitee.com/oschina/gitee/issues/IG6E9",
"id": 295024870,
"number": "IG8E1",
"title": "IE fault",
"body": "js fault",
"issue_type": "缺陷",
"state": "open",
"comments": 0,
"created_at": "2018-02-07T23:46:46+08:00",
"updated_at": "2018-02-07T23:46:46+08:00",
"user": {
"id": 1,
"login": "robot",
"avatar_url": "https://gitee.com/assets/favicon.ico",
"html_url": "https://gitee.com/robot",
"type": "User",
"site_admin": false,
"name": "robot",
"email": "robot@gitee.com",
"username": "robot",
"user_name": "robot",
"url": "https://gitee.com/robot"
},
"labels": [
{
"id": 827033694,
"name": "bug",
"color": "d73a4a"
}
],
"assignee": {
"id": 1,
"login": "robot",
"avatar_url": "https://gitee.com/assets/favicon.ico",
"html_url": "https://gitee.com/robot",
"type": "User",
"site_admin": false,
"name": "robot",
"email": "robot@gitee.com",
"username": "robot",
"user_name": "robot",
"url": "https://gitee.com/robot"
},
"milestone": {
"html_url": "https://gitee.com/oschina/gitee/milestones/1",
"id": 3096855,
"number": 1,
"title": "problem",
"description": null,
"open_issues": 13,
"started_issues": 6,
"closed_issues": 31,
"approved_issues": 42,
"state": "open",
"created_at": "2018-02-01T23:46:46+08:00",
"updated_at": "2018-02-02T23:46:46+08:00",
"due_on": null
}
},
"repository": {
"id": 120249025,
"name": "Gitee",
"path": "Cython",
"full_name": "China/Gitee",
"owner": {
"id": 1,
"login": "robot",
"avatar_url": "https://gitee.com/assets/favicon.ico",
"html_url": "https://gitee.com/robot",
"type": "User",
"site_admin": false,
"name": "robot",
"email": "robot@gitee.com",
"username": "robot",
"user_name": "robot",
"url": "https://gitee.com/robot"
},
"private": false,
"html_url": "https://gitee.com/oschina/gitee",
"url": "https://gitee.com/oschina/gitee",
"description": "",
"fork": false,
"created_at": "2018-02-05T23:46:46+08:00",
"updated_at": "2018-02-05T23:46:46+08:00",
"pushed_at": "2018-02-05T23:46:46+08:00",
"git_url": "git://gitee.com:oschina/gitee.git",
"ssh_url": "git@gitee.com:oschina/gitee.git",
"clone_url": "https://gitee.com/oschina/gitee.git",
"svn_url": "svn://gitee.com/oschina/gitee",
"git_http_url": "https://gitee.com/oschina/gitee.git",
"git_ssh_url": "git@gitee.com:oschina/gitee.git",
"git_svn_url": "svn://gitee.com/oschina/gitee",
"homepage": null,
"stargazers_count": 11,
"watchers_count": 12,
"forks_count": 0,
"language": "ruby",
"has_issues": true,
"has_wiki": true,
"has_pages": false,
"license": null,
"open_issues_count": 0,
"default_branch": "master",
"namespace": "oschina",
"name_with_namespace": "China/Gitee",
"path_with_namespace": "oschina/gitee"
},
"sender": {
"id": 1,
"login": "robot",
"avatar_url": "https://gitee.com/assets/favicon.ico",
"html_url": "https://gitee.com/robot",
"type": "User",
"site_admin": false,
"name": "robot",
"email": "robot@gitee.com",
"username": "robot",
"user_name": "robot",
"url": "https://gitee.com/robot"
},
"enterprise": {
"name": "oschina",
"url": "https://gitee.com/oschina"
}
}
}
]
\ No newline at end of file
[{ [
"dbname": "mainline", {
"downloadURL": null, "release": "1.fc29",
"license": "GPLv2+ and BSD and MIT and IBM", "used_time": 0,
"maintainer": null, "maintainer": null,
"maintainlevel": null, "feature": 0,
"sourceName": "A", "latest_version": null,
"sourceURL": "http://play0ad.com", "latest_version_time": null,
"version": "0.0.23b" "maintainlevel": null,
}, { "url": "http://play0ad.com",
"dbname": "mainline", "release_time": null,
"downloadURL": null, "id": 1,
"license": null, "version": "0.0.23b",
"maintainer": null, "name": "A",
"maintainlevel": null, "rpm_license": "GPLv2+ and BSD and MIT and IBM",
"sourceName": "B", "issue": 0
"sourceURL": null, }
"version": "0.0.2" ]
}, { \ No newline at end of file
"dbname": "mainline",
"downloadURL": null,
"license": null,
"maintainer": null,
"maintainlevel": null,
"sourceName": "C",
"sourceURL": null,
"version": "0.1"
}, {
"dbname": "mainline",
"downloadURL": null,
"license": null,
"maintainer": null,
"maintainlevel": null,
"sourceName": "D",
"sourceURL": null,
"version": "0.11"
}, {
"dbname": "fedora30",
"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": "fedora30",
"downloadURL": null,
"license": null,
"maintainer": null,
"maintainlevel": null,
"sourceName": "B",
"sourceURL": null,
"version": "0.0.3"
}, {
"dbname": "fedora30",
"downloadURL": null,
"license": null,
"maintainer": null,
"maintainlevel": null,
"sourceName": "C",
"sourceURL": null,
"version": "0.1"
}, {
"dbname": "fedora30",
"downloadURL": null,
"license": null,
"maintainer": null,
"maintainlevel": null,
"sourceName": "D",
"sourceURL": null,
"version": "0.12"
}, {
"dbname": "fedora30",
"downloadURL": null,
"license": null,
"maintainer": null,
"maintainlevel": null,
"sourceName": "E",
"sourceURL": null,
"version": "0.4"
}, {
"dbname": "fedora30",
"downloadURL": null,
"license": null,
"maintainer": null,
"maintainlevel": null,
"sourceName": "F",
"sourceURL": null,
"version": "1"
}]
[
{
"id": 1,
"name": "A",
"maintainer": null,
"maintainlevel": null,
"release": "1.fc29",
"rpm_version": "0.0.23b",
"used_time": 0,
"release_time": null,
"latest_version_time": null,
"latest_version": null,
"feature": 0,
"url": "http://play0ad.com",
"license": "GPLv2+ and BSD and MIT and IBM",
"issue": 0
}
]
\ No newline at end of file
- database_name: mainline - database_name: mainline
priority: 1 priority: 1
status: enable
- database_name: fedora30 - database_name: fedora30
priority: 2 priority: 2
status: enable
version_control: NA
src_repo: NA
tag_prefix: NA
seperator: NA
maintainer: taotao
maintainlevel: 4
\ No newline at end of file
version_control: NA
src_repo: NA
tag_prefix: NA
seperator: NA
maintainer: taotao
maintainlevel: 3
\ No newline at end of file
version_control: NA
src_repo: NA
tag_prefix: NA
seperator: NA
maintainer: taotao
maintainlevel: 4
\ No newline at end of file
version_control: NA
src_repo: NA
tag_prefix: NA
seperator: NA
maintainer: taotao
maintainlevel: 3
\ No newline at end of file
version_control: NA
src_repo: NA
tag_prefix: NA
seperator: NA
maintainer: taotao
maintainlevel: 6
\ No newline at end of file
version_control: NA
src_repo: NA
tag_prefix: NA
seperator: NA
maintainer: taotao
maintainlevel: 3
\ No newline at end of file
version_control: NA
src_repo: NA
tag_prefix: NA
seperator: NA
maintainer: taotao
maintainlevel: 4
\ No newline at end of file
version_control: NA
src_repo: NA
tag_prefix: NA
seperator: NA
maintainer: taotao
maintainlevel: 3
\ No newline at end of file
import unittest
import datetime
from test.base_code.my_test_runner import MyTestRunner
RUNNER = MyTestRunner()
def import_data_tests():
"""Initialize related test cases"""
from test.test_module.init_system_tests.test_importdata import ImportData
suite = unittest.TestSuite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(ImportData))
return RUNNER.run(suite)
start_time = datetime.datetime.now()
result_4_import = import_data_tests()
stop_time = datetime.datetime.now()
print('\nA Init Test total of %s test cases were run: \nsuccessful:%s\tfailed:%s\terror:%s\n' % (
int(result_4_import.testsRun),
int(result_4_import.success_case_count),
int(result_4_import.failure_case_count),
int(result_4_import.err_case_count)
))
print('Init Test Total Time: %s' % (stop_time - start_time))
#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
Execute all test cases
"""
import unittest import unittest
import datetime import datetime
from test.base_code.my_test_runner import MyTestRunner from test.base_code.my_test_runner import MyTestRunner
RUNNER = MyTestRunner(verbosity=1) RUNNER = MyTestRunner()
def import_data_tests():
"""Initialize related test cases"""
from test.test_module.init_system_tests.test_importdata import ImportData
suite = unittest.TestSuite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(ImportData))
return RUNNER.run(suite)
def read_data_tests(): def read_data_tests():
"""Test cases with read operations on data""" """Test cases with read operations on data"""
from test.test_module.dependent_query_tests.test_install_depend import TestInstallDepend from test.test_module.dependent_query_tests.test_install_depend import TestInstallDepend
from test.test_module.dependent_query_tests.test_self_depend import TestSelfDepend from test.test_module.dependent_query_tests.test_self_depend import TestSelfDepend
from test.test_module.dependent_query_tests.test_be_depend import TestBeDepend from test.test_module.dependent_query_tests.test_be_depend import TestBeDepend
...@@ -30,54 +14,30 @@ def read_data_tests(): ...@@ -30,54 +14,30 @@ def read_data_tests():
from test.test_module.dependent_query_tests.test_build_depend import TestBuildDepend from test.test_module.dependent_query_tests.test_build_depend import TestBuildDepend
from test.test_module.packages_tests.test_packages import TestPackages from test.test_module.packages_tests.test_packages import TestPackages
from test.test_module.single_package_tests.test_get_singlepack import TestGetSinglePack from test.test_module.single_package_tests.test_get_singlepack import TestGetSinglePack
from test.test_module.lifecycle.test_maintainer import TestGetMaintainers
from test.test_module.lifecycle.test_downloadexcel import TestDownloadExcelFile
from test.test_module.lifecycle.test_get_issues import TestGetIssue
suite = unittest.TestSuite() suite = unittest.TestSuite()
classes = [TestInstallDepend, TestSelfDepend, TestBeDepend, classes = [TestInstallDepend, TestSelfDepend, TestBeDepend,
TestGetRepodatas, TestBuildDepend, TestPackages, TestGetSinglePack] TestGetRepodatas, TestBuildDepend, TestPackages,
TestGetSinglePack, TestGetMaintainers, TestDownloadExcelFile,
TestGetIssue]
for cls in classes: for cls in classes:
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(cls)) suite.addTests(unittest.TestLoader().loadTestsFromTestCase(cls))
return RUNNER.run(suite) return RUNNER.run(suite)
def write_data_tests(): start_time = datetime.datetime.now()
"""Test cases with write operations on data""" result_4_read = read_data_tests()
stop_time = datetime.datetime.now()
from test.test_module.repodatas_test.test_delete_repodatas import TestDeleteRepodatas
from test.test_module.single_package_tests.test_update_singlepack import TestUpdatePackage
suite = unittest.TestSuite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestDeleteRepodatas))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestUpdatePackage))
return RUNNER.run(suite)
def main():
"""Test case execution entry function"""
start_time = datetime.datetime.now()
result_4_import = import_data_tests()
result_4_read = read_data_tests()
result_4_write = write_data_tests()
stop_time = datetime.datetime.now()
print('\nA total of %s test cases were run: \nsuccessful:%s\tfailed:%s\terror:%s\n' % (
int(result_4_import.testsRun) + int(result_4_read.testsRun) + int(result_4_write.testsRun),
int(
result_4_import.success_case_count
) + int(result_4_read.success_case_count) + int(result_4_write.success_case_count),
int(
result_4_import.failure_case_count
) + int(result_4_read.failure_case_count) + int(result_4_write.failure_case_count),
int(
result_4_import.err_case_count
) + int(result_4_read.err_case_count) + int(result_4_write.err_case_count)
))
print('Total Time: %s' % (stop_time - start_time))
print('\nA Read Test total of %s test cases were run: \nsuccessful:%s\tfailed:%s\terror:%s\n' % (
int(result_4_read.testsRun),
int(result_4_read.success_case_count),
int(result_4_read.failure_case_count),
int(result_4_read.err_case_count)
))
main() print('Read Test Total Time: %s' % (stop_time - start_time))
...@@ -280,10 +280,7 @@ class TestSelfDepend(ReadTestBase): ...@@ -280,10 +280,7 @@ class TestSelfDepend(ReadTestBase):
data=json.dumps(input_value), data=json.dumps(input_value),
content_type="application/json") content_type="application/json")
output_for_input = correct_data["output"] output_for_input = correct_data["output"]
from pprint import pprint
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertTrue(compare_two_values(output_for_input, resp_dict), self.assertTrue(compare_two_values(output_for_input, resp_dict),
msg="The answer is not correct") msg="The answer is not correct")
......
...@@ -64,7 +64,7 @@ class ImportData(unittest.TestCase): ...@@ -64,7 +64,7 @@ class ImportData(unittest.TestCase):
# Yaml file exists but the content is empty # Yaml file exists but the content is empty
try: try:
_config_path = ReadConfig().get_system('init_conf_path') _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path')
shutil.copyfile(_config_path, _config_path + '.bak') shutil.copyfile(_config_path, _config_path + '.bak')
with open(_config_path, 'w', encoding='utf-8') as w_f: with open(_config_path, 'w', encoding='utf-8') as w_f:
...@@ -83,7 +83,7 @@ class ImportData(unittest.TestCase): ...@@ -83,7 +83,7 @@ class ImportData(unittest.TestCase):
# Yaml file exists but DB exists_ The same with name # Yaml file exists but DB exists_ The same with name
try: try:
_config_path = ReadConfig().get_system('init_conf_path') _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path')
shutil.copyfile(_config_path, _config_path + '.bak') shutil.copyfile(_config_path, _config_path + '.bak')
with open(_config_path, 'r', encoding='utf-8') as file: with open(_config_path, 'r', encoding='utf-8') as file:
origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader)
...@@ -118,7 +118,7 @@ class ImportData(unittest.TestCase): ...@@ -118,7 +118,7 @@ class ImportData(unittest.TestCase):
config.set("SYSTEM", "init_conf_path", "D:\\Users\\conf.yaml") config.set("SYSTEM", "init_conf_path", "D:\\Users\\conf.yaml")
config.write(open(system_config.SYS_CONFIG_PATH, "w")) config.write(open(system_config.SYS_CONFIG_PATH, "w"))
_config_path = ReadConfig().get_system('init_conf_path') _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path')
InitDataBase(config_file_path=_config_path).init_data() InitDataBase(config_file_path=_config_path).init_data()
except FileNotFoundError as error: except FileNotFoundError as error:
self.assertEqual( self.assertEqual(
...@@ -132,36 +132,10 @@ class ImportData(unittest.TestCase): ...@@ -132,36 +132,10 @@ class ImportData(unittest.TestCase):
system_config.SYS_CONFIG_PATH + ".bak", system_config.SYS_CONFIG_PATH + ".bak",
system_config.SYS_CONFIG_PATH) 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")
# Modify dbtype to "test"_ dbtype"
config = ConfigParser()
config.read(system_config.SYS_CONFIG_PATH)
config.set("DATABASE", "dbtype", "test_dbtype")
config.write(open(system_config.SYS_CONFIG_PATH, "w"))
_config_path = ReadConfig().get_system('init_conf_path')
InitDataBase(config_file_path=None).init_data()
except Error as error:
self.assertEqual(
error.__class__,
Error,
msg="Wrong exception type thrown when dbtype is wrong")
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)
def test_dbname(self): def test_dbname(self):
"""test dbname""" """test dbname"""
try: try:
_config_path = ReadConfig().get_system('init_conf_path') _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path')
shutil.copyfile(_config_path, _config_path + '.bak') shutil.copyfile(_config_path, _config_path + '.bak')
with open(_config_path, 'r', encoding='utf-8') as file: with open(_config_path, 'r', encoding='utf-8') as file:
origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader)
...@@ -185,7 +159,7 @@ class ImportData(unittest.TestCase): ...@@ -185,7 +159,7 @@ class ImportData(unittest.TestCase):
def test_src_db_file(self): def test_src_db_file(self):
"""test src db file""" """test src db file"""
try: try:
_config_path = ReadConfig().get_system('init_conf_path') _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path')
shutil.copyfile(_config_path, _config_path + '.bak') shutil.copyfile(_config_path, _config_path + '.bak')
with open(_config_path, 'r', encoding='utf-8') as file: with open(_config_path, 'r', encoding='utf-8') as file:
origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader)
...@@ -209,7 +183,7 @@ class ImportData(unittest.TestCase): ...@@ -209,7 +183,7 @@ class ImportData(unittest.TestCase):
def test_priority(self): def test_priority(self):
"""test priority""" """test priority"""
try: try:
_config_path = ReadConfig().get_system('init_conf_path') _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path')
shutil.copyfile(_config_path, _config_path + '.bak') shutil.copyfile(_config_path, _config_path + '.bak')
with open(_config_path, 'r', encoding='utf-8') as file: with open(_config_path, 'r', encoding='utf-8') as file:
origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader)
...@@ -237,7 +211,7 @@ class ImportData(unittest.TestCase): ...@@ -237,7 +211,7 @@ class ImportData(unittest.TestCase):
Initialization of system data Initialization of system data
""" """
# Normal configuration # Normal configuration
_config_path = ReadConfig().get_system('init_conf_path') _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path')
InitDataBase(config_file_path=_config_path).init_data() InitDataBase(config_file_path=_config_path).init_data()
# In the correct case, an import will be generated under the initsystem # In the correct case, an import will be generated under the initsystem
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
""" """
test_get_single_packages test_get_single_packages
""" """
from io import BytesIO
import os import os
import unittest import unittest
import pandas as pd import pandas as pd
...@@ -44,7 +45,7 @@ class TestDownloadExcelFile(ReadTestBase): ...@@ -44,7 +45,7 @@ class TestDownloadExcelFile(ReadTestBase):
""" """
response = self.client.get("/lifeCycle/download/issues") response = self.client.get("/lifeCycle/download/issues")
data_frame = pd.read_excel( data_frame = pd.read_excel(
response.data, sheet_name='Summary') BytesIO(response.data), sheet_name='Summary',engine='xlrd')
datas = data_frame.values.tolist() datas = data_frame.values.tolist()
self.assertEqual( self.assertEqual(
14, len(datas), msg="An error occurred in the downloaded data") 14, len(datas), msg="An error occurred in the downloaded data")
...@@ -55,7 +56,7 @@ class TestDownloadExcelFile(ReadTestBase): ...@@ -55,7 +56,7 @@ class TestDownloadExcelFile(ReadTestBase):
'issue_content': 'def get_yaml(self, pkg):', 'issue_content': 'def get_yaml(self, pkg):',
'issue_title': '【CI加固】对识别修改对周边组件和升级影响', 'issue_title': '【CI加固】对识别修改对周边组件和升级影响',
'issue_status': 'open', 'issue_status': 'open',
'name': 'dnf', 'pkg_name': 'dnf',
'issue_type': 'defect', 'issue_type': 'defect',
'related_release': 'hahaxx' 'related_release': 'hahaxx'
} }
...@@ -70,7 +71,7 @@ class TestDownloadExcelFile(ReadTestBase): ...@@ -70,7 +71,7 @@ class TestDownloadExcelFile(ReadTestBase):
"/lifeCycle/download/packages?table_name=mainline") "/lifeCycle/download/packages?table_name=mainline")
data_frame = pd.read_excel( data_frame = pd.read_excel(
response.data, sheet_name='Summary') BytesIO(response.data), sheet_name='Summary',engine='xlrd')
datas = data_frame.values.tolist() datas = data_frame.values.tolist()
self.assertEqual( self.assertEqual(
5, len(datas), msg="An error occurred in the downloaded data") 5, len(datas), msg="An error occurred in the downloaded data")
......
...@@ -21,28 +21,7 @@ class TestGetIssue(ReadTestBase): ...@@ -21,28 +21,7 @@ class TestGetIssue(ReadTestBase):
Less transmission is always parameter transmission Less transmission is always parameter transmission
""" """
# No arguments passed # No arguments passed
resp = self.client.get("/lifeCycle/issuetrace?table_name=&page_num=&page_size=") resp = self.client.get("/lifeCycle/issuetrace?page_num=&page_size=")
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")
# Only the table_name
resp = self.client.get("/lifeCycle/issuetrace?table_name=mainline&page_num=&page_size=")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
...@@ -63,7 +42,7 @@ class TestGetIssue(ReadTestBase): ...@@ -63,7 +42,7 @@ class TestGetIssue(ReadTestBase):
msg="Error in data information return") msg="Error in data information return")
# Only the page_num # Only the page_num
resp = self.client.get("/lifeCycle/issuetrace?table_name+&page_num=1&page_size=") resp = self.client.get("/lifeCycle/issuetrace?page_num=1&page_size=")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
...@@ -84,28 +63,7 @@ class TestGetIssue(ReadTestBase): ...@@ -84,28 +63,7 @@ class TestGetIssue(ReadTestBase):
msg="Error in data information return") msg="Error in data information return")
# Only the page_size # Only the page_size
resp = self.client.get("/lifeCycle/issuetrace?table_name=&page_num=&page_size=5") resp = self.client.get("/lifeCycle/issuetrace?page_num=&page_size=5")
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")
# Without table_name
resp = self.client.get("/lifeCycle/issuetrace?table_name=&page_num=1&page_size=5")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
...@@ -126,7 +84,7 @@ class TestGetIssue(ReadTestBase): ...@@ -126,7 +84,7 @@ class TestGetIssue(ReadTestBase):
msg="Error in data information return") msg="Error in data information return")
# Without page_num # Without page_num
resp = self.client.get("/lifeCycle/issuetrace?table_name=mainline&page_num=&page_size=5") resp = self.client.get("/lifeCycle/issuetrace?page_num=&page_size=5")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
...@@ -147,7 +105,7 @@ class TestGetIssue(ReadTestBase): ...@@ -147,7 +105,7 @@ class TestGetIssue(ReadTestBase):
msg="Error in data information return") msg="Error in data information return")
# Without page_size # Without page_size
resp = self.client.get("/lifeCycle/issuetrace?table_name=mainline&page_num=1&page_size=") resp = self.client.get("/lifeCycle/issuetrace?page_num=1&page_size=")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
...@@ -172,7 +130,7 @@ class TestGetIssue(ReadTestBase): ...@@ -172,7 +130,7 @@ class TestGetIssue(ReadTestBase):
Results contrast Results contrast
""" """
# All incoming # All incoming
resp = self.client.get("/lifeCycle/issuetrace?table_name=mainline&page_num=1&page_size=5") resp = self.client.get("/lifeCycle/issuetrace?page_num=1&page_size=5")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
...@@ -195,7 +153,7 @@ class TestGetIssue(ReadTestBase): ...@@ -195,7 +153,7 @@ class TestGetIssue(ReadTestBase):
""" """
# pkg_name Parameter error # pkg_name Parameter error
resp = self.client.get( resp = self.client.get(
"/lifeCycle/issuetrace?table_name=mainline&pkg_name=hhh") "/lifeCycle/issuetrace?pkg_name=hhh")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
...@@ -214,7 +172,7 @@ class TestGetIssue(ReadTestBase): ...@@ -214,7 +172,7 @@ class TestGetIssue(ReadTestBase):
# page_num Parameter error # page_num Parameter error
resp = self.client.get( resp = self.client.get(
"/lifeCycle/issuetrace?table_name=mainline&pkg_name=dnf&page_num=x") "/lifeCycle/issuetrace?pkg_name=dnf&page_num=x")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
...@@ -236,26 +194,7 @@ class TestGetIssue(ReadTestBase): ...@@ -236,26 +194,7 @@ class TestGetIssue(ReadTestBase):
# page_size Parameter error # page_size Parameter error
resp = self.client.get( resp = self.client.get(
"/lifeCycle/issuetrace?table_name=mainline&pkg_name=dnf&page_num=1&page_size=x") "/lifeCycle/issuetrace?pkg_name=dnf&page_num=1&page_size=x")
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")
# table_name Parameter error
resp = self.client.get(
"/lifeCycle/issuetrace?table_name=xer&pkg_name=dnf")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
......
...@@ -26,7 +26,6 @@ class TestIssueCatch(OperateTestBase): ...@@ -26,7 +26,6 @@ class TestIssueCatch(OperateTestBase):
json='') json='')
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Wrong return format!") self.assertIn("code", resp_dict, msg="Wrong return format!")
self.assertEqual(ResponseCode.PARAM_ERROR, self.assertEqual(ResponseCode.PARAM_ERROR,
resp_dict.get("code"), resp_dict.get("code"),
...@@ -61,3 +60,7 @@ class TestIssueCatch(OperateTestBase): ...@@ -61,3 +60,7 @@ class TestIssueCatch(OperateTestBase):
resp_dict.get("msg"), resp_dict.get("msg"),
msg="Error in status prompt return") msg="Error in status prompt return")
self.assertIn("data", resp_dict, msg="Error in data format return") self.assertIn("data", resp_dict, msg="Error in data format return")
if __name__ == '__main__':
unittest.main()
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
""" """
packges test packges test
""" """
from test.base_code.common_test_code import get_correct_json_by_filename, compare_two_values
from test.base_code.read_data_base import ReadTestBase from test.base_code.read_data_base import ReadTestBase
import unittest import unittest
import json import json
...@@ -15,29 +16,297 @@ class TestPackages(ReadTestBase): ...@@ -15,29 +16,297 @@ class TestPackages(ReadTestBase):
All package test cases All package test cases
""" """
def test_empty_dbname(self): def test_miss_required_parameter(self):
"""dbName is none""" """
Missing required parameters
"""
# test miss all table_name page_num page_size
resp = self.client.get("/packages?table_name=&page_num=&page_size=")
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")
# test miss table_name
resp = self.client.get("/packages?table_name=&page_num=1&page_size=1")
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")
# test miss page_num
resp = self.client.get(
"/packages?table_name=mainline&page_num=&page_size=1")
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")
# test miss page_size
resp = self.client.get(
"/packages?table_name=mainline&page_num=1&page_size=")
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_wrong_required_parameter(self):
"""
wrong required parameters
"""
# test wrong page_num
resp = self.client.get(
"/packages?table_name=mainline&page_num=-1&page_size=1")
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")
# test wrong page_num
resp = self.client.get(
"/packages?table_name=mainline&page_num=a&page_size=1")
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")
# test wrong page_num
resp = self.client.get(
"/packages?table_name=mainline&page_num=1.1&page_size=1")
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")
# test wrong page_num
resp = self.client.get(
"/packages?table_name=mainline&page_num=65535&page_size=1")
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")
resp = self.client.get("/packages") 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")
# test wrong page_size
resp = self.client.get(
"/packages?table_name=mainline&page_num=1&page_size=-1")
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")
# test wrong page_size
resp = self.client.get(
"/packages?table_name=mainline&page_num=1&page_size=65535")
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")
# test wrong page_size
resp = self.client.get(
"/packages?table_name=mainline&page_num=1&page_size=a")
resp_dict = json.loads(resp.data) 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")
# test wrong page_size
resp = self.client.get(
"/packages?table_name=mainline&page_num=1&page_size=1.1")
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_required_parameter(self):
"""
test_true_required_parameter
"""
resp = self.client.get(
"/packages?table_name=fedora30&page_num=1&page_size=1")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.SUCCESS, self.assertEqual(ResponseCode.SUCCESS,
resp_dict.get("code"), resp_dict.get("code"),
msg="Error in status code return") msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return") self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.CODE_MSG_MAP.get(ResponseCode.SUCCESS), self.assertEqual(
resp_dict.get("msg"), ResponseCode.CODE_MSG_MAP.get(
msg="Error in status prompt return") ResponseCode.SUCCESS),
resp_dict.get("msg"),
msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return") self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNotNone( self.assertIsNotNone(
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
resp = self.client.get("/packages?dbName=") correct_list = get_correct_json_by_filename("packages")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.SUCCESS, self.assertEqual(ResponseCode.SUCCESS,
...@@ -50,33 +319,85 @@ class TestPackages(ReadTestBase): ...@@ -50,33 +319,85 @@ class TestPackages(ReadTestBase):
msg="Error in status prompt return") msg="Error in status prompt return")
self.assertIn("data", resp_dict, msg="Error in data format return") self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNotNone( self.assertTrue(
compare_two_values(
resp_dict.get("data"),
correct_list),
msg="Error in data information return")
def test_wrong_table_name(self):
"""
test_wrong_table_name
"""
# test wrong table name
resp = self.client.get(
"/packages?table_name=test&page_num=1&page_size=1")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.TABLE_NAME_NOT_EXIST,
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.TABLE_NAME_NOT_EXIST),
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"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
def test_wrong_dbname(self): def test_wrong_optional_paramters(self):
"""dbName is err""" """
test wrong Optional parameters
"""
resp = self.client.get("/packages?dbName=test") # test wrong maintainlevel
resp = self.client.get(
"/packages?table_name=mainline&query_pkg_name=&maintainner=&maintainlevel=5&page_num=1&page_size=4")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.DB_NAME_ERROR, self.assertEqual(ResponseCode.PARAM_ERROR,
resp_dict.get("code"), resp_dict.get("code"),
msg="Error in status code return") msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return") self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual( self.assertEqual(
ResponseCode.CODE_MSG_MAP.get( ResponseCode.CODE_MSG_MAP.get(
ResponseCode.DB_NAME_ERROR), ResponseCode.PARAM_ERROR),
resp_dict.get("msg"), resp_dict.get("msg"),
msg="Error in data format return") msg="Error in status code return")
self.assertIn("data", resp_dict, msg="Error in data format return") self.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNone( self.assertIsNone(
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
def test_like_srcname_paramters(self):
resp = self.client.get(
"/packages?table_name=fedora30&page_num=1&page_size=4&query_pkg_name=A")
resp_dict = json.loads(resp.data)
correct_list = get_correct_json_by_filename(
"packages_like_src")
if __name__ == '__main__': self.assertIn("code", resp_dict, msg="Error in data format return")
unittest.main() 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")
...@@ -12,13 +12,14 @@ import json ...@@ -12,13 +12,14 @@ import json
from packageship import system_config from packageship import system_config
from packageship.libs.exception import Error from packageship.libs.exception import Error
from packageship.application.apps.package.function.constants import ResponseCode from packageship.application.apps.package.function.constants import ResponseCode
from packageship.application.apps.package.function.searchdb import db_priority
class TestDeleteRepodatas(OperateTestBase): class TestDeleteRepodatas(OperateTestBase):
""" """
test delete repodata test delete repodata
""" """
def test_wrong_dbname(self): def test_wrong_dbname(self):
"""Test simulation scenario, dbname is not transmitted""" """Test simulation scenario, dbname is not transmitted"""
...@@ -73,7 +74,6 @@ class TestDeleteRepodatas(OperateTestBase): ...@@ -73,7 +74,6 @@ class TestDeleteRepodatas(OperateTestBase):
shutil.copytree(system_config.DATABASE_FOLDER_PATH, system_config.DATABASE_FOLDER_PATH + '.bak') shutil.copytree(system_config.DATABASE_FOLDER_PATH, system_config.DATABASE_FOLDER_PATH + '.bak')
resp = self.client.delete("/repodatas?dbName=fedora30") resp = self.client.delete("/repodatas?dbName=fedora30")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.SUCCESS, self.assertEqual(ResponseCode.SUCCESS,
resp_dict.get("code"), resp_dict.get("code"),
......
...@@ -11,17 +11,22 @@ import json ...@@ -11,17 +11,22 @@ import json
from packageship.application.apps.package.function.constants import ResponseCode from packageship.application.apps.package.function.constants import ResponseCode
from packageship.application.apps.package.function.searchdb import db_priority from packageship.application.apps.package.function.searchdb import db_priority
class TestGetSinglePack(ReadTestBase): class TestGetSinglePack(ReadTestBase):
""" """
Single package test case Single package test case
""" """
db_name = db_priority()[-1]
def test_error_sourcename(self):
"""sourceName is none or err"""
resp = self.client.get(f"packages/packageInfo?dbName={self.db_name}") def test_missing_required_parameters(self):
"""
Missing required parameters
"""
# Missing required parameters pkg_name
resp = self.client.get(
f"packages/packageInfo?pkg_name=&table_name=mainline")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.PARAM_ERROR, self.assertEqual(ResponseCode.PARAM_ERROR,
resp_dict.get("code"), resp_dict.get("code"),
...@@ -39,8 +44,8 @@ class TestGetSinglePack(ReadTestBase): ...@@ -39,8 +44,8 @@ class TestGetSinglePack(ReadTestBase):
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
resp = self.client.get( # Missing required parameters table_name
f"packages/packageInfo?sourceName=&dbName={self.db_name}") resp = self.client.get(f"packages/packageInfo?pkg_name=A&table_name=")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
...@@ -60,19 +65,25 @@ class TestGetSinglePack(ReadTestBase): ...@@ -60,19 +65,25 @@ class TestGetSinglePack(ReadTestBase):
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
def test_wrong_parameters(self):
"""
test wrong parramters
"""
# Missing required parameters table_name
resp = self.client.get( resp = self.client.get(
"packages/packageInfo?sourceName=test&dbName=for") f"packages/packageInfo?pkg_name=A&table_name=test")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.DB_NAME_ERROR, self.assertEqual(ResponseCode.TABLE_NAME_NOT_EXIST,
resp_dict.get("code"), resp_dict.get("code"),
msg="Error in status code return") msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return") self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual( self.assertEqual(
ResponseCode.CODE_MSG_MAP.get( ResponseCode.CODE_MSG_MAP.get(
ResponseCode.DB_NAME_ERROR), ResponseCode.TABLE_NAME_NOT_EXIST),
resp_dict.get("msg"), resp_dict.get("msg"),
msg="Error in status prompt return") msg="Error in status prompt return")
...@@ -81,33 +92,39 @@ class TestGetSinglePack(ReadTestBase): ...@@ -81,33 +92,39 @@ class TestGetSinglePack(ReadTestBase):
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
def test_true_dbname(self): # Missing required parameters pkg_name
"""dbName is null or err""" resp = self.client.get(
f"packages/packageInfo?pkg_name=test&table_name=fedora30")
resp = self.client.get("packages/packageInfo?sourceName=A")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.SUCCESS, self.assertEqual(ResponseCode.PACK_NAME_NOT_FOUND,
resp_dict.get("code"), resp_dict.get("code"),
msg="Error in status code return") msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return") self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.CODE_MSG_MAP.get(ResponseCode.SUCCESS), self.assertEqual(
resp_dict.get("msg"), ResponseCode.CODE_MSG_MAP.get(
msg="Error in status prompt return") 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.assertIn("data", resp_dict, msg="Error in data format return")
self.assertIsNotNone( self.assertIsNone(
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
correct_list = get_correct_json_by_filename("get_single_package") def test_true_parameters(self):
self.assertNotEqual([], correct_list, msg="Error reading JSON file") """
input_value = correct_list[0]["url"] test true parameters
"""
resp = self.client.get( resp = self.client.get(
f"{input_value}") "/packages/packageInfo?pkg_name=A&table_name=fedora30")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
correct_list = get_correct_json_by_filename(
"get_single_package")
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.SUCCESS, self.assertEqual(ResponseCode.SUCCESS,
resp_dict.get("code"), resp_dict.get("code"),
...@@ -122,32 +139,5 @@ class TestGetSinglePack(ReadTestBase): ...@@ -122,32 +139,5 @@ class TestGetSinglePack(ReadTestBase):
self.assertTrue( self.assertTrue(
compare_two_values( compare_two_values(
resp_dict.get("data"), resp_dict.get("data"),
correct_list[0]['data']), correct_list),
msg="Error in data information return") msg="Error in data information return")
def test_wrong_dbname(self):
"""test_wrong_dbname"""
resp = self.client.get(
"/packages/packageInfo?sourceName=A&dbName=open")
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")
if __name__ == '__main__':
unittest.main()
#!/usr/bin/python3 #!/usr/bin/python3
"""TestUpdatePackage""" """TestUpdatePackage"""
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import os
from test.base_code.operate_data_base import OperateTestBase from test.base_code.operate_data_base import OperateTestBase
import unittest from packageship import system_config
import json import json
from packageship.application.apps.package.function.constants import ResponseCode from packageship.application.apps.package.function.constants import ResponseCode
from packageship.application.apps.package.function.searchdb import db_priority
class TestUpdatePackage(OperateTestBase):
class TestBatchUpdatePackage(OperateTestBase):
"""TestUpdatePackage""" """TestUpdatePackage"""
db_name = db_priority()[0]
def test_empty_dbname(self): def test_missing_required_parameters(self):
"""Parameter error""" """
Parameter error
resp = self.client.put("/packages/packageInfo", """
data=json.dumps({"dbName": "", # all miss required parameters
"sourceName": "xx", resp = self.client.put("/lifeCycle/updatePkgInfo",
"maintainer": "", data=json.dumps({"batch": ""}),
"maintainlevel": "1"}),
content_type="application/json") content_type="application/json")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
resp_dict.get("data") resp_dict.get("data")
...@@ -40,25 +41,168 @@ class TestUpdatePackage(OperateTestBase): ...@@ -40,25 +41,168 @@ class TestUpdatePackage(OperateTestBase):
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
# wrong dbname # all miss wrong parameters
resp = self.client.put("/packages/packageInfo", resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({"dbName": "xhhz", data=json.dumps({"batch": "1"}),
"sourceName": "xx",
"maintainer": "",
"maintainlevel": "1"}),
content_type="application/json") content_type="application/json")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
resp_dict.get("data") resp_dict.get("data")
self.assertIn("code", resp_dict, msg="Error in data format return") self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.DB_NAME_ERROR, self.assertEqual(ResponseCode.SPECIFIED_FILE_NOT_EXIST,
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.SPECIFIED_FILE_NOT_EXIST),
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_read_yaml_update(self):
"""
Returns:
"""
# Missing file path
resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({"batch": 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.SPECIFIED_FILE_NOT_EXIST,
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.SPECIFIED_FILE_NOT_EXIST),
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")
# File path error
resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({"batch": 1,
"filepath": "D\\"}),
content_type="application/json")
resp_dict = json.loads(resp.data)
self.assertIn("code", resp_dict, msg="Error in data format return")
self.assertEqual(ResponseCode.SPECIFIED_FILE_NOT_EXIST,
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.SPECIFIED_FILE_NOT_EXIST),
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")
# Data error in yaml file
yaml_path = os.path.join(
os.path.dirname(system_config.BASE_PATH),
"test",
"common_files",
"test_wrong_format_yaml")
resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({"filepath": yaml_path,
"batch": 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.YAML_FILE_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.YAML_FILE_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")
# Data error in yaml file
yaml_path = os.path.join(
os.path.dirname(system_config.BASE_PATH),
"test",
"common_files",
"test_wrong_main_yaml")
resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({"filepath": yaml_path,
"batch": 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.YAML_FILE_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.YAML_FILE_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_batch_error(self):
"""
test_batch_error
Returns:
"""
resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({"filepath": "C:\\",
"batch": 2
}),
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"), resp_dict.get("code"),
msg="Error in status code return") msg="Error in status code return")
self.assertIn("msg", resp_dict, msg="Error in data format return") self.assertIn("msg", resp_dict, msg="Error in data format return")
self.assertEqual( self.assertEqual(
ResponseCode.CODE_MSG_MAP.get( ResponseCode.CODE_MSG_MAP.get(
ResponseCode.DB_NAME_ERROR), ResponseCode.PARAM_ERROR),
resp_dict.get("msg"), resp_dict.get("msg"),
msg="Error in status prompt return") msg="Error in status prompt return")
...@@ -67,13 +211,54 @@ class TestUpdatePackage(OperateTestBase): ...@@ -67,13 +211,54 @@ class TestUpdatePackage(OperateTestBase):
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
def test_empty_sourcename(self): def test_true_yaml(self):
"""Parameter error""" """
Returns:
resp = self.client.put("/packages/packageInfo", """
data=json.dumps({"dbName": f"{self.db_name}", yaml_path = os.path.join(
"sourceName": "xx", os.path.dirname(system_config.BASE_PATH),
"maintainer": "1"}), "test",
"common_files",
"test_true_yaml")
resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({"filepath": yaml_path,
"batch": 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 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_single_update(self):
"""
Returns:
"""
# Various parameters are missing
resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({
"pkg_name": "",
"batch": 0
}),
content_type="application/json") content_type="application/json")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
resp_dict.get("data") resp_dict.get("data")
...@@ -94,10 +279,13 @@ class TestUpdatePackage(OperateTestBase): ...@@ -94,10 +279,13 @@ class TestUpdatePackage(OperateTestBase):
self.assertIsNone( self.assertIsNone(
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
# miss maintainer maintainlevel
resp = self.client.put("/packages/packageInfo", resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({"dbName": f"{self.db_name}", data=json.dumps({
"sourceName": "xx"}), "pkg_name": "CUnit",
"batch": 0,
"maintainlevel": "a"
}),
content_type="application/json") content_type="application/json")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
resp_dict.get("data") resp_dict.get("data")
...@@ -119,15 +307,45 @@ class TestUpdatePackage(OperateTestBase): ...@@ -119,15 +307,45 @@ class TestUpdatePackage(OperateTestBase):
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
def test_true_parram(self): resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({
"pkg_name": "CUnit",
"batch": 0,
"maintainlevel": "6"
}),
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_ture_name(self):
""" """
test table name
Returns: Returns:
""" """
resp = self.client.put("/packages/packageInfo", resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({"dbName": f"{self.db_name}", data=json.dumps({
"sourceName": "A", "pkg_name": "CUnit",
"maintainer": "x", "batch": 0,
"maintainlevel": "1"}), "maintainlevel": "4"
}),
content_type="application/json") content_type="application/json")
resp_dict = json.loads(resp.data) resp_dict = json.loads(resp.data)
resp_dict.get("data") resp_dict.get("data")
...@@ -149,6 +367,68 @@ class TestUpdatePackage(OperateTestBase): ...@@ -149,6 +367,68 @@ class TestUpdatePackage(OperateTestBase):
resp_dict.get("data"), resp_dict.get("data"),
msg="Error in data information return") msg="Error in data information return")
def test_pkg_name(self):
"""
test_pkg_name
Returns:
"""
resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({
"pkg_name": "",
"batch": 0,
"maintainlevel": "4"
}),
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")
def test_true_updata_single(self):
"""
test_true_single
Returns:
"""
resp = self.client.put("/lifeCycle/updatePkgInfo",
data=json.dumps({
"pkg_name": "CUnit",
"batch": 0,
"maintainlevel": "4"
}),
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")
if __name__ == '__main__': self.assertIn("data", resp_dict, msg="Error in data format return")
unittest.main() self.assertIsNone(
resp_dict.get("data"),
msg="Error in data information return")
#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
Execute all test cases
"""
import unittest
import datetime
from test.base_code.my_test_runner import MyTestRunner
RUNNER = MyTestRunner()
def write_data_tests():
"""Test cases with write operations on data"""
from test.test_module.repodatas_test.test_delete_repodatas import TestDeleteRepodatas
from test.test_module.single_package_tests.test_update_singlepack import TestBatchUpdatePackage
from test.test_module.lifecycle.test_issue_catch import TestIssueCatch
suite = unittest.TestSuite()
classes = [
# TestDeleteRepodatas,
# TestBatchUpdatePackage,
TestIssueCatch
]
for cls in classes:
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(cls))
return RUNNER.run(suite)
start_time = datetime.datetime.now()
result_4_write = write_data_tests()
stop_time = datetime.datetime.now()
print('\nA Write Test total of %s test cases were run: \nsuccessful:%s\tfailed:%s\terror:%s\n' % (
int(result_4_write.testsRun),
int(result_4_write.success_case_count),
int(result_4_write.failure_case_count),
int(result_4_write.err_case_count)
))
print('Write Test Total Time: %s' % (stop_time - start_time))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册