How to use has_jinja method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

stubber.py

Source:stubber.py Github

copy

Full Screen

1#!/usr/bin/python2# -*- coding: utf-8 -*-3#4# Copyright (c) 2017 F5 Networks Inc.5# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)6from __future__ import absolute_import, division, print_function7__metaclass__ = type8import os9import shutil10from .common import BASE_DIR11try:12 from jinja2 import Environment13 from jinja2 import FileSystemLoader14 HAS_JINJA = True15except ImportError:16 HAS_JINJA = False17if HAS_JINJA:18 JINJA_ENV = Environment(19 loader=FileSystemLoader(BASE_DIR + '/devtools/stubs')20 )21def module_file_present(module):22 module_file = '{0}/library/modules/{1}.py'.format(BASE_DIR, module)23 if os.path.exists(module_file):24 print('Module file "{0}" exists'.format(module_file))25 return True26 return False27def module_file_absent(module):28 result = module_file_present(module)29 return not result30def stub_roles_dirs(module):31 # Create role containing all of your future functional tests32 for d in ['defaults', 'tasks']:33 directory = '{0}/test/integration/targets/{1}/{2}'.format(BASE_DIR, module, d)34 if not os.path.exists(directory):35 os.makedirs(directory)36def stub_roles_yaml_files(module):37 # Create default vars to contain any playbook variables38 for dir in ['defaults', 'tasks']:39 defaults_file = '{0}/test/integration/targets/{1}/{2}/main.yaml'.format(40 BASE_DIR, module, dir41 )42 touch(defaults_file)43 for f in ['setup.yaml', 'teardown.yaml']:44 defaults_file = '{0}/test/integration/targets/{1}/tasks/{2}'.format(BASE_DIR, module, f)45 touch(defaults_file)46 main_tests = '{0}/test/integration/targets/{1}/tasks/main.yaml'.format(BASE_DIR, module)47 template = JINJA_ENV.get_template('test_integration_targets_main.yaml')48 content = template.render()49 with open(main_tests, 'w') as fh:50 fh.write(content)51def stub_playbook_file(module):52 # Stub out the test playbook53 playbook_file = '{0}/test/integration/{1}.yaml'.format(BASE_DIR, module)54 template = JINJA_ENV.get_template('playbooks_module.yaml')55 content = template.render(module=module)56 fh = open(playbook_file, 'w')57 fh.write(content)58 fh.close()59def stub_library_file(module, extension):60 # Create your new module python file61 library_file = '{0}/library/modules/{1}{2}'.format(BASE_DIR, module, extension)62 template = JINJA_ENV.get_template('library_module.py')63 content = template.render(module=module)64 fh = open(library_file, 'w')65 fh.write(content)66 fh.close()67def stub_module_documentation(module):68 # Create the documentation link for your module69 documentation_file = '{0}/docs/modules/{1}.rst'.format(BASE_DIR, module)70 touch(documentation_file)71def touch(name, times=None):72 with open(name, 'a'):73 os.utime(name, times)74def stub_unit_test_file(module, extension):75 test_dir_path = '{0}/test/unit/'.format(BASE_DIR)76 if not os.path.exists(test_dir_path):77 os.makedirs(test_dir_path)78 test_file = '{0}/test/unit/test_{1}{2}'.format(79 BASE_DIR, module, extension80 )81 template = JINJA_ENV.get_template('tests_unit_module.py')82 content = template.render(module=module)83 fh = open(test_file, 'w')84 fh.write(content)85 fh.close()86def unstub_roles_dirs(module):87 for dir in ['defaults', 'tasks']:88 directory = '{0}/test/integration/targets/{1}/{2}'.format(BASE_DIR, module, dir)89 if os.path.exists(directory):90 shutil.rmtree(directory)91def unstub_playbook_file(module):92 playbook_file = '{0}/test/integration/{1}.yaml'.format(BASE_DIR, module)93 if os.path.exists(playbook_file):94 os.remove(playbook_file)95def unstub_library_file(module, extension):96 library_file = '{0}/library/modules/{1}{2}'.format(BASE_DIR, module, extension)97 if os.path.exists(library_file):98 os.remove(library_file)99def unstub_module_documentation(module):100 documentation_file = '{0}/docs/modules/{1}.rst'.format(BASE_DIR, module)101 if os.path.exists(documentation_file):102 os.remove(documentation_file)103def unstub_unit_test_file(module, extension):104 test_dir_path = '{0}/test/unit/'.format(BASE_DIR)105 if not os.path.exists(test_dir_path):106 os.makedirs(test_dir_path)107 test_file = '{0}/test/unit/test_{1}{2}'.format(108 BASE_DIR, module, extension109 )110 if os.path.exists(test_file):...

