1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-10-31 19:42:16 +01:00

behave: Add osc fork test

This commit is contained in:
Andrii Nikitin
2025-04-22 23:27:24 +02:00
committed by Daniel Mach
parent 8ea352270a
commit ddef2a11cc
6 changed files with 36 additions and 8 deletions

View File

@@ -81,15 +81,16 @@ def before_all(context):
context.podman = podman.ThreadedPodman(context, container_name_prefix="osc-behave-", max_containers=podman_max_containers)
else:
context.podman = podman.Podman(context, container_name="osc-behave")
context.osc = osc.Osc(context)
context.git_obs = osc.GitObs(context)
context.git_osc_precommit_hook = osc.GitOscPrecommitHook(context)
# we reference git_obs here, so initialize osc after it
context.osc = osc.Osc(context)
def after_all(context):
del context.osc
del context.git_osc_precommit_hook
del context.git_obs
del context.osc
context.podman.kill()
del context.podman
del context.fixtures

View File

@@ -0,0 +1,12 @@
Feature: `osc fork` command
Background:
Given I set working directory to "{context.osc.temp}"
@destructive
Scenario: Fork a git repo
When I execute osc with args "fork test:factory test-GitPkgA"
Then the exit code is 0
And stdout contains " scmsync URL: "
And stdout contains "/Admin/test-GitPkgA#factory"

View File

@@ -64,10 +64,15 @@ def run_in_context(context, cmd, can_fail=False, **run_args):
if hasattr(context.scenario, "working_dir") and 'cwd' not in run_args:
run_args['cwd'] = context.scenario.working_dir
if hasattr(context.scenario, "PATH"):
env = os.environ.copy()
# let's temporarily pass GIT_OBS_CONFIG through environment variable until other methods work
if not env.get("GIT_OBS_CONFIG"):
env["GIT_OBS_CONFIG"] = context.git_obs.config
if hasattr(context.scenario, "PATH"):
path = context.scenario.PATH
env["PATH"] = path.replace("$PATH", env["PATH"])
run_args["env"] = env
debug(context, "Running command:", cmd)

View File

@@ -47,6 +47,9 @@ class Osc(CommandBase):
def write_config(self, username=None, password=None):
with open(self.config, "w") as f:
f.write("[general]\n")
# this doesn't work and as workaround initialize environment variable in steps/common.py
if self.context.git_obs.config:
f.write(f"gitea_config={self.context.git_obs.config}\n")
f.write("\n")
f.write(f"[https://localhost:{self.context.podman.container.ports['obs_https']}]\n")
f.write(f"user={username or 'Admin'}\n")

View File

@@ -165,6 +165,9 @@ class Command:
because it disables argument intermixing.
"""
def post_parse_args(self, args):
pass
def run(self, args):
"""
Override to implement the command functionality.
@@ -214,6 +217,7 @@ class MainCommand(Command):
if not cmd:
self.parser.error("Please specify a command")
self.post_parse_args(args)
cmd.post_parse_args(args)
return cmd.run(args)
def load_command(self, cls, module_prefix):

View File

@@ -38,13 +38,16 @@ class Login(BaseModel):
def __str__(self):
if self.kwargs == {"name": None}:
return \
"Could not find a default Gitea config entry\n" \
" * either set the default entry by running `git-obs login edit <login> --set-as-default`\n" \
return (
"Could not find a default Gitea config entry\n"
" * either set the default entry by running `git-obs login update <login> --set-as-default`\n"
" * or run the command with `-G/--gitea-login <login>` option"
)
kwargs_str = ", ".join([f"{key}={value}" for key, value in self.kwargs.items()])
return f"Could not find a matching Gitea config entry: {kwargs_str}\n" \
return (
f"Could not find a matching Gitea config entry: {kwargs_str}\n"
" * see `git-obs login list` for valid entries"
)
def __init__(self, **kwargs):
# ignore extra fields