diff --git a/core/getdate.py b/core/getdate.py index 173fdd03dee1a285af10393655deb58d58d12f0d..6ef8484397fb928c52993f0a0609b1d65224d966 100644 --- a/core/getdate.py +++ b/core/getdate.py @@ -51,6 +51,7 @@ class GETDate(object): self.sourcedir = "/srv/cache/obs/tar_scm/repo/next/" self.pkg_time = {} self.realdir = None + self.clone_path = os.getcwd() def _get_realdir(self): """ @@ -170,8 +171,8 @@ class GETDate(object): push the latest obs_pkg_rpms to origin """ for i in range(5): - push_cmd = "cd obs_pkg_rpms && git add * && \ - git commit -m 'update for package' && git push && cd -" + push_cmd = "cd %s/obs_pkg_rpms && git pull && git add -A && \ + git commit -m 'update for package' && git push" % self.clone_path push_result = subprocess.getstatusoutput(push_cmd) log.info(push_result) if "nothing to commit" in push_result[1]: diff --git a/test/test_check_obs_service.py b/test/test_check_obs_service.py new file mode 100644 index 0000000000000000000000000000000000000000..4d52fef7de1a3390babee9191ebced84c05b68ff --- /dev/null +++ b/test/test_check_obs_service.py @@ -0,0 +1,149 @@ +#/bin/env python3 +# -*- encoding=utf8 -*- +#****************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Author: yaokai13 +# Create: 2021-06-15 +# ***************************************************************************** +""" +test all: python3 -m pytest -s test_check_obs_service.py +test one class: python3 -m pytest -s test_check_obs_service.py::TestCase +test one class one case: python3 -m pytest -s test_check_obs_service.py::TestCase::test_1 +""" +import os +import sys +import pytest +current_path = os.path.join(os.path.split(os.path.realpath(__file__))[0]) +sys.path.append(os.path.join(current_path, "..")) +from func import SetEnv, CommonFunc +from core.check_meta_service import CheckMetaPull +from common.common import Pexpect + +S = SetEnv() +C = CommonFunc() + +class TestCase(object): + def setup_class(self): + S.set_oscrc() + S.set_gitee() + cmd_result = os.system("sed -i 's/master...thispr/HEAD~1 HEAD~0/g' ../core/check_meta_service.py") + if cmd_result != 0: + assert False + + def teardown_class(self): + S.unset_oscrc() + S.unset_gitee() + cmd_result = os.system("sed -i 's/HEAD~1 HEAD~0/master...thispr/g' ../core/check_meta_service.py") + if cmd_result != 0: + assert False + + def test_1(self): + """ + test obs_meta commit for modifiy service : Service Correct + """ + kw = { + "branch": "", + "pr_id": "751", + "access_token": "***" + } + check1 = CheckMetaPull(**kw) + try: + check1.do_all() + except SystemExit: + assert False + else: + assert True + + def test_2(self): + """ + test error service for given branch : Branch have no wrong service + """ + kw = { + "branch": "openEuler-20.03-LTS", + "pr_id": "", + "access_token": "***" + } + check2 = CheckMetaPull(**kw) + try: + check2.do_all() + except SystemExit: + assert False + else: + assert True + + def test_3(self): + """ + test the meta file commit for obs_meta : The meta file have a correct format + """ + kw = { + "branch": "", + "pr_id": "698", + "access_token": "***" + } + check3 = CheckMetaPull(**kw) + try: + check3.do_all() + except SystemExit: + assert False + else: + assert True + + + def test_4(self): + """ + test obs_meta commit for modifiy service : Service Error + """ + kw = { + "branch": "", + "pr_id": "744", + "access_token": "***" + } + check4 = CheckMetaPull(**kw) + try: + check4.do_all() + except SystemExit: + assert True + else: + assert False + + def test_5(self): + """ + test obs_meta commit for meta file : The meta file have a wrong format + """ + kw = { + "branch": "", + "pr_id": "731", + "access_token": "***" + } + check4 = CheckMetaPull(**kw) + try: + check4.do_all() + except SystemExit: + assert False + else: + assert True + + def test_6(self): + """ + test error service for given branch : Branch have wrong service + """ + kw = { + "branch": "openEuler-20.03-LTS-SP1", + "pr_id": "", + "access_token": "***" + } + check2 = CheckMetaPull(**kw) + try: + check2.do_all() + except SystemExit: + assert True + else: + assert False