Beispiel #1
0
def record_git_module(
    _func=None,
    cassette: Optional[Cassette] = None,
):
    decorators = [
        (
            "git.repo.base.Repo.clone_from",
            StoreFiles.where_arg_references(
                key_position_params_dict={"to_path": 2},
                output_cls=Repo,
                cassette=cassette,
            ),
        ),
        (
            "git.remote.Remote.push",
            PushInfoStorageList.decorator_plain(),
        ),
        ("git.remote.Remote.fetch", FetchInfoStorageList.decorator_plain()),
        ("git.remote.Remote.pull", FetchInfoStorageList.decorator_plain()),
    ]
    record_git_decorator = replace_module_match_with_multiple_decorators(
        *decorators,
        cassette=cassette,
    )

    if _func is not None:
        return record_git_decorator(_func)
    else:
        return record_git_decorator
Beispiel #2
0
    def execute(cls, keys: list, func: Callable, *args, **kwargs) -> Any:
        """
        Class method to store or read object from persistent storage
        with explicit set of *args, **kwargs parameters to use as keys
        :param keys: list of keys used as parameter
        :param func: original function
        :param args: parameters of original function
        :param kwargs: parameters of original function
        :return: output of called func
        """

        output = super().execute(keys, func, *args, **kwargs)
        git_object = args[0]
        remote_url = git_object.repo.remotes[git_object.name].url
        if os.path.isdir(remote_url):
            StoreFiles.explicit_reference(remote_url)
        return output
Beispiel #3
0
    def execute(cls, keys: list, func: Callable, *args, **kwargs) -> Any:
        """
        Class method to store or read object from persistent storage
        with explicit set of *args, **kwargs parameters to use as keys
        :param keys: list of keys used as parameter
        :param func: original function
        :param args: parameters of original function
        :param kwargs: parameters of original function
        :return: output of called func
        """

        output = super().execute(keys, func, *args, **kwargs)
        git_object = args[0]
        git_dir = git_object.repo.git_dir
        StoreFiles.explicit_reference(git_dir)
        if not PersistentObjectStorage().do_store(keys):
            # mimic the code in git for read mode for Remote.fetch
            # https://github.com/gitpython-developers/GitPython/blob/master/git/remote.py
            if hasattr(git_object.repo.odb, "update_cache"):
                git_object.repo.odb.update_cache()
        return output
Beispiel #4
0
 def test_base(self):
     """
     verify if tar archive is in persistent storage
     """
     filename = "some_random_name"
     self.create_temp_dir()
     self.create_dir_content(filename=filename,
                             target_dir=self.temp_dir,
                             content="ciao")
     tar_data = PersistentObjectStorage(
     ).cassette.content["X"]["file"]["tar"]["StoreFiles"][
         "storage_test.yaml"]["target_dir"][0]["output"]["filename"]
     with BytesIO(
             StoreFiles.read_file_content(cassette=self.cassette,
                                          file_name=tar_data)) as tar_byte:
         with tarfile.open(mode="r:xz", fileobj=tar_byte) as tar_archive:
             self.assertIn(filename,
                           [x.name for x in tar_archive.getmembers()][-1])
Beispiel #5
0
from requre.helpers.git.pushinfo import PushInfoStorageList
from requre.helpers.git.fetchinfo import FetchInfoStorageList
from requre.helpers.git.repo import Repo

from packit.api import PackitAPI
from tests_recording.testbase import PackitTest


@record_requests_for_all_methods()
@apply_decorator_to_all_methods(
    replace_module_match(what="packit.utils.run_command_remote",
                         decorate=Simple.decorator_plain()))
@apply_decorator_to_all_methods(
    replace_module_match(
        what="packit.fedpkg.FedPKG.clone",
        decorate=StoreFiles.where_arg_references(
            key_position_params_dict={"target_path": 2}),
    ))
@apply_decorator_to_all_methods(
    replace_module_match(
        what="git.repo.base.Repo.clone_from",
        decorate=StoreFiles.where_arg_references(
            key_position_params_dict={"to_path": 2},
            return_decorator=Repo.decorator_plain,
        ),
    ))
@apply_decorator_to_all_methods(
    replace_module_match(what="git.remote.Remote.push",
                         decorate=PushInfoStorageList.decorator_plain()))
@apply_decorator_to_all_methods(
    replace_module_match(what="git.remote.Remote.fetch",
                         decorate=FetchInfoStorageList.decorator_plain()))
Beispiel #6
0
    record_requests_module,
    record_tempfile_module,
    record_git_module,
)


@record_tempfile_module
@record_requests_module
@record_git_module
@apply_decorator_to_all_methods(
    replace_module_match(what="packit.utils.run_command_remote",
                         decorate=Simple.decorator_plain()))
@apply_decorator_to_all_methods(
    replace_module_match(
        what="packit.pkgtool.PkgTool.clone",
        decorate=StoreFiles.where_arg_references(
            key_position_params_dict={"target_path": 2}),
    ))
@apply_decorator_to_all_methods(
    replace_module_match(what="copr.v3.helpers.config_from_file",
                         decorate=Simple.decorator_plain()))
class ProposeUpdate(PackitTest):
    def cassette_setup(self, cassette):
        cassette.data_miner.data_type = DataTypes.Dict

    def setUp(self):
        super().setUp()
        self.configure_git()
        self._api = None

    @property
    def api(self):
Beispiel #7
0
     where="^requests$",
     who_name=["lookaside_cache_helper", "^copr", "packit.distgit"],
     what="Session.send",
     decorator=RequestResponseHandling.decorator_plain,
 )
 .replace_module(where="^tempfile$", who_name="^packit", replacement=TempFile)
 .decorate(
     where="^packit$",
     who_name="fedpkg",
     what="utils.run_command_remote",
     decorator=Simple.decorator_plain,
 )
 .decorate(
     where="packit.fedpkg",
     what="FedPKG.clone",
     decorator=StoreFiles.arg_references(files_params={"target_path": 2}),
 )
 .decorate(
     where="git",
     who_name="local_project",
     what="remote.Remote.push",
     decorator=PushInfoStorageList.decorator_plain,
 )
 .decorate(
     where="git",
     who_name="local_project",
     what="remote.Remote.fetch",
     decorator=RemoteFetch.decorator_plain,
 )
 .decorate(
     where="git",