# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# inv.DiscoveryID tests
# ----------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------

# Python modules
from __future__ import absolute_import

# Third-party modules
from builtins import str
import pytest

# NOC modules
from noc.core.mac import MAC
from noc.inv.models.discoveryid import DiscoveryID


@pytest.mark.parametrize(
    "ranges,additional,result",
    [
        (
            [{"first_chassis_mac": "01:02:03:25:6C:80", "last_chassis_mac": "01:02:03:25:6C:80"}],
            [
                "01:02:03:25:6C:8D",
                "01:02:03:25:6C:8E",
                "01:02:03:25:6C:8F",
                "01:02:03:25:6C:8A",
                "01:02:03:25:6C:8B",
                "01:02:03:25:6C:8C",
                "01:02:03:25:6C:99",
                "01:02:03:25:6C:98",
                "01:02:03:25:6C:93",
                "01:02:03:25:6C:92",
                "01:02:03:25:6C:91",
                "01:02:03:25:6C:90",
                "01:02:03:25:6C:97",
                "01:02:03:25:6C:96",
                "01:02:03:25:6C:95",
                "01:02:03:25:6C:94",
                "01:02:03:25:6C:9C",
                "01:02:03:25:6C:9A",
                "01:02:03:25:6C:C0",
                "01:02:03:25:6C:88",
                "01:02:03:25:6C:89",
                "01:02:03:25:6C:84",
                "01:02:03:25:6C:85",
                "01:02:03:25:6C:86",
                "01:02:03:25:6C:87",
                "01:02:03:25:6C:81",
                "01:02:03:25:6C:82",
                "01:02:03:25:6C:83",
            ],
            [
                "01:02:03:25:6C:80",
                "01:02:03:25:6C:81",
                "01:02:03:25:6C:82",
                "01:02:03:25:6C:83",
                "01:02:03:25:6C:84",
                "01:02:03:25:6C:85",
                "01:02:03:25:6C:86",
                "01:02:03:25:6C:87",
                "01:02:03:25:6C:88",
                "01:02:03:25:6C:89",
                "01:02:03:25:6C:8A",
                "01:02:03:25:6C:8B",
                "01:02:03:25:6C:8C",
                "01:02:03:25:6C:8D",
                "01:02:03:25:6C:8E",
                "01:02:03:25:6C:8F",
                "01:02:03:25:6C:90",
                "01:02:03:25:6C:91",
                "01:02:03:25:6C:92",
                "01:02:03:25:6C:93",
                "01:02:03:25:6C:94",
                "01:02:03:25:6C:95",
                "01:02:03:25:6C:96",
                "01:02:03:25:6C:97",
                "01:02:03:25:6C:98",
                "01:02:03:25:6C:99",
                "01:02:03:25:6C:9A",
                "01:02:03:25:6C:9C",
                "01:02:03:25:6C:C0",
            ],
        )
    ],
)
def test_macs_as_ints(ranges, additional, result):
    r = [str(MAC(x)) for x in DiscoveryID._macs_as_ints(ranges, additional)]
    assert r == result


@pytest.mark.parametrize(
    "macs,result",
    [
        (
            [
                "01:02:03:25:6C:80",
                "01:02:03:25:6C:81",
                "01:02:03:25:6C:82",
                "01:02:03:25:6C:83",
                "01:02:03:25:6C:84",
                "01:02:03:25:6C:85",
                "01:02:03:25:6C:86",
                "01:02:03:25:6C:87",
                "01:02:03:25:6C:88",
                "01:02:03:25:6C:89",
                "01:02:03:25:6C:8A",
                "01:02:03:25:6C:8B",
                "01:02:03:25:6C:8C",
                "01:02:03:25:6C:8D",
                "01:02:03:25:6C:8E",
                "01:02:03:25:6C:8F",
                "01:02:03:25:6C:90",
                "01:02:03:25:6C:91",
                "01:02:03:25:6C:92",
                "01:02:03:25:6C:93",
                "01:02:03:25:6C:94",
                "01:02:03:25:6C:95",
                "01:02:03:25:6C:96",
                "01:02:03:25:6C:97",
                "01:02:03:25:6C:98",
                "01:02:03:25:6C:99",
                "01:02:03:25:6C:9A",
                "01:02:03:25:6C:9C",
                "01:02:03:25:6C:C0",
            ],
            [
                ("01:02:03:25:6C:80", "01:02:03:25:6C:9A"),
                ("01:02:03:25:6C:9C", "01:02:03:25:6C:9C"),
                ("01:02:03:25:6C:C0", "01:02:03:25:6C:C0"),
            ],
        )
    ],
)
def test_macs_to_ranges(macs, result):
    imacs = [int(MAC(m)) for m in macs]
    r = [(mr.first_mac, mr.last_mac) for mr in DiscoveryID._macs_to_ranges(imacs)]
    assert r == result
