Esempio n. 1
0
def test_execution_order():
    rule_1 = ExampleRule(name="rule_1", param="rule_1")
    rule_2 = ExampleRule(name="rule_2", param="rule_2")
    rule_3 = ExampleRule(name="rule_3", param="rule_3")

    rule_1.get_execution_order = Mock(return_value=[])
    rule_2.get_execution_order = Mock(return_value=[])
    rule_3.get_execution_order = Mock(return_value=[])

    law = Law(name="Passing", description="passing law", rules=(rule_1, rule_2, rule_3))
    law.get_execution_order()

    rule_1.get_execution_order.assert_called_once_with()
    rule_2.get_execution_order.assert_called_once_with()
    rule_3.get_execution_order.assert_called_once_with()
Esempio n. 2
0
def test_commit_no_changes():
    rule = get_passing_rule()
    rule.execute = Mock()
    rule.made_changes = False

    law = Law(name="Passing", description="passing law", rules=(rule,))
    law.git_commit = Mock()
    law.get_execution_order = Mock(return_value=[rule])

    law.enforce()

    rule.execute.assert_called_once_with()
    assert law.git_commit.called is False
Esempio n. 3
0
def test_commit_changes():
    rule = get_passing_rule()
    rule.execute = Mock()
    rule.made_changes = True

    law = Law(name="Passing", description="passing law", rules=(rule,))
    law.git_commit = Mock()
    law.get_execution_order = Mock(return_value=[rule])

    expected_commit_message = f"{law.documentation}\n\n* {rule.name}"

    law.enforce()

    rule.execute.assert_called_once_with()
    law.get_execution_order.assert_called_once_with()
    law.git_commit.assert_called_once_with(expected_commit_message)