Skip to content

Commit

Permalink
Adding elevation images folder and test logic (netbox-community#1225)
Browse files Browse the repository at this point in the history
* Added new test code for elevation images. Added elevation folder.

* Also adding first file with image definitions
  • Loading branch information
danner26 authored Mar 24, 2023
1 parent 128de18 commit f78c90d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions device-types/Nokia/7220-IXR-H3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ u_height: 1
is_full_depth: true # 21.65"
weight: 24.65
weight_unit: lb
front_image: true
rear_image: true
comments: '[Datasheet](https://onestore.nokia.com/asset/210990)'
console-ports:
- name: Console
Expand Down
Binary file added elevation-images/Nokia/7220-IXR-H3.front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added elevation-images/Nokia/7220-IXR-H3.rear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions schema/devicetype.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"oz"
]
},
"front_image": {
"type": "boolean"
},
"rear_image": {
"type": "boolean"
},
"subdevice_role": {
"type": "string",
"enum": [
Expand Down
43 changes: 43 additions & 0 deletions tests/definitions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
('module-types', 'moduletype.json'),
)

IMAGE_FILETYPES = (
'bmp', 'gif', 'pjp', 'jpg', 'pjpeg', 'jpeg', 'jfif', 'png', 'tif', 'tiff', 'webp'
)

COMPONENT_TYPES = (
'console-ports',
'console-server-ports',
Expand Down Expand Up @@ -49,8 +53,24 @@ def _get_definition_files():

return ret

def _get_image_files():
"""
Return a list of all image files within the specified path and manufacturer.
"""
ret = []

for f in sorted(glob.glob(f"elevation-images/*/*", recursive=True)):
# f = 'elevation-images/Nokia/nokia-7220-ixr-h3-front.png'
# f.split('/')[1] = Nokia
assert f.split('/')[2].split('.')[-1] in IMAGE_FILETYPES, f"Invalid file extension: {f}"

ret.append((f.split('/')[1], f))

return ret


definition_files = _get_definition_files()
image_files = _get_image_files()
known_slugs = set()


Expand Down Expand Up @@ -133,4 +153,27 @@ def iterlist(var):
elif isinstance(list_value, list):
iterlist(list_value)

# Check for images if front_image or rear_image is True
if (definition.get('front_image') or definition.get('rear_image')):
manufacturer_images = [image for image in image_files if image[0] == file_path.split('/')[1]]
if not manufacturer_images:
pytest.fail(f'{file_path} has Front or Rear Image set to True but no images found for manufacturer', False)

if(definition.get('front_image')):
devices = [image_path.split('/')[2] for image, image_path in manufacturer_images if image_path.split('/')[2].split('.')[1] == 'front']

if not devices:
pytest.fail(f'{file_path} has front_image set to True but no images found for device', False)

for device_image in devices:
assert slug.find(device_image.split('.')[0].casefold()) != -1, f'{file_path} has front_image set to True but no images found for device'
if(definition.get('rear_image')):
devices = [image_path.split('/')[2] for image, image_path in manufacturer_images if image_path.split('/')[2].split('.')[1] == 'rear']

if not devices:
pytest.fail(f'{file_path} has rear_image set to True but no images found for device', False)

for device_image in devices:
assert slug.find(device_image.split('.')[0].casefold()) != -1, f'{file_path} has rear_image set to True but no images found for device'

iterdict(definition)

0 comments on commit f78c90d

Please sign in to comment.