コード例 #1
0
ファイル: test_interface.py プロジェクト: Ktmi/kytos
 def setUp(self):
     """Create UNI object."""
     switch = MagicMock()
     switch.dpid = '00:00:00:00:00:00:00:01'
     interface = Interface('name', 1, switch)
     user_tag = TAG(1, 123)
     self.uni = UNI(interface, user_tag)
コード例 #2
0
ファイル: test_interface.py プロジェクト: Ktmi/kytos
    def test__eq__(self):
        """Test __eq__ method."""
        user_tag = TAG(2, 456)
        interface = Interface('name', 2, MagicMock())
        other = UNI(interface, user_tag)

        self.assertFalse(self.uni.__eq__(other))
コード例 #3
0
 def uni_from_dict(uni_dict, controller):
     """Create UNI instance from a dictionary."""
     intf = MaintenanceWindow.intf_from_dict(uni_dict['interface_id'],
                                             controller)
     tag = TAG.from_dict(uni_dict['tag'])
     if intf and tag:
         return UNI(intf, tag)
     return None
コード例 #4
0
ファイル: test_interface.py プロジェクト: Ktmi/kytos
class TestUNI(unittest.TestCase):
    """UNI tests."""
    def setUp(self):
        """Create UNI object."""
        switch = MagicMock()
        switch.dpid = '00:00:00:00:00:00:00:01'
        interface = Interface('name', 1, switch)
        user_tag = TAG(1, 123)
        self.uni = UNI(interface, user_tag)

    def test__eq__(self):
        """Test __eq__ method."""
        user_tag = TAG(2, 456)
        interface = Interface('name', 2, MagicMock())
        other = UNI(interface, user_tag)

        self.assertFalse(self.uni.__eq__(other))

    def test_is_valid(self):
        """Test is_valid method for a valid, invalid and none tag."""
        self.assertTrue(self.uni.is_valid())

        with self.assertRaises(ValueError):
            TAG(999999, 123)

        self.uni.user_tag = None
        self.assertTrue(self.uni.is_valid())

    def test_as_dict(self):
        """Test as_dict method."""
        expected_dict = {
            'interface_id': '00:00:00:00:00:00:00:01:1',
            'tag': {
                'tag_type': 1,
                'value': 123
            }
        }
        self.assertEqual(self.uni.as_dict(), expected_dict)

    def test_as_json(self):
        """Test as_json method."""
        expected_json = '{"interface_id": "00:00:00:00:00:00:00:01:1", ' + \
                        '"tag": {"tag_type": 1, "value": 123}}'
        self.assertEqual(self.uni.as_json(), expected_json)
コード例 #5
0
    def uni_from_dict(self, uni_dict):
        """Return a UNI object from python dict."""
        if uni_dict is None:
            return False

        interface_id = uni_dict.get("interface_id")
        interface = self.controller.get_interface_by_id(interface_id)
        if interface is None:
            raise ValueError(f'Could not instantiate interface {interface_id}')

        tag_dict = uni_dict.get("tag")
        tag = TAG.from_dict(tag_dict)
        if tag is False:
            raise ValueError(f'Could not instantiate tag from dict {tag_dict}')

        uni = UNI(interface, tag)

        return uni
コード例 #6
0
    def _uni_from_dict(self, uni_dict):
        """Return a UNI object from python dict."""
        if uni_dict is None:
            return False

        interface_id = uni_dict.get("interface_id")
        interface = self.controller.get_interface_by_id(interface_id)
        if interface is None:
            raise ValueError(f'Could not instantiate interface {interface_id}')

        try:
            tag_dict = uni_dict["tag"]
        except KeyError:
            tag = None
        else:
            tag = TAG.from_dict(tag_dict)
        uni = UNI(interface, tag)

        return uni
コード例 #7
0
ファイル: main.py プロジェクト: llgoncalves/mef_eline
    def uni_from_dict(self, uni_dict):
        """Return a UNI object from python dict."""
        if uni_dict is None:
            return False

        interface_id = uni_dict.get("interface_id")
        interface = self.controller.get_interface_by_id(interface_id)
        if interface is None:
            return False

        tag = TAG.from_dict(uni_dict.get("tag"))

        if tag is False:
            return False

        try:
            uni = UNI(interface, tag)
        except TypeError:
            return False

        return uni
コード例 #8
0
ファイル: main.py プロジェクト: rmotitsuki/mef_eline
    def _uni_from_dict(self, uni_dict):
        """Return a UNI object from python dict."""
        if uni_dict is None:
            return False

        interface_id = uni_dict.get("interface_id")
        interface = self.controller.get_interface_by_id(interface_id)
        if interface is None:
            result = (
                "Error creating UNI:"
                + f"Could not instantiate interface {interface_id}"
            )
            raise ValueError(result) from ValueError

        tag_dict = uni_dict.get("tag", None)
        if tag_dict:
            tag = TAG.from_dict(tag_dict)
        else:
            tag = None
        uni = UNI(interface, tag)

        return uni
コード例 #9
0
 def _uni_from_dict_side_effect(self, uni_dict):
     interface_id = uni_dict.get("interface_id")
     tag_dict = uni_dict.get("tag")
     interface = Interface(interface_id, "0", "switch")
     return UNI(interface, tag_dict)