From a580f9b71aeb91e59f05a672639cf0fff8e7d88c Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Mon, 11 Feb 2019 13:20:00 +0100 Subject: [PATCH] added test of test_interface_addresses_list --- test/per_router/test_juniper_data.py | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/per_router/test_juniper_data.py b/test/per_router/test_juniper_data.py index 2574209e..72147764 100644 --- a/test/per_router/test_juniper_data.py +++ b/test/per_router/test_juniper_data.py @@ -102,3 +102,53 @@ def test_bgp_list(netconf_doc): def test_snmp_community_string(mocked_netifaces, netconf_doc): assert juniper.snmp_community_string(netconf_doc) == '0pBiFbD' + + +def test_interface_addresses_list(netconf_doc): + schema = { + "$schema": "http://json-schema.org/draft-07/schema#", + + "definitions": { + "v4a": { + "type": "string", + "pattern": r'^(\d+\.){3}\d+$' + }, + "v6a": { + "type": "string", + "pattern": r'^([a-f\d]{4}:){7}[a-f\d]{4}$' + }, + "v4i": { + "type": "string", + "pattern": r'^(\d+\.){3}\d+/\d+$' + }, + "v6i": { + "type": "string", + "pattern": r'^[a-f\d:]+/\d+$' + } + }, + + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "oneOf": [ + {"$ref": "#/definitions/v4a"}, + {"$ref": "#/definitions/v6a"} + ] + }, + "interface address": { + "oneOf": [ + {"$ref": "#/definitions/v4i"}, + {"$ref": "#/definitions/v6i"} + ] + }, + "interface name": {"type": "string"}, + }, + "required": ["name", "interface address", "interface name"], + "additionalProperties": False + } + } + + addresses = list(juniper.interface_addresses(netconf_doc)) + jsonschema.validate(addresses, schema) -- GitLab