Best Python code snippet using molecule_python
test_create.py
Source:test_create.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 create22@pytest.fixture23def _patched_create_setup(mocker):24 return mocker.patch("molecule.command.create.Create._setup")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.28def test_execute(29 mocker,30 patched_logger_info,31 command_patched_ansible_create,32 patched_config_validate,33 config_instance,34):35 c = create.Create(config_instance)36 c.execute()37 x = [mocker.call("Scenario: 'default'"), mocker.call("Action: 'create'")]38 assert x == patched_logger_info.mock_calls39 assert "docker" == config_instance.state.driver40 command_patched_ansible_create.assert_called_once_with()41 assert config_instance.state.created42@pytest.mark.parametrize(43 "config_instance", ["command_driver_delegated_section_data"], indirect=True44)45def test_execute_skips_when_delegated_driver(46 _patched_create_setup,47 patched_logger_warning,48 command_patched_ansible_create,49 config_instance,50):51 c = create.Create(config_instance)52 c.execute()53 msg = "Skipping, instances are delegated."54 patched_logger_warning.assert_called_once_with(msg)55 assert not command_patched_ansible_create.called56def test_execute_skips_when_instances_already_created(57 patched_logger_warning, command_patched_ansible_create, config_instance58):59 config_instance.state.change_state("created", True)60 c = create.Create(config_instance)61 c.execute()62 msg = "Skipping, instances already created."63 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!!