Best Python code snippet using molecule_python
test_api_internal.py
Source:test_api_internal.py
...48 device_id=devid, attributes=inventory_attributes49 )50 assert r.status_code == 20151 dev = management_client.getDevice(device_id=devid)52 self._verify_inventory(inventory_attributes, dev.attributes)53 def test_create_twice_ok(54 self, internal_client, management_client, clean_db, inventory_attributes,55 ):56 # insert first device57 devid = "".join([format(i, "02x") for i in os.urandom(128)])58 _, r = internal_client.create_device(59 device_id=devid, attributes=inventory_attributes60 )61 assert r.status_code == 20162 # add extra attribute, modify existing63 new_attr = management_client.inventoryAttribute(64 name="new attr", value="new value", scope="inventory", description="desc",65 )66 existing = inventory_attributes[0]67 existing.value = "newval"68 existing.description = "newdesc"69 new_attrs = [new_attr, existing]70 # inventory_attributes will now act as 'expected' output attrs71 inventory_attributes.append(new_attr)72 # insert 'the same' device73 _, r = internal_client.create_device(device_id=devid, attributes=new_attrs)74 assert r.status_code == 20175 # verify update76 dev = management_client.getDevice(devid)77 self._verify_inventory(inventory_attributes, dev.attributes)78 def _verify_inventory(self, expected, inventory):79 # Filter only attributes within the inventory scope80 expected_inventory = list(filter(lambda a: a.scope == "inventory", expected))81 inventory = list(filter(lambda a: a.scope == "inventory", inventory))82 assert len(inventory) == len(83 expected_inventory84 ), "expected: %s / actual: %s" % (inventory, expected_inventory)85 for e in expected_inventory:86 found = [87 f88 for f in inventory89 if (90 f.name == e.name91 and f.value == e.value92 and f.description == e.description...
test_yamlfile.py
Source:test_yamlfile.py
...25 ({'test&device1': {'address': '198.18.0.1',26 'driver': 'dummy',27 'password': 'test'}}, False),28])29def test_verify_inventory(test_devices, expected):30 from autonet.drivers.backend.yamlfile import YAMLFile31 assert YAMLFile._verify_inventory(test_devices) == expected32@pytest.mark.parametrize('test_device_id, expected', [33 ('test_device1', AutonetDeviceCredentials(34 username='test1',35 password='test1'36 )),37 ('test_device2', AutonetDeviceCredentials(38 username='test2',39 password='test2'40 )),41 ('test_device3', None)42])43def test_get_device_credentials(test_device_id, expected,44 test_yamlfile_path, monkeypatch):45 from autonet.drivers.backend.yamlfile import YAMLFile...
yamlfile.py
Source:yamlfile.py
...14 def __init__(self):15 inventory_file = config.backend_yamlfile.path16 with open(config.backend_yamlfile.path, 'r') as fh:17 self._devices = yaml.safe_load(fh)18 if not self._verify_inventory(self._devices):19 raise exc.AutonetException(f"Inventory file {inventory_file} "20 f"is not properly formatted.")21 @staticmethod22 def _verify_inventory(devices: dict) -> bool:23 """Verify that inventory loaded from YAML file is properly24 formatted. Returns `True` or `False` accordingly.25 :param devices: Devices dictionary loaded from YAML inventory file.26 """27 required_fields = ['address', 'username', 'password', 'driver']28 for device_id, device_data in devices.items():29 match = re.search(r'^[\dA-z-]*$', device_id)30 if not match:31 return False32 for field in required_fields:33 if field not in device_data:34 return False35 return True36 def get_device(self, device_id) -> Union[None, AutonetDevice]:...
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!!