amyasnikov / validity

NetBox plugin to validate network devices
MIT License
136 stars 8 forks source link

Using a custom site field in tests #84

Closed ArsenyPie closed 7 months ago

ArsenyPie commented 7 months ago

Hi! It's me again) I need to compare a certain value in the current sterilized state of my devices with the custom field of the site that is attached to this device. Example: device.config['policy']['channel_restriction'] == device.site.get('channel_restriction') However, the site attribute cannot be used inside the tests. Is there any way to solve this problem?

amyasnikov commented 7 months ago

Hey @ArsenyPie

device.site must be available inside the test (post test error here if it's not). Use cf attribute to access its custom fields:

 device.config['policy']['channel_restriction'] == device.site.cf.get('channel_restriction')

BTW, you can debug your tests inside django shell:

# ./manage.py shell
>>> from validity.models import VDevice
>>> device1 = VDevice.objects.get(name='device1')
>>> print(device.site.cf['channel_restriction'])

BTW2, use discussions to ask "how does it work" questions. Main purpose of Issues is bug reporting or new functionality requests.