diff --git a/packageship/packageship/application/apps/package/function/packages.py b/packageship/packageship/application/apps/package/function/packages.py index 94f7df1d92a7ca9833dfe62aebed637b142d411d..264588db167485eeb83c979420ecbc568d9252f9 100644 --- a/packageship/packageship/application/apps/package/function/packages.py +++ b/packageship/packageship/application/apps/package/function/packages.py @@ -296,7 +296,7 @@ def provide_(tablename, bin_provides_set): bin_provides_dict['id'] = bin_provides_obj.id bin_provides_dict['name'] = bin_provides_obj.name 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 = [ reqired_obj.pkgKey for reqired_obj in reqired_set] required_bin_set = data_name.session.query(BinPack).filter( diff --git a/packageship/pkgship.spec b/packageship/pkgship.spec index f72bf57182e859a3396e873546363d50cacdc06c..2d8f7bf9dd933ddbaf0340e2ca224798d45cecb9 100644 --- a/packageship/pkgship.spec +++ b/packageship/pkgship.spec @@ -10,9 +10,11 @@ BuildArch: noarch 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-Flask-APScheduler python3-pandas python3-retrying python3-xlrd python3-XlsxWriter Requires: python3-pip python3-flask-restful python3-flask python3 python3-pyyaml Requires: python3-sqlalchemy python3-prettytable python3-requests 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 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 +export TZ=Asia/Shanghai # change log_path to solve default log_path permission denied problem log_path=`pwd`/tmp/ 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 %post diff --git a/packageship/test/base_code/basetest.py b/packageship/test/base_code/basetest.py new file mode 100644 index 0000000000000000000000000000000000000000..efc030c4b29efd3669d091ccaff0596a3c3fe289 --- /dev/null +++ b/packageship/test/base_code/basetest.py @@ -0,0 +1,16 @@ +#!/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") diff --git a/packageship/test/base_code/common_test_code.py b/packageship/test/base_code/common_test_code.py index f92cb9d88a177b827cf52fd1105cec0c85c2ff73..ba8950ccdbc93b4e3844145d17236b54dc1d14f2 100644 --- a/packageship/test/base_code/common_test_code.py +++ b/packageship/test/base_code/common_test_code.py @@ -41,7 +41,7 @@ def get_correct_json_by_filename(filename): "correct_test_result_json", "{}.json".format(filename)) 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()) except FileNotFoundError: return [] diff --git a/packageship/test/base_code/my_test_runner.py b/packageship/test/base_code/my_test_runner.py index e3ce22f32178e441efd0eb15a85b6f9e25da4139..4f506ba686c46f7c6d942ef0427e36e9b737fc0f 100644 --- a/packageship/test/base_code/my_test_runner.py +++ b/packageship/test/base_code/my_test_runner.py @@ -24,32 +24,29 @@ class MyTestResult(unittest.TestResult): """When the use case is executed successfully""" self.success_case_count += 1 super(MyTestResult, self).addSuccess(test) - if self.verbosity > 0: - sys.stderr.write('Success ') - sys.stderr.write(str(test)) - sys.stderr.write('\n') + sys.stderr.write('Success ') + sys.stderr.write(str(test)) + sys.stderr.write('\n') def addError(self, test, err): """When a code error causes a use case to fail""" self.err_case_count += 1 super(MyTestResult, self).addError(test, err) - if self.verbosity > 0: - sys.stderr.write('Error ') - sys.stderr.write(str(test)+'\n') - _,err_info = self.errors[-1] - sys.stderr.write(err_info) - sys.stderr.write('\n') + sys.stderr.write('Error ') + sys.stderr.write(str(test)+'\n') + _,err_info = self.errors[-1] + sys.stderr.write(err_info) + sys.stderr.write('\n') def addFailure(self, test, err): """When the assertion is false""" self.failure_case_count += 1 super(MyTestResult, self).addFailure(test, err) - if self.verbosity > 0: - sys.stderr.write('Failure ') - sys.stderr.write(str(test)+'\n') - _, err_info = self.failures[-1] - sys.stderr.write(err_info) - sys.stderr.write('\n') + sys.stderr.write('Failure ') + sys.stderr.write(str(test) + '\n') + _, err_info = self.failures[-1] + sys.stderr.write(err_info) + sys.stderr.write('\n') class MyTestRunner(): @@ -57,11 +54,8 @@ class MyTestRunner(): Run All TestCases """ - def __init__(self, verbosity=0): - self.verbosity = verbosity - def run(self, test): """run MyTestResult and return result""" - result = MyTestResult(self.verbosity) + result = MyTestResult() test(result) return result diff --git a/packageship/test/base_code/operate_data_base.py b/packageship/test/base_code/operate_data_base.py index b5a472a9a128aacf02cd9b3d25a89ca4eb2eeff8..bbdee42123e3ad2d9b8a781ac2820d531cbd12c7 100644 --- a/packageship/test/base_code/operate_data_base.py +++ b/packageship/test/base_code/operate_data_base.py @@ -7,6 +7,7 @@ import os import unittest from packageship.libs.exception import Error + try: from packageship import system_config diff --git a/packageship/test/base_code/read_data_base.py b/packageship/test/base_code/read_data_base.py index 0e7a33ddf28dbcc23bf40d257a15a5c199919049..8e6a4c0fa996a961c49ffdfa941621f95b49597f 100644 --- a/packageship/test/base_code/read_data_base.py +++ b/packageship/test/base_code/read_data_base.py @@ -2,6 +2,8 @@ # -*- coding:utf-8 -*- import os import unittest +import json +from .basetest import TestBase from packageship.libs.exception import Error try: @@ -28,6 +30,15 @@ except Error: 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): self.client = app.test_client() diff --git a/packageship/test/common_files/correct_test_result_json/be_depend.json b/packageship/test/common_files/correct_test_result_json/be_depend.json index a567c73839d4fd2e5f55eb8454bdad8b40a4c452..33423547638d23f53feaf5394298e45f3c08c2f4 100644 --- a/packageship/test/common_files/correct_test_result_json/be_depend.json +++ b/packageship/test/common_files/correct_test_result_json/be_depend.json @@ -1,131 +1,153 @@ [ - { - "input": { - "packagename": "A", - "dbname": "mainline" - }, - "output": { - "code": "2001", - "data": { - "A1": [ - "A", - "0.0.23b", - "mainline", - [ - [ - "B", - "build" - ], - [ - "D", - "build" - ], - [ - "D1", - "install" - ], - [ - "B1", - "install" - ] - ] - ], - "A2": [ - "A", - "0.0.23b", - "mainline", - [ - [ - "C", - "build" - ], - [ - "C1", - "install" - ], - [ - "A1", - "install" - ] - ] - ], - "A_src": [ - "source", - "0.0.23b", - "mainline", - [ - [ - "root", - null - ] - ] - ], - "B1": [ - "B", - "0.0.2", - "mainline", - [ - [ - "A", - "build" - ], - [ - "D", - "build" - ] - ] - ], - "B2": [ - "B", - "0.0.2", - "mainline", - [ - [ - "C", - "build" - ] - ] - ], - "C1": [ - "C", - "0.1", - "mainline", - [ - [ - "A", - "build" - ], - [ - "B", - "build" - ], - [ - "A2", - "install" - ], - [ - "B2", - "install" - ] - ] - ], - "D1": [ - "D", - "0.11", - "mainline", - [ - [ - "D2", - "install" - ], - [ - "A2", - "install" - ] - ] - ] - }, - "msg": "Successful Operation!" - } + { + "input": { + "packagename": "A", + "dbname": "mainline" + }, + "output": { + "code": "2001", + "data": { + "A1": [ + "A", + "0.0.23b", + "mainline", + [ + [ + "B", + "build" + ], + [ + "B1", + "install" + ], + [ + "D", + "build" + ], + [ + "D1", + "install" + ] + ] + ], + "A2": [ + "A", + "0.0.23b", + "mainline", + [ + [ + "A1", + "install" + ], + [ + "C", + "build" + ], + [ + "C1", + "install" + ] + ] + ], + "A_src": [ + "source", + "0.0.23b", + "mainline", + [ + [ + "root", + null + ] + ] + ], + "B1": [ + "B", + "0.0.2", + "mainline", + [ + [ + "A", + "build" + ], + [ + "D", + "build" + ] + ] + ], + "B2": [ + "B", + "0.0.2", + "mainline", + [ + [ + "C", + "build" + ] + ] + ], + "C1": [ + "C", + "0.1", + "mainline", + [ + [ + "A", + "build" + ], + [ + "A2", + "install" + ], + [ + "B", + "build" + ], + [ + "B2", + "install" + ] + ] + ], + "C2": [ + "C", + "0.1", + "mainline", + [ + [ + null, + null + ] + ] + ], + "D1": [ + "D", + "0.11", + "mainline", + [ + [ + "A2", + "install" + ], + [ + "D2", + "install" + ] + ] + ], + "D2": [ + "D", + "0.11", + "mainline", + [ + [ + null, + null + ] + ] + ] + }, + "msg": "Successful Operation!" } + } ] \ No newline at end of file diff --git a/packageship/test/common_files/correct_test_result_json/get_repodatas.json b/packageship/test/common_files/correct_test_result_json/get_repodatas.json index 395ff7e8c32c8e40b68ec0f0a7c4a5b2a996fb48..8b8d0124342ca5c50f09f072f488f914fb42665e 100644 --- a/packageship/test/common_files/correct_test_result_json/get_repodatas.json +++ b/packageship/test/common_files/correct_test_result_json/get_repodatas.json @@ -1,12 +1,10 @@ [ { "database_name": "mainline", - "priority": 1, - "status": "enable" + "priority": 1 }, { "database_name": "fedora30", - "priority": 2, - "status": "enable" + "priority": 2 } ] \ No newline at end of file diff --git a/packageship/test/common_files/correct_test_result_json/get_single_package.json b/packageship/test/common_files/correct_test_result_json/get_single_package.json index 7fc68ab9d9d1cd517351f2478588e1f8858d17fa..8f46fbfb197bc553fcc318c4b26f26353a753e99 100644 --- a/packageship/test/common_files/correct_test_result_json/get_single_package.json +++ b/packageship/test/common_files/correct_test_result_json/get_single_package.json @@ -1,30 +1,79 @@ -[ - { - "url": "/packages/packageInfo?sourceName=A&dbName=mainline", - "data": [ - { - "buildDep": [ - "B1", - "C1" - ], - "dbname": "mainline", - "license": "GPLv2+ and BSD and MIT and IBM", - "maintainer": null, - "maintainlevel": null, - "rpm_packager": "Fedora Project", - "sourceName": "A", - "sourceURL": "http://play0ad.com", - "subpack": { - "A1": [ - "A2" - ], - "A2": [ - "C1", - "D1" - ] - }, - "version": "0.0.23b" - } - ] - } -] \ No newline at end of file +{ + "buildrequired": [ + "B1", + "C1", + "C1" + ], + "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.", + "feature": 0, + "gitee_url": "www.gitee.com/src-openeuler/A", + "issue": 0, + "license": "GPLv2+ and BSD and MIT and IBM", + "maintainer": null, + "maintainlevel": null, + "pkg_name": "A", + "release": "1.fc29", + "subpack": [ + { + "id": 1, + "name": "A1", + "provides": [ + { + "id": 4, + "name": "Ba", + "requiredby": [ + "B1" + ] + }, + { + "id": 7, + "name": "Da", + "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 diff --git a/packageship/test/common_files/correct_test_result_json/issues.json b/packageship/test/common_files/correct_test_result_json/issues.json new file mode 100644 index 0000000000000000000000000000000000000000..c276341f7a87932440002680aff912a41627549d --- /dev/null +++ b/packageship/test/common_files/correct_test_result_json/issues.json @@ -0,0 +1,152 @@ +[ + { + "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 diff --git a/packageship/test/common_files/correct_test_result_json/packages.json b/packageship/test/common_files/correct_test_result_json/packages.json index 0bd84505c2b079bd8116fa76db45271593263102..dbcd63459aac26aa82f549b3c284acf7d315735e 100644 --- a/packageship/test/common_files/correct_test_result_json/packages.json +++ b/packageship/test/common_files/correct_test_result_json/packages.json @@ -1,91 +1,18 @@ - [{ - "dbname": "mainline", - "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": "mainline", - "downloadURL": null, - "license": null, - "maintainer": null, - "maintainlevel": null, - "sourceName": "B", - "sourceURL": null, - "version": "0.0.2" - }, { - "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" - }] +[ + { + "release": "1.fc29", + "used_time": 0, + "maintainer": null, + "feature": 0, + "latest_version": null, + "latest_version_time": null, + "maintainlevel": null, + "url": "http://play0ad.com", + "release_time": null, + "id": 1, + "version": "0.0.23b", + "name": "A", + "rpm_license": "GPLv2+ and BSD and MIT and IBM", + "issue": 0 + } +] \ No newline at end of file diff --git a/packageship/test/common_files/correct_test_result_json/packages_like_src.json b/packageship/test/common_files/correct_test_result_json/packages_like_src.json new file mode 100644 index 0000000000000000000000000000000000000000..54c3fff8fea415f4a56b489585c3795688016edd --- /dev/null +++ b/packageship/test/common_files/correct_test_result_json/packages_like_src.json @@ -0,0 +1,18 @@ +[ + { + "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 diff --git a/packageship/test/common_files/database_file_info.yaml b/packageship/test/common_files/database_file_info.yaml index fead15d8a33f0db9ece1f1d5987e397926b9b0ac..f9b468a05e27b811a51ff92239135416a543821c 100644 --- a/packageship/test/common_files/database_file_info.yaml +++ b/packageship/test/common_files/database_file_info.yaml @@ -1,6 +1,4 @@ - database_name: mainline priority: 1 - status: enable - database_name: fedora30 priority: 2 - status: enable diff --git a/packageship/test/common_files/dbs/lifecycle.db b/packageship/test/common_files/dbs/lifecycle.db new file mode 100644 index 0000000000000000000000000000000000000000..264f168a630bc3e8485bdf9e464d8a56e409b808 Binary files /dev/null and b/packageship/test/common_files/dbs/lifecycle.db differ diff --git a/packageship/test/common_files/operate_dbs/fedora30.db b/packageship/test/common_files/operate_dbs/fedora30.db index b7ca1a27484b467a27e96cd625658182a9784243..2d6c77f9da54228843d3026dd79df0a5ad219588 100644 Binary files a/packageship/test/common_files/operate_dbs/fedora30.db and b/packageship/test/common_files/operate_dbs/fedora30.db differ diff --git a/packageship/test/common_files/operate_dbs/lifecycle.db b/packageship/test/common_files/operate_dbs/lifecycle.db new file mode 100644 index 0000000000000000000000000000000000000000..9053816339c706c36913a234b7e928c439529b21 Binary files /dev/null and b/packageship/test/common_files/operate_dbs/lifecycle.db differ diff --git a/packageship/test/common_files/operate_dbs/mainline.db b/packageship/test/common_files/operate_dbs/mainline.db index 0e31b354171dd7c05cf72766679c9f127588bd8c..a96d22a6301a92698fa34d0e3fa5dfca78d11245 100644 Binary files a/packageship/test/common_files/operate_dbs/mainline.db and b/packageship/test/common_files/operate_dbs/mainline.db differ diff --git a/packageship/test/common_files/operate_dbs/maintenance.information.db b/packageship/test/common_files/operate_dbs/maintenance.information.db index e654f0ee4db55657418c1bdb733b9911158e406a..d43b5e4e10a2b922a2931664afe5cb6aba22852f 100644 Binary files a/packageship/test/common_files/operate_dbs/maintenance.information.db and b/packageship/test/common_files/operate_dbs/maintenance.information.db differ diff --git a/packageship/test/common_files/test_true_yaml/CUnit.yaml b/packageship/test/common_files/test_true_yaml/CUnit.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c8422018718cd23e04003ec2ef9e4629d6490f08 --- /dev/null +++ b/packageship/test/common_files/test_true_yaml/CUnit.yaml @@ -0,0 +1,6 @@ +version_control: NA +src_repo: NA +tag_prefix: NA +seperator: NA +maintainer: taotao +maintainlevel: 4 \ No newline at end of file diff --git a/packageship/test/common_files/test_true_yaml/Judy.yaml b/packageship/test/common_files/test_true_yaml/Judy.yaml new file mode 100644 index 0000000000000000000000000000000000000000..32bd50d837afb3dc73111d2fad904c9966797434 --- /dev/null +++ b/packageship/test/common_files/test_true_yaml/Judy.yaml @@ -0,0 +1,6 @@ +version_control: NA +src_repo: NA +tag_prefix: NA +seperator: NA +maintainer: taotao +maintainlevel: 3 \ No newline at end of file diff --git a/packageship/test/common_files/test_wrong_format_yaml/CUnit.yaml b/packageship/test/common_files/test_wrong_format_yaml/CUnit.yaml new file mode 100644 index 0000000000000000000000000000000000000000..55d600f6a357f64818d5f3de7a9daff0d85c6880 --- /dev/null +++ b/packageship/test/common_files/test_wrong_format_yaml/CUnit.yaml @@ -0,0 +1,6 @@ +version_control: NA +src_repo: NA +tag_prefix: NA +seperator: NA +maintainer: taotao + maintainlevel: 4 \ No newline at end of file diff --git a/packageship/test/common_files/test_wrong_format_yaml/Judy.yaml b/packageship/test/common_files/test_wrong_format_yaml/Judy.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ed6d215c0a3b56ab87e7bf3d93d03bea11a1d910 --- /dev/null +++ b/packageship/test/common_files/test_wrong_format_yaml/Judy.yaml @@ -0,0 +1,6 @@ +version_control: NA +src_repo: NA +tag_prefix: NA +seperator: NA +maintainer: taotao + maintainlevel: 3 \ No newline at end of file diff --git a/packageship/test/common_files/test_wrong_main_yaml/CUnit.yaml b/packageship/test/common_files/test_wrong_main_yaml/CUnit.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6b84e8eb63b84db382680cf21ec790e717431bf5 --- /dev/null +++ b/packageship/test/common_files/test_wrong_main_yaml/CUnit.yaml @@ -0,0 +1,6 @@ +version_control: NA +src_repo: NA +tag_prefix: NA +seperator: NA +maintainer: taotao +maintainlevel: 6 \ No newline at end of file diff --git a/packageship/test/common_files/test_wrong_main_yaml/Judy.yaml b/packageship/test/common_files/test_wrong_main_yaml/Judy.yaml new file mode 100644 index 0000000000000000000000000000000000000000..32bd50d837afb3dc73111d2fad904c9966797434 --- /dev/null +++ b/packageship/test/common_files/test_wrong_main_yaml/Judy.yaml @@ -0,0 +1,6 @@ +version_control: NA +src_repo: NA +tag_prefix: NA +seperator: NA +maintainer: taotao +maintainlevel: 3 \ No newline at end of file diff --git a/packageship/test/common_files/test_wrong_pkgname_yaml/CUnit.yaml b/packageship/test/common_files/test_wrong_pkgname_yaml/CUnit.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c8422018718cd23e04003ec2ef9e4629d6490f08 --- /dev/null +++ b/packageship/test/common_files/test_wrong_pkgname_yaml/CUnit.yaml @@ -0,0 +1,6 @@ +version_control: NA +src_repo: NA +tag_prefix: NA +seperator: NA +maintainer: taotao +maintainlevel: 4 \ No newline at end of file diff --git a/packageship/test/common_files/test_wrong_pkgname_yaml/tets.yaml b/packageship/test/common_files/test_wrong_pkgname_yaml/tets.yaml new file mode 100644 index 0000000000000000000000000000000000000000..32bd50d837afb3dc73111d2fad904c9966797434 --- /dev/null +++ b/packageship/test/common_files/test_wrong_pkgname_yaml/tets.yaml @@ -0,0 +1,6 @@ +version_control: NA +src_repo: NA +tag_prefix: NA +seperator: NA +maintainer: taotao +maintainlevel: 3 \ No newline at end of file diff --git a/packageship/test/init_test.py b/packageship/test/init_test.py new file mode 100644 index 0000000000000000000000000000000000000000..fba21fdcb068ed695f1304b06c3ef31fadd4fed6 --- /dev/null +++ b/packageship/test/init_test.py @@ -0,0 +1,29 @@ +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)) diff --git a/packageship/test/read_test.py b/packageship/test/read_test.py new file mode 100644 index 0000000000000000000000000000000000000000..16eb5b9dd2cc703d982249c1b0356a00109295d0 --- /dev/null +++ b/packageship/test/read_test.py @@ -0,0 +1,43 @@ +import unittest +import datetime +from test.base_code.my_test_runner import MyTestRunner + +RUNNER = MyTestRunner() + + +def read_data_tests(): + """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_self_depend import TestSelfDepend + from test.test_module.dependent_query_tests.test_be_depend import TestBeDepend + from test.test_module.repodatas_test.test_get_repodatas import TestGetRepodatas + 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.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() + + classes = [TestInstallDepend, TestSelfDepend, TestBeDepend, + TestGetRepodatas, TestBuildDepend, TestPackages, + TestGetSinglePack, TestGetMaintainers, TestDownloadExcelFile, + TestGetIssue] + for cls in classes: + suite.addTests(unittest.TestLoader().loadTestsFromTestCase(cls)) + return RUNNER.run(suite) + + +start_time = datetime.datetime.now() +result_4_read = read_data_tests() +stop_time = datetime.datetime.now() + +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) +)) + +print('Read Test Total Time: %s' % (stop_time - start_time)) diff --git a/packageship/test/run_tests.py b/packageship/test/run_tests.py deleted file mode 100644 index 6d389d6b6870e8cfd1b4c8b019a3bee1286e7716..0000000000000000000000000000000000000000 --- a/packageship/test/run_tests.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/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(verbosity=1) - - -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(): - """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_self_depend import TestSelfDepend - from test.test_module.dependent_query_tests.test_be_depend import TestBeDepend - from test.test_module.repodatas_test.test_get_repodatas import TestGetRepodatas - 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.single_package_tests.test_get_singlepack import TestGetSinglePack - suite = unittest.TestSuite() - - classes = [TestInstallDepend, TestSelfDepend, TestBeDepend, - TestGetRepodatas, TestBuildDepend, TestPackages, TestGetSinglePack] - - for cls in classes: - suite.addTests(unittest.TestLoader().loadTestsFromTestCase(cls)) - return RUNNER.run(suite) - - -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 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)) - - -main() diff --git a/packageship/test/test_module/dependent_query_tests/test_self_depend.py b/packageship/test/test_module/dependent_query_tests/test_self_depend.py index f27967bbab213d928e214f96a08be59e980f2211..4a2fcb5d1f794f88b8ed8ab45b279ed1df2acc43 100644 --- a/packageship/test/test_module/dependent_query_tests/test_self_depend.py +++ b/packageship/test/test_module/dependent_query_tests/test_self_depend.py @@ -280,10 +280,7 @@ class TestSelfDepend(ReadTestBase): data=json.dumps(input_value), content_type="application/json") output_for_input = correct_data["output"] - from pprint import pprint - resp_dict = json.loads(resp.data) - self.assertTrue(compare_two_values(output_for_input, resp_dict), msg="The answer is not correct") diff --git a/packageship/test/test_module/init_system_tests/test_importdata.py b/packageship/test/test_module/init_system_tests/test_importdata.py index 35e303aa45def44488a6ae98428fd1ad48563f9c..59beb9603eaf3725ae70faf706791e4d6fb60d57 100644 --- a/packageship/test/test_module/init_system_tests/test_importdata.py +++ b/packageship/test/test_module/init_system_tests/test_importdata.py @@ -64,7 +64,7 @@ class ImportData(unittest.TestCase): # Yaml file exists but the content is empty 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') with open(_config_path, 'w', encoding='utf-8') as w_f: @@ -83,7 +83,7 @@ class ImportData(unittest.TestCase): # Yaml file exists but DB exists_ The same with name 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') with open(_config_path, 'r', encoding='utf-8') as file: origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) @@ -118,7 +118,7 @@ class ImportData(unittest.TestCase): config.set("SYSTEM", "init_conf_path", "D:\\Users\\conf.yaml") 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() except FileNotFoundError as error: self.assertEqual( @@ -132,36 +132,10 @@ class ImportData(unittest.TestCase): 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") - # 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): """test dbname""" 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') with open(_config_path, 'r', encoding='utf-8') as file: origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) @@ -185,7 +159,7 @@ class ImportData(unittest.TestCase): def test_src_db_file(self): """test src db file""" 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') with open(_config_path, 'r', encoding='utf-8') as file: origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) @@ -209,7 +183,7 @@ class ImportData(unittest.TestCase): def test_priority(self): """test priority""" 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') with open(_config_path, 'r', encoding='utf-8') as file: origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) @@ -237,7 +211,7 @@ class ImportData(unittest.TestCase): Initialization of system data """ # 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() # In the correct case, an import will be generated under the initsystem diff --git a/packageship/test/test_module/lifecycle/test_downloadexcel.py b/packageship/test/test_module/lifecycle/test_downloadexcel.py index a07acade2a4c375d3e3c34c7e11538c9d8a881f7..e84994ab9a132a456f1114b1deca0b612cb27efa 100644 --- a/packageship/test/test_module/lifecycle/test_downloadexcel.py +++ b/packageship/test/test_module/lifecycle/test_downloadexcel.py @@ -3,6 +3,7 @@ """ test_get_single_packages """ +from io import BytesIO import os import unittest import pandas as pd @@ -44,7 +45,7 @@ class TestDownloadExcelFile(ReadTestBase): """ response = self.client.get("/lifeCycle/download/issues") data_frame = pd.read_excel( - response.data, sheet_name='Summary') + BytesIO(response.data), sheet_name='Summary',engine='xlrd') datas = data_frame.values.tolist() self.assertEqual( 14, len(datas), msg="An error occurred in the downloaded data") @@ -55,7 +56,7 @@ class TestDownloadExcelFile(ReadTestBase): 'issue_content': 'def get_yaml(self, pkg):', 'issue_title': '【CI加固】对识别修改对周边组件和升级影响', 'issue_status': 'open', - 'name': 'dnf', + 'pkg_name': 'dnf', 'issue_type': 'defect', 'related_release': 'hahaxx' } @@ -70,7 +71,7 @@ class TestDownloadExcelFile(ReadTestBase): "/lifeCycle/download/packages?table_name=mainline") data_frame = pd.read_excel( - response.data, sheet_name='Summary') + BytesIO(response.data), sheet_name='Summary',engine='xlrd') datas = data_frame.values.tolist() self.assertEqual( 5, len(datas), msg="An error occurred in the downloaded data") diff --git a/packageship/test/test_module/lifecycle/test_get_issues.py b/packageship/test/test_module/lifecycle/test_get_issues.py index 8d47ca6e55717f8bbd658c6e070d8ba249891d7a..756a185c090156d59748dd29467c08c1780de573 100644 --- a/packageship/test/test_module/lifecycle/test_get_issues.py +++ b/packageship/test/test_module/lifecycle/test_get_issues.py @@ -21,28 +21,7 @@ class TestGetIssue(ReadTestBase): Less transmission is always parameter transmission """ # No arguments passed - resp = self.client.get("/lifeCycle/issuetrace?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 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 = 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") @@ -63,7 +42,7 @@ class TestGetIssue(ReadTestBase): msg="Error in data information return") # 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) self.assertIn("code", resp_dict, msg="Error in data format return") @@ -84,28 +63,7 @@ class TestGetIssue(ReadTestBase): msg="Error in data information return") # Only the page_size - resp = self.client.get("/lifeCycle/issuetrace?table_name=&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 = 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") @@ -126,7 +84,7 @@ class TestGetIssue(ReadTestBase): msg="Error in data information return") # 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) self.assertIn("code", resp_dict, msg="Error in data format return") @@ -147,7 +105,7 @@ class TestGetIssue(ReadTestBase): msg="Error in data information return") # 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) self.assertIn("code", resp_dict, msg="Error in data format return") @@ -172,7 +130,7 @@ class TestGetIssue(ReadTestBase): Results contrast """ # 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) self.assertIn("code", resp_dict, msg="Error in data format return") @@ -195,7 +153,7 @@ class TestGetIssue(ReadTestBase): """ # pkg_name Parameter error resp = self.client.get( - "/lifeCycle/issuetrace?table_name=mainline&pkg_name=hhh") + "/lifeCycle/issuetrace?pkg_name=hhh") resp_dict = json.loads(resp.data) self.assertIn("code", resp_dict, msg="Error in data format return") @@ -214,7 +172,7 @@ class TestGetIssue(ReadTestBase): # page_num Parameter error 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) self.assertIn("code", resp_dict, msg="Error in data format return") @@ -236,26 +194,7 @@ class TestGetIssue(ReadTestBase): # page_size Parameter error resp = self.client.get( - "/lifeCycle/issuetrace?table_name=mainline&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") + "/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") diff --git a/packageship/test/test_module/lifecycle/test_issue_catch.py b/packageship/test/test_module/lifecycle/test_issue_catch.py index 71c54c0fc250877a0d7ceffa1f05d3cc0c906bd1..2f5eb3afcfa76583306dfdf1930ab7c0dc1b9304 100644 --- a/packageship/test/test_module/lifecycle/test_issue_catch.py +++ b/packageship/test/test_module/lifecycle/test_issue_catch.py @@ -26,7 +26,6 @@ class TestIssueCatch(OperateTestBase): json='') resp_dict = json.loads(resp.data) - self.assertIn("code", resp_dict, msg="Wrong return format!") self.assertEqual(ResponseCode.PARAM_ERROR, resp_dict.get("code"), @@ -61,3 +60,7 @@ class TestIssueCatch(OperateTestBase): resp_dict.get("msg"), msg="Error in status prompt return") self.assertIn("data", resp_dict, msg="Error in data format return") + + +if __name__ == '__main__': + unittest.main() diff --git a/packageship/test/test_module/packages_tests/test_packages.py b/packageship/test/test_module/packages_tests/test_packages.py index c549e0b64f329f25fb06151430d9b5ecf7b3a06c..2a98bceab2cae3c2168348bc31266290901b3627 100644 --- a/packageship/test/test_module/packages_tests/test_packages.py +++ b/packageship/test/test_module/packages_tests/test_packages.py @@ -3,6 +3,7 @@ """ 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 import unittest import json @@ -15,29 +16,297 @@ class TestPackages(ReadTestBase): All package test cases """ - def test_empty_dbname(self): - """dbName is none""" + def test_miss_required_parameter(self): + """ + 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) + 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.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.assertEqual( + ResponseCode.CODE_MSG_MAP.get( + ResponseCode.SUCCESS), + resp_dict.get("msg"), + msg="Error in status code return") self.assertIn("data", resp_dict, msg="Error in data format return") self.assertIsNotNone( resp_dict.get("data"), msg="Error in data information return") - resp = self.client.get("/packages?dbName=") - resp_dict = json.loads(resp.data) + correct_list = get_correct_json_by_filename("packages") self.assertIn("code", resp_dict, msg="Error in data format return") self.assertEqual(ResponseCode.SUCCESS, @@ -50,33 +319,85 @@ class TestPackages(ReadTestBase): msg="Error in status prompt 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"), msg="Error in data information return") - def test_wrong_dbname(self): - """dbName is err""" + def test_wrong_optional_paramters(self): + """ + 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) 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"), 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), + ResponseCode.PARAM_ERROR), 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.assertIsNone( resp_dict.get("data"), 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__': - unittest.main() + 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") diff --git a/packageship/test/test_module/repodatas_test/test_delete_repodatas.py b/packageship/test/test_module/repodatas_test/test_delete_repodatas.py index 3a229dd7a5179fabc3e2e04b4546b8fee139de4c..0cd640aed9ecac82615f6297a2df137c2e6c04fe 100644 --- a/packageship/test/test_module/repodatas_test/test_delete_repodatas.py +++ b/packageship/test/test_module/repodatas_test/test_delete_repodatas.py @@ -12,13 +12,14 @@ import json from packageship import system_config from packageship.libs.exception import Error from packageship.application.apps.package.function.constants import ResponseCode +from packageship.application.apps.package.function.searchdb import db_priority class TestDeleteRepodatas(OperateTestBase): """ test delete repodata """ - + def test_wrong_dbname(self): """Test simulation scenario, dbname is not transmitted""" @@ -73,7 +74,6 @@ class TestDeleteRepodatas(OperateTestBase): shutil.copytree(system_config.DATABASE_FOLDER_PATH, system_config.DATABASE_FOLDER_PATH + '.bak') resp = self.client.delete("/repodatas?dbName=fedora30") 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"), diff --git a/packageship/test/test_module/single_package_tests/test_get_singlepack.py b/packageship/test/test_module/single_package_tests/test_get_singlepack.py index e6f0eddbb2a008fee96f7ebc5aa845c5199686bf..3eb3c8a95d9a088c9cd89d6e5a3ab811f2f877e9 100644 --- a/packageship/test/test_module/single_package_tests/test_get_singlepack.py +++ b/packageship/test/test_module/single_package_tests/test_get_singlepack.py @@ -11,17 +11,22 @@ import json from packageship.application.apps.package.function.constants import ResponseCode from packageship.application.apps.package.function.searchdb import db_priority + + class TestGetSinglePack(ReadTestBase): """ 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) - + self.assertIn("code", resp_dict, msg="Error in data format return") self.assertEqual(ResponseCode.PARAM_ERROR, resp_dict.get("code"), @@ -39,8 +44,8 @@ class TestGetSinglePack(ReadTestBase): resp_dict.get("data"), msg="Error in data information return") - resp = self.client.get( - f"packages/packageInfo?sourceName=&dbName={self.db_name}") + # Missing required parameters table_name + resp = self.client.get(f"packages/packageInfo?pkg_name=A&table_name=") resp_dict = json.loads(resp.data) self.assertIn("code", resp_dict, msg="Error in data format return") @@ -60,19 +65,25 @@ class TestGetSinglePack(ReadTestBase): resp_dict.get("data"), msg="Error in data information return") + def test_wrong_parameters(self): + """ + test wrong parramters + """ + + # Missing required parameters table_name 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) 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"), 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), + ResponseCode.TABLE_NAME_NOT_EXIST), resp_dict.get("msg"), msg="Error in status prompt return") @@ -81,33 +92,39 @@ class TestGetSinglePack(ReadTestBase): 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/packageInfo?sourceName=A") + # Missing required parameters pkg_name + resp = self.client.get( + f"packages/packageInfo?pkg_name=test&table_name=fedora30") resp_dict = json.loads(resp.data) 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"), 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.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.assertIsNotNone( + self.assertIsNone( 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") - input_value = correct_list[0]["url"] + def test_true_parameters(self): + """ + test true parameters + """ resp = self.client.get( - f"{input_value}") + "/packages/packageInfo?pkg_name=A&table_name=fedora30") 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.assertEqual(ResponseCode.SUCCESS, resp_dict.get("code"), @@ -122,32 +139,5 @@ class TestGetSinglePack(ReadTestBase): self.assertTrue( compare_two_values( resp_dict.get("data"), - correct_list[0]['data']), + correct_list), 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() diff --git a/packageship/test/test_module/single_package_tests/test_update_singlepack.py b/packageship/test/test_module/single_package_tests/test_update_singlepack.py index d6298b34372cd55f089d0f046f95c236115f344f..b6c8ffb3c1bd51b8170b1453f93c926e0430994e 100644 --- a/packageship/test/test_module/single_package_tests/test_update_singlepack.py +++ b/packageship/test/test_module/single_package_tests/test_update_singlepack.py @@ -1,24 +1,25 @@ #!/usr/bin/python3 """TestUpdatePackage""" # -*- coding:utf-8 -*- +import os from test.base_code.operate_data_base import OperateTestBase -import unittest +from packageship import system_config + import json 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""" - db_name = db_priority()[0] - def test_empty_dbname(self): - """Parameter error""" - - resp = self.client.put("/packages/packageInfo", - data=json.dumps({"dbName": "", - "sourceName": "xx", - "maintainer": "", - "maintainlevel": "1"}), + + def test_missing_required_parameters(self): + """ + Parameter error + """ + # all miss required parameters + resp = self.client.put("/lifeCycle/updatePkgInfo", + data=json.dumps({"batch": ""}), content_type="application/json") resp_dict = json.loads(resp.data) resp_dict.get("data") @@ -40,25 +41,168 @@ class TestUpdatePackage(OperateTestBase): resp_dict.get("data"), msg="Error in data information return") - # wrong dbname - resp = self.client.put("/packages/packageInfo", - data=json.dumps({"dbName": "xhhz", - "sourceName": "xx", - "maintainer": "", - "maintainlevel": "1"}), + # all miss wrong parameters + resp = self.client.put("/lifeCycle/updatePkgInfo", + data=json.dumps({"batch": "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, + 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"), 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), + ResponseCode.PARAM_ERROR), resp_dict.get("msg"), msg="Error in status prompt return") @@ -67,13 +211,54 @@ class TestUpdatePackage(OperateTestBase): resp_dict.get("data"), msg="Error in data information return") - def test_empty_sourcename(self): - """Parameter error""" + def test_true_yaml(self): + """ + + Returns: - resp = self.client.put("/packages/packageInfo", - data=json.dumps({"dbName": f"{self.db_name}", - "sourceName": "xx", - "maintainer": "1"}), + """ + yaml_path = os.path.join( + os.path.dirname(system_config.BASE_PATH), + "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") resp_dict = json.loads(resp.data) resp_dict.get("data") @@ -94,10 +279,13 @@ class TestUpdatePackage(OperateTestBase): self.assertIsNone( resp_dict.get("data"), msg="Error in data information return") - # miss maintainer maintainlevel - resp = self.client.put("/packages/packageInfo", - data=json.dumps({"dbName": f"{self.db_name}", - "sourceName": "xx"}), + + resp = self.client.put("/lifeCycle/updatePkgInfo", + data=json.dumps({ + "pkg_name": "CUnit", + "batch": 0, + "maintainlevel": "a" + }), content_type="application/json") resp_dict = json.loads(resp.data) resp_dict.get("data") @@ -119,15 +307,45 @@ class TestUpdatePackage(OperateTestBase): resp_dict.get("data"), 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: + """ - resp = self.client.put("/packages/packageInfo", - data=json.dumps({"dbName": f"{self.db_name}", - "sourceName": "A", - "maintainer": "x", - "maintainlevel": "1"}), + 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") @@ -149,6 +367,68 @@ class TestUpdatePackage(OperateTestBase): resp_dict.get("data"), 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__': - unittest.main() + self.assertIn("data", resp_dict, msg="Error in data format return") + self.assertIsNone( + resp_dict.get("data"), + msg="Error in data information return") diff --git a/packageship/test/write_test.py b/packageship/test/write_test.py new file mode 100644 index 0000000000000000000000000000000000000000..dded68e6469b76a7db4d0668d77c0a647e958057 --- /dev/null +++ b/packageship/test/write_test.py @@ -0,0 +1,44 @@ +#!/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))