mirror of
https://github.com/netbox-community/devicetype-library.git
synced 2024-11-22 08:23:33 +01:00
Per #175, check for duplicate devices. I am comparing slugs, and found a duplicate Generic device already.
This commit is contained in:
parent
e12f531f3a
commit
e5c4414f8a
@ -1,6 +1,6 @@
|
||||
manufacturer: Generic
|
||||
model: shelf-1he
|
||||
slug: shelf-1he
|
||||
model: shelf-2he
|
||||
slug: shelf-2he
|
||||
u_height: 2
|
||||
full_depth: false
|
||||
|
||||
|
41
tests/test_dupes.py
Normal file
41
tests/test_dupes.py
Normal file
@ -0,0 +1,41 @@
|
||||
import glob
|
||||
import json
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
KNOWN_MODELS = {}
|
||||
|
||||
def _get_definition_files():
|
||||
"""
|
||||
Return a list of all definition files.
|
||||
"""
|
||||
return [f for f in glob.glob("device-types/*/*", recursive=True)]
|
||||
|
||||
def test_environment():
|
||||
"""
|
||||
Run basic sanity checks on the environment to ensure tests are running correctly.
|
||||
"""
|
||||
# Validate that definition files exist
|
||||
assert _get_definition_files(), "No definition files found!"
|
||||
|
||||
@pytest.mark.parametrize("file_path", _get_definition_files())
|
||||
def test_dupes(file_path):
|
||||
# Check file extension
|
||||
assert file_path.split('.')[-1] in ('yaml', 'yml'), f"Invalid file extension: {file_path}"
|
||||
|
||||
# Read file
|
||||
with open(file_path) as definition_file:
|
||||
content = definition_file.read()
|
||||
|
||||
# Check for trailing newline
|
||||
assert content[-1] == '\n', "Missing trailing newline"
|
||||
|
||||
# Load YAML data
|
||||
definition = yaml.load(content, Loader=yaml.SafeLoader)
|
||||
|
||||
slug = definition.get('slug')
|
||||
|
||||
if KNOWN_MODELS.get(slug, None) is not None:
|
||||
pytest.fail(f"{file_path} is a duplicate device_type for {slug}")
|
||||
|
||||
KNOWN_MODELS[slug] = definition.get('model')
|
Loading…
Reference in New Issue
Block a user