Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Requre testing #612

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repos:
rev: v2.2.3
hooks:
- id: check-added-large-files
exclude: tests_recording/test_data
- id: check-ast
- id: check-merge-conflict
- id: check-yaml
Expand Down
78 changes: 1 addition & 77 deletions tests/integration/test_base_git.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import pytest
from git import PushInfo

from flexmock import flexmock
from packit.actions import ActionName
from packit.base_git import PackitRepositoryBase
from packit.exceptions import PackitException
from packit.config import Config, PackageConfig, RunCommandType
from packit.local_project import LocalProject
from tests.spellbook import can_a_module_be_imported
from packit.config import Config, PackageConfig


@pytest.mark.parametrize(
Expand All @@ -28,75 +24,3 @@ def test_get_output_from_action_defined(echo_cmd, expected_output):

result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
assert result == expected_output


@pytest.mark.skipif(
not can_a_module_be_imported("sandcastle"), reason="sandcastle is not installed"
)
def test_get_output_from_action_defined_in_sandcastle():
from sandcastle.api import Sandcastle

echo_cmd = "hello world"
flexmock(Sandcastle).should_receive("get_api_client")
flexmock(Sandcastle).should_receive("is_pod_already_deployed").and_return(True)
c = Config()
c.command_handler = RunCommandType.sandcastle
packit_repository_base = PackitRepositoryBase(
config=c, package_config=PackageConfig(actions={ActionName.pre_sync: echo_cmd})
)
packit_repository_base.local_project = LocalProject()

flexmock(Sandcastle).should_receive("run")
flexmock(Sandcastle).should_receive("exec").and_return(echo_cmd)
flexmock(Sandcastle).should_receive("delete_pod").and_return(None)
result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
assert result[-1] == echo_cmd


@pytest.mark.skip(
reason="Skipping since we don't have an OpenShift cluster by default."
)
def test_run_in_sandbox():
packit_repository_base = PackitRepositoryBase(
config=Config(),
package_config=PackageConfig(actions={ActionName.pre_sync: "ls -lha"}),
)
packit_repository_base.config.actions_handler = "sandcastle"

result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
assert "total 4.0K" in result
assert "drwxr-xr-x. 1 root root" in result


def test_base_push_bad(distgit_and_remote):
distgit, _ = distgit_and_remote

b = PackitRepositoryBase(config=Config(), package_config=PackageConfig())
b.local_project = LocalProject(
working_dir=str(distgit), git_url="https://github.com/packit-service/lol"
)
flexmock(
LocalProject,
push=lambda *args, **kwargs: [
PushInfo(PushInfo.REMOTE_REJECTED, None, None, None, None)
],
)
with pytest.raises(PackitException) as e:
b.push("master")
assert "unable to push" in str(e.value)


def test_base_push_good(distgit_and_remote):
distgit, _ = distgit_and_remote

b = PackitRepositoryBase(config=Config(), package_config=PackageConfig())
b.local_project = LocalProject(
working_dir=str(distgit), git_url="https://github.com/packit-service/lol"
)
flexmock(
LocalProject,
push=lambda *args, **kwargs: [
PushInfo(PushInfo.FAST_FORWARD, None, None, None, None)
],
)
b.push("master")
39 changes: 0 additions & 39 deletions tests/integration/test_distgit.py

This file was deleted.

20 changes: 20 additions & 0 deletions tests/integration/test_openshift.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from packit.actions import ActionName
from packit.base_git import PackitRepositoryBase
from packit.config import Config, PackageConfig


@pytest.mark.skip(
reason="Skipping since we don't have an OpenShift cluster by default."
)
def test_run_in_sandbox():
packit_repository_base = PackitRepositoryBase(
config=Config(),
package_config=PackageConfig(actions={ActionName.pre_sync: "ls -lha"}),
)
packit_repository_base.config.actions_handler = "sandcastle"

result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
assert "total 4.0K" in result
assert "drwxr-xr-x. 1 root root" in result
72 changes: 0 additions & 72 deletions tests/integration/test_pagure.py

This file was deleted.

31 changes: 31 additions & 0 deletions tests/integration/test_sandcastle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest

from flexmock import flexmock
from packit.actions import ActionName
from packit.base_git import PackitRepositoryBase
from packit.config import Config, PackageConfig, RunCommandType
from packit.local_project import LocalProject
from tests.spellbook import can_a_module_be_imported


@pytest.mark.skipif(
not can_a_module_be_imported("sandcastle"), reason="sandcastle is not installed"
)
def test_get_output_from_action_defined_in_sandcastle():
from sandcastle.api import Sandcastle

echo_cmd = "hello world"
flexmock(Sandcastle).should_receive("get_api_client")
flexmock(Sandcastle).should_receive("is_pod_already_deployed").and_return(True)
c = Config()
c.command_handler = RunCommandType.sandcastle
packit_repository_base = PackitRepositoryBase(
config=c, package_config=PackageConfig(actions={ActionName.pre_sync: echo_cmd})
)
packit_repository_base.local_project = LocalProject()

flexmock(Sandcastle).should_receive("run")
flexmock(Sandcastle).should_receive("exec").and_return(echo_cmd)
flexmock(Sandcastle).should_receive("delete_pod").and_return(None)
result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
assert result[-1] == echo_cmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from tests.testsuite_basic.spellbook import SPECFILE

from packit.specfile import Specfile
from rebasehelper.specfile import SpecContent

from tests.spellbook import SPECFILE


def test_write_spec_content():
with open(SPECFILE) as spec:
Expand Down
24 changes: 0 additions & 24 deletions tests/integration/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import subprocess
from pathlib import Path

import pytest

from flexmock import flexmock
from packit.api import PackitAPI, Config
from packit.config import parse_loaded_config
Expand All @@ -32,28 +30,6 @@
from tests.spellbook import TARBALL_NAME


@pytest.fixture()
def github_release_webhook():
return {
"repository": {
"full_name": "brewery/beer",
"owner": {"login": "brewery"},
"name": "beer",
"html_url": "https://github.com/brewery/beer",
},
"release": {
"body": "Changelog content will be here",
"tag_name": "0.1.0",
"created_at": "2019-02-28T18:48:27Z",
"published_at": "2019-02-28T18:51:10Z",
"draft": False,
"prerelease": False,
"name": "Beer 0.1.0 is gooooood",
},
"action": "published",
}


def test_basic_local_update(
cwd_upstream, api_instance, mock_remote_functionality_upstream
):
Expand Down
8 changes: 7 additions & 1 deletion tests_recording/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from requre.helpers.files import StoreFiles
from requre.helpers.function_output import store_function_output
from requre.helpers.git.fetchinfo import RemoteFetch
from requre.helpers.git.pushinfo import PushInfoStorageList
from requre.helpers.requests_response import RequestResponseHandling
from requre.helpers.tempfile import TempFile
Expand Down Expand Up @@ -31,6 +32,12 @@
what="FedPKG.clone",
decorator=StoreFiles.arg_references(files_params={"target_path": 2}),
)
.decorate(
where="git",
who_name="local_project",
what="remote.Remote.fetch",
decorator=RemoteFetch.decorator_plain,
)
.decorate(
where="git",
who_name="local_project",
Expand All @@ -45,7 +52,6 @@
"gitlab",
"github.MainClass",
"github.Requester",
"ogr.services.github_tweak",
],
decorator=RequestResponseHandling.decorator(item_list=[]),
)
Expand Down