Beispiel #1
0
def test_generate_pull_request_body_no_changes_no_passing_law():
    failing_rule = ExampleRule(name="Test failed rule 1", param=Mock())
    failing_rule.made_changes = False

    law_3 = Law(
        name="Test law 3", description="Test description 3", rules=[failing_rule]
    )

    law_3.rules[0].made_changes = False
    law_3._failed_rules = (failing_rule,)

    mocked_pillar = Mock()
    mocked_pillar.laws = [law_3]

    expected_body = """## Description
Below you can find the executed laws and information about them.

### Test law 3
Test description 3

<details open>
<summary>Failed rules (manual fix needed)</summary>

* Test failed rule 1
</details>"""

    pr_helper = get_pull_request_helper_mixin_consumer()

    body = pr_helper.generate_pull_request_body(mocked_pillar)

    assert body == expected_body
Beispiel #2
0
def test_generate_pull_request_body_with_chained_rules():
    failed_rule = ExampleRule(
        name="Test failed rule 1",
        param=Mock(),
        preconditions=[PASSING_PRECONDITION],
        children=[get_passing_rule("Child rule")],
    )

    failed_rule.made_changes = False

    passing_rule = ExampleRule(
        name="Test rule 1",
        param=Mock(),
        preconditions=[PASSING_PRECONDITION],
        children=[get_passing_rule("Passing child rule")],
    )

    failed_execution_law = Law(
        name="Test law 1",
        description="Test description 1",
        rules=[passing_rule, failed_rule],
    )

    failed_execution_law._failed_rules = (failed_rule,)

    mocked_pillar = Mock()
    mocked_pillar.laws = [
        failed_execution_law,
        Law(
            name="Test law 2",
            description="Test description 2",
            rules=[ExampleRule(name="Test rule 2", param=Mock())],
        ),
        Law(
            name="Test law 3",
            description="Test description 3",
            rules=[
                ExampleRule(name="Test rule 3", param=Mock()),
                ExampleRule(name="Test rule 4", param=Mock()),
            ],
        ),
    ]

    expected_body = """## Description
Below you can find the executed laws and information about them.

### Test law 1
Test description 1

<details>
<summary>Passed rules</summary>

* Test rule 1
  * Passing child rule
</details>

<details open>
<summary>Failed rules (manual fix needed)</summary>

* Test failed rule 1
  * Child rule
</details>

### Test law 2
Test description 2

<details>
<summary>Passed rules</summary>

* Test rule 2
</details>

### Test law 3
Test description 3

<details>
<summary>Passed rules</summary>

* Test rule 3
* Test rule 4
</details>"""

    pr_helper = get_pull_request_helper_mixin_consumer()

    body = pr_helper.generate_pull_request_body(mocked_pillar)

    assert body == expected_body