def test_get_path_for_active_scenario_dir_from_envar_and_create( tmpdir, service: BaseService, scenario_dir_exists: bool, scenario_dir_envar: Optional[str], expected_generated_path: str, ): scenarios_dir = tmpdir.join('scenarios').mkdir() if scenario_dir_exists: scenarios_dir.join('test_scenario').mkdir() scenarios_dir.join('test_scenario').join('TestService').mkdir() assert scenarios_dir.join('test_scenario').join('TestService').exists() else: assert not scenarios_dir.join('test_scenario').join( 'TestService').exists() with patch.dict( environ, {'SCENARIOS_PATH': scenario_dir_envar.format(tmpdir=tmpdir)}): result_generated_path = service.get_path_for_active_scenario_dir( create=True) expected_generated_path = Path( expected_generated_path.format(tmpdir=tmpdir)) assert result_generated_path == expected_generated_path assert scenarios_dir.join('test_scenario').join('TestService').exists()
def test_get_path_for_active_scenario_dir_from_default_do_not_create_already_exists( in_tmpdir, service: BaseService, ): scenarios_dir = in_tmpdir.join('scenarios').mkdir() assert not scenarios_dir.join('test_scenario').join('TestService').exists() result_generated_path = service.get_path_for_active_scenario_dir( create=False) expected_generated_path = Path( './scenarios/test_scenario/TestService/'.format(tmpdir=in_tmpdir)) assert result_generated_path == expected_generated_path assert not scenarios_dir.join('test_scenario').join('TestService').exists()
def test_get_path_for_active_scenario_dir_from_envar_do_not_create( tmpdir, service: BaseService, ): scenarios_dir = tmpdir.join('scenarios').mkdir() assert not scenarios_dir.join('test_scenario').join('TestService').exists() with patch.dict( environ, {'SCENARIOS_PATH': '{tmpdir}/scenarios/'.format(tmpdir=tmpdir)}): result_generated_path = service.get_path_for_active_scenario_dir( create=False) expected_generated_path = Path( '{tmpdir}/scenarios/test_scenario/TestService/'.format( tmpdir=tmpdir)) assert result_generated_path == expected_generated_path assert not scenarios_dir.join('test_scenario').join( 'TestService').exists()