mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-04 05:46:16 +01:00
Add behave test for the 'token' command
This commit is contained in:
parent
933040425c
commit
86c91276de
@ -124,6 +124,28 @@ def step_impl(context):
|
|||||||
raise AssertionError(f"Stdout is not:\n{expected_str}\n\nActual stdout:\n{found_str}")
|
raise AssertionError(f"Stdout is not:\n{expected_str}\n\nActual stdout:\n{found_str}")
|
||||||
|
|
||||||
|
|
||||||
|
@behave.step("stdout matches")
|
||||||
|
def step_impl(context):
|
||||||
|
expected = context.text.format(context=context).rstrip()
|
||||||
|
found = context.cmd_stdout.rstrip()
|
||||||
|
|
||||||
|
if re.match(expected, found, re.MULTILINE):
|
||||||
|
return
|
||||||
|
|
||||||
|
raise AssertionError(f"Stdout doesn't match:\n{expected}\n\nActual stdout:\n{found}")
|
||||||
|
|
||||||
|
|
||||||
|
@behave.step("I search '{pattern}' in stdout and store named groups in '{context_attribute}'")
|
||||||
|
def step_impl(context, pattern, context_attribute):
|
||||||
|
pattern = r"{}".format(pattern)
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for match in re.finditer(pattern, context.cmd_stdout):
|
||||||
|
result.append(match.groupdict())
|
||||||
|
|
||||||
|
setattr(context, context_attribute, result)
|
||||||
|
|
||||||
|
|
||||||
@behave.step("stderr is")
|
@behave.step("stderr is")
|
||||||
def step_impl(context):
|
def step_impl(context):
|
||||||
expected = context.text.format(context=context).rstrip().split("\n")
|
expected = context.text.format(context=context).rstrip().split("\n")
|
||||||
|
38
behave/features/token.feature
Normal file
38
behave/features/token.feature
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Feature: `osc token` command
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Run `osc token` with no arguments
|
||||||
|
When I execute osc with args "token"
|
||||||
|
Then stdout is
|
||||||
|
"""
|
||||||
|
<directory count="0"/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Run `osc token --operation rebuild`
|
||||||
|
When I execute osc with args "token --create --operation rebuild test:factory test-pkgA"
|
||||||
|
Then stdout matches
|
||||||
|
"""
|
||||||
|
Create a new token
|
||||||
|
<status code="ok">
|
||||||
|
<summary>Ok</summary>
|
||||||
|
<data name="token">.*</data>
|
||||||
|
<data name="id">1</data>
|
||||||
|
</status>
|
||||||
|
"""
|
||||||
|
Given I execute osc with args "token"
|
||||||
|
And stdout matches
|
||||||
|
"""
|
||||||
|
<directory count="1">
|
||||||
|
<entry id="1" string=".*" kind="rebuild" description="" triggered_at="" project="test:factory" package="test-pkgA"/>
|
||||||
|
</directory>
|
||||||
|
"""
|
||||||
|
And I search 'string="(?P<token>[^"]+)' in stdout and store named groups in 'tokens'
|
||||||
|
When I execute osc with args "token --trigger {context.tokens[0][token]}"
|
||||||
|
Then stdout is
|
||||||
|
"""
|
||||||
|
Trigger token
|
||||||
|
<status code="ok">
|
||||||
|
<summary>Ok</summary>
|
||||||
|
</status>
|
||||||
|
"""
|
Loading…
Reference in New Issue
Block a user