Full Screen

Full Screen

collection.py

Source:collection.py Github

copy

Full Screen

1#!/usr/bin/python2# -*- coding: utf-8 -*-3#4# Copyright (c) 2017 F5 Networks Inc.5# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)6from __future__ import absolute_import, division, print_function7__metaclass__ = type8import os9import semver10import sys11from .lib.common import BASE_DIR12from invoke import task13from tasks.module import upstream as upstream_module14from tasks.module_utils import upstream as upstream_utils15from tasks.module_doc_fragments import upstream as upstream_doc16from tasks.plugins import upstream as upstream_plugins17try:18 from jinja2 import Environment19 from jinja2 import FileSystemLoader20 HAS_JINJA = True21except ImportError:22 HAS_JINJA = False23if HAS_JINJA:24 JINJA_ENV = Environment(25 loader=FileSystemLoader(BASE_DIR + '/devtools/stubs')26 )27BUILD_DIR = '{0}/local/ansible_collections/_builds'.format(BASE_DIR)28HELP = dict(29 filename="Name of the tarball file to be pubished found in _builds directory.",30 api_key="The api key from Ansible Galaxy to be used to upload",31 qa="Indicates if the target Galaxy environment is a Galaxy test site."32)33def update_galaxy_file(version, collection):34 # updates galaxy.yml file for collection update35 galaxy_file = '{0}/local/ansible_collections/f5networks/{1}/galaxy.yml'.format(BASE_DIR, collection)36 template = JINJA_ENV.get_template('collection_galaxy.yml')37 content = template.render(version=version, collection=collection)38 fh = open(galaxy_file, 'w')39 fh.write(content)40 fh.close()41def validate_version(version):42 try:43 semver.parse_version_info(version)44 except ValueError as ex:45 print(str(ex))46 sys.exit(1)47@task(optional=['collection', 'skiptest'], help=dict(48 version="Version of the collection to build, the version must follow in SemVer format.",49 collection="The collection name to which the modules are upstreamed, DEFAULT: 'f5_modules'.",50 update="Allows updating galaxy file when requested."51))52def build(c, version, collection='f5_modules', update=True):53 """Creates collection builds in the ansible_collections/_build directory."""54 validate_version(version)55 if update:56 update_galaxy_file(version, collection)57 if not os.path.exists(BUILD_DIR):58 os.makedirs(BUILD_DIR)59 coll_dest = '{0}/local/ansible_collections/f5networks/{1}'.format(BASE_DIR, collection)60 cmd = 'ansible-galaxy collection build {0} -f --output-path {1}'.format(coll_dest, BUILD_DIR)61 c.run(cmd)62@task(optional=['qa'], help=HELP)63def publish(c, filename, api_key, qa=None):64 """Publish collection on Galaxy."""65 file = '{0}/{1}'.format(BUILD_DIR, os.path.basename(filename))66 if not os.path.exists(file):67 print("Requested file {0} not found.".format(file))68 sys.exit(1)69 if qa:70 cmd = 'ansible-galaxy collection publish {0} --api-key={1} -s https://galaxy-qa.ansible.com/ '.format(file, api_key)71 else:72 cmd = 'ansible-galaxy collection publish {0} --api-key={1}'.format(file, api_key)73 c.run(cmd)74@task75def update_galaxy(c, version, collection='f5_modules'):76 """Updates galaxy.yml file"""77 validate_version(version)78 update_galaxy_file(version, collection)79 print("File galaxy.yml updated.")80@task81def make_local(c):82 """Creates local collection structure, used in local testing and debugging."""83 upstream_module(c, ['all'])84 upstream_utils(c)85 upstream_doc(c)86 upstream_plugins(c)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful