#!/usr/bin/env python
"""
Copyright 2015 Brocade Communications Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""


import unittest
import xml.etree.ElementTree as ET
import pynos.versions.base.interface as interface
import pynos.utilities


class TestInterface(unittest.TestCase):
    """
    Interface unit tests. Compare expected XML to generated XML.
    """
    def setUp(self):
        self.interface = interface.Interface(pynos.utilities.return_xml)
        self.namespace = 'urn:brocade.com:mgmt:brocade-interface'
        self.phys_int_type = 'gigabitethernet'
        self.phys_name = '1/0/0'

    def test_description(self):
        expected = '<config>'\
                   '<interface xmlns="{}"><gigabitethernet>'\
                   '<name>1/0/0</name>'\
                   '<description>Hodor</description>'\
                   '</gigabitethernet></interface>'\
                   '</config>'.format(self.namespace)
        description = 'Hodor'
        result = self.interface.description(int_type=self.phys_int_type,
                                            name=self.phys_name,
                                            desc=description)
        result = ET.tostring(result)
        self.assertEquals(expected, result)

    def test_description_exception(self):
        with self.assertRaises(KeyError):
            self.interface.description(int_type=self.phys_int_type,
                                       desc='Hodor')

@@ -1075,16 +1075,44 @@
  '1/0/0'
+%0A        self.vlan_id = '40'
 %0A%0A    de
@@ -1950,8 +1950,769 @@
 Hodor')%0A
+%0A    def test_private_vlan_type(self):%0A        expected = '%3Cconfig%3E'%5C%0A                   '%3Cinterface-vlan xmlns=%22%7B%7D%22%3E%3Cinterface%3E'%5C%0A                   '%3Cvlan%3E%3Cname%3E40%3C/name%3E%3Cprivate-vlan%3E'%5C%0A                   '%3Cpvlan-type-leaf%3Eisolated%3C/pvlan-type-leaf%3E'%5C%0A                   '%3C/private-vlan%3E%3C/vlan%3E%3C/interface%3E%3C/interface-vlan%3E'%5C%0A                   '%3C/config%3E'.format(self.namespace)%0A        result = self.interface.private_vlan_type(name=self.vlan_id,%0A                                                  pvlan_type='isolated')%0A        result = ET.tostring(result)%0A        self.assertEquals(expected, result)%0A%0A    def test_private_vlan_type_exception(self):%0A        with self.assertRaises(KeyError):%0A            self.interface.private_vlan_type(name=self.vlan_id)%0A

add new test for pvlan type