Best Python code snippet using molecule_python
test_destroy.py
Source:test_destroy.py
1# Copyright (c) 2015-2018 Cisco Systems, Inc.2#3# Permission is hereby granted, free of charge, to any person obtaining a copy4# of this software and associated documentation files (the "Software"), to5# deal in the Software without restriction, including without limitation the6# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or7# sell copies of the Software, and to permit persons to whom the Software is8# furnished to do so, subject to the following conditions:9#10# The above copyright notice and this permission notice shall be included in11# all copies or substantial portions of the Software.12#13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING18# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER19# DEALINGS IN THE SOFTWARE.20import pytest21from molecule.command import destroy22@pytest.fixture23def _patched_ansible_destroy(mocker):24 return mocker.patch("molecule.provisioner.ansible.Ansible.destroy")25@pytest.fixture26def _patched_destroy_setup(mocker):27 return mocker.patch("molecule.command.destroy.Destroy._setup")28# NOTE(retr0h): The use of the `patched_config_validate` fixture, disables29# config.Config._validate from executing. Thus preventing odd side-effects30# throughout patched.assert_called unit tests.31def test_execute(32 mocker,33 patched_logger_info,34 patched_config_validate,35 _patched_ansible_destroy,36 config_instance,37):38 d = destroy.Destroy(config_instance)39 d.execute()40 x = [mocker.call("Scenario: 'default'"), mocker.call("Action: 'destroy'")]41 assert x == patched_logger_info.mock_calls42 _patched_ansible_destroy.assert_called_once_with()43 assert not config_instance.state.converged44 assert not config_instance.state.created45@pytest.mark.parametrize(46 "config_instance", ["command_driver_delegated_section_data"], indirect=True47)48def test_execute_skips_when_destroy_strategy_is_never(49 _patched_destroy_setup,50 patched_logger_warning,51 _patched_ansible_destroy,52 config_instance,53):54 config_instance.command_args = {"destroy": "never"}55 d = destroy.Destroy(config_instance)56 d.execute()57 msg = "Skipping, '--destroy=never' requested."58 patched_logger_warning.assert_called_once_with(msg)59 assert not _patched_ansible_destroy.called60@pytest.mark.parametrize(61 "config_instance", ["command_driver_delegated_section_data"], indirect=True62)63def test_execute_skips_when_delegated_driver(64 _patched_destroy_setup,65 patched_logger_warning,66 _patched_ansible_destroy,67 config_instance,68):69 d = destroy.Destroy(config_instance)70 d.execute()71 msg = "Skipping, instances are delegated."72 patched_logger_warning.assert_called_once_with(msg)...
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!!