Best Python code snippet using molecule_python
test_idempotence.py
Source:test_idempotence.py
...19# DEALINGS IN THE SOFTWARE.20import pytest21from molecule.command import idempotence22@pytest.fixture23def _patched_is_idempotent(mocker):24 return mocker.patch("molecule.command.idempotence.Idempotence._is_idempotent")25# NOTE(retr0h): The use of the `patched_config_validate` fixture, disables26# config.Config._validate from executing. Thus preventing odd side-effects27# throughout patched.assert_called unit tests.28@pytest.fixture29def _instance(patched_config_validate, config_instance):30 config_instance.state.change_state("converged", True)31 return idempotence.Idempotence(config_instance)32def test_execute(33 mocker,34 patched_logger_info,35 patched_ansible_converge,36 _patched_is_idempotent,37 patched_logger_success,38 _instance,39):40 _instance.execute()41 x = [mocker.call("Scenario: 'default'"), mocker.call("Action: 'idempotence'")]42 assert x == patched_logger_info.mock_calls43 patched_ansible_converge.assert_called_once_with(out=None, err=None)44 _patched_is_idempotent.assert_called_once_with("patched-ansible-converge-stdout")45 msg = "Idempotence completed successfully."46 patched_logger_success.assert_called_once_with(msg)47def test_execute_raises_when_not_converged(48 patched_logger_critical, patched_ansible_converge, _instance49):50 _instance._config.state.change_state("converged", False)51 with pytest.raises(SystemExit) as e:52 _instance.execute()53 assert 1 == e.value.code54 msg = "Instances not converged. Please converge instances first."55 patched_logger_critical.assert_called_once_with(msg)56def test_execute_raises_when_fails_idempotence(57 mocker,58 patched_logger_critical,59 patched_ansible_converge,60 _patched_is_idempotent,61 _instance,62):63 _patched_is_idempotent.return_value = False64 with pytest.raises(SystemExit) as e:65 _instance.execute()66 assert 1 == e.value.code67 msg = "Idempotence test failed because of the following tasks:\n"68 patched_logger_critical.assert_called_once_with(msg)69def test_is_idempotent(_instance):70 output = """71PLAY RECAP ***********************************************************72check-command-01: ok=3 changed=0 unreachable=0 failed=073 """74 assert _instance._is_idempotent(output)75def test_is_idempotent_not_idempotent(_instance):76 output = """77PLAY RECAP ***********************************************************78check-command-01: ok=2 changed=1 unreachable=0 failed=079check-command-02: ok=2 changed=1 unreachable=0 failed=080 """81 assert not _instance._is_idempotent(output)82def test_non_idempotent_tasks_idempotent(_instance):83 output = """84PLAY [all] ***********************************************************85GATHERING FACTS ******************************************************86ok: [check-command-01]87TASK: [Idempotence test] *********************************************88ok: [check-command-01]89PLAY RECAP ***********************************************************90check-command-01: ok=3 changed=0 unreachable=0 failed=091"""92 result = _instance._non_idempotent_tasks(output)93 assert result == []94def test_non_idempotent_tasks_not_idempotent(_instance):95 output = """...
request.py
Source:request.py
1import requests2IDEMPOTENT_HTTP_METHODS = frozenset(['HEAD', 'GET', 'PUT', 'DELETE', 'OPTIONS', 'TRACE'])3class ApiRequest(requests.Request):4 def __init__(self, *args, **kwargs):5 try:6 self._is_idempotent = kwargs.pop('is_idempotent')7 except KeyError:8 pass9 self.raw_response = kwargs.pop('raw_response', False)10 super().__init__(*args, **kwargs)11 @property12 def is_idempotent(self):13 """By default it's method agnostic."""14 try:15 return self._is_idempotent16 except AttributeError:17 return self.method in IDEMPOTENT_HTTP_METHODS18 @is_idempotent.setter19 def is_idempotent(self, value):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!