Best Python code snippet using localstack_python
test_facts.py
Source: test_facts.py
1import os2import re3import sys4import unittest5import yaml6import module_utils.helpers as helpers7sys.modules['ansible.module_utils.helpers'] = helpers8import library.cartridge_validate_config as validate_config9import unit.test_validate_config as test_validate_config10# This tests protects against inattentive people, who do not completely change the variables list11class TestFacts(unittest.TestCase):12 def setUp(self):13 self.maxDiff = None14 role_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')15 self.defaults_file = os.path.join(role_dir, 'defaults', 'main.yml')16 with open(self.defaults_file, 'r') as f:17 try:18 self.defaults = yaml.safe_load(f)19 self.cached_facts_names = self.defaults['cartridge_cached_fact_names_by_target']20 except yaml.YAMLError as e:21 self.fail("Impossible to parse 'defaults/main.yml': %s" % e)22 self.set_instance_facts_file = os.path.join(role_dir, 'tasks', 'set_instance_facts.yml')23 with open(self.set_instance_facts_file, 'r') as f:24 try:25 self.set_instance_facts = yaml.safe_load(f)26 except yaml.YAMLError as e:27 self.fail("Impossible to parse 'tasks/set_instance_facts.yml': %s" % e)28 self.doc_facts_file = os.path.join(role_dir, 'doc', 'variables.md')29 with open(self.doc_facts_file, 'r') as f:30 text = f.read()31 self.doc_facts = re.findall(r'\n[*-][^`]*`([^`]+)`', text)32 self.validate_config_facts = list(validate_config.SCHEMA.keys())33 self.test_validate_config_facts = set()34 for params in test_validate_config.PARAMS_BY_TYPES.values():35 for param in params:36 self.test_validate_config_facts.add(param.split('.')[0].split('[')[0])37 self.test_validate_config_facts = list(self.test_validate_config_facts)38 self.not_user_facts = [39 # Role defaults40 'cartridge_role_scenarios',41 'cartridge_cached_fact_names_by_target',42 # Cross-step facts43 'delivered_package_path',44 'control_instance',45 'temporary_files',46 'needs_restart',47 'cluster_disabled_instances',48 'inventory_disabled_instances',49 'alive_not_expelled_instance',50 'instance_backup_files',51 'backup_archive_path',52 'fetched_backup_archive_path',53 'backup_files_from_machine',54 # Temp facts55 'cached_facts',56 'facts_for_machines_res',57 'single_instances_for_each_machine',58 'instances_from_same_machine',59 ]60 # If someone added a variable to defaults, but forgot to set it in 'set_instance_facts' step61 def test_set_instance_facts(self):62 default_names = list(self.defaults.keys())63 set_instance_facts_name = list(self.set_instance_facts[0]['set_fact']['role_facts'].keys())64 self.assertEqual(65 sorted(default_names), sorted(set_instance_facts_name + self.not_user_facts),66 'List of facts in defaults and in "set_instance_fact" step is different',67 )68 # If someone added a variable to defaults, but forgot to add it to doc69 def test_doc_facts(self):70 default_names = list(self.defaults.keys())71 self.assertEqual(72 sorted(default_names), sorted(self.doc_facts + self.not_user_facts),73 'List of facts in defaults and in documentation is different',74 )75 # If someone added a variable to defaults, but forgot to add it to validate config76 def test_validate_config_facts(self):77 default_names = list(self.defaults.keys())78 self.assertEqual(79 sorted(default_names), sorted(self.validate_config_facts + self.not_user_facts),80 'List of facts in defaults and in validate config step is different',81 )82 # If someone added a variable to validate config step, but forgot to add it to cached facts list83 def test_validate_config_cached_facts(self):84 cached_facts_names = self.cached_facts_names['validate_config']85 self.assertEqual(86 sorted(self.validate_config_facts), sorted(cached_facts_names),87 'List of facts in cached facts and in validate config step is different',88 )89 # If someone added a variable to validate config step, but forgot to add it to test of validate config90 def test_validate_config_test_facts(self):91 self.assertEqual(92 sorted(self.validate_config_facts), sorted(self.test_validate_config_facts),93 'List of facts in validate config step and in test of this step is different',...
test_purgeuploads.py
Source: test_purgeuploads.py
1import unittest2from models import PurgeUpload3class TestPurgeUploadsDefault(unittest.TestCase):4 def test_validate_config(self):5 purge_config = dict([6 ('enabled',True),7 ('age','168h'),8 ('interval','24h'),9 ('dryrun', False),10 ])11 cfg = PurgeUpload(purge_config)12 cfg.validate()13 def test_validate_config(self):14 purge_config = dict([15 ('enabled','false'),16 ('age','168h'),17 ('interval','24h'),18 ('dryrun', 'false'),19 ])20 cfg = PurgeUpload(purge_config)21 cfg.validate()22 def test_validate_config_2hour(self):23 purge_config = dict([24 ('enabled',True),25 ('age','2h'),26 ('interval','2h'),27 ('dryrun', False),...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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!!