1
+ # Copyright (C) 2025 Intel Corporation
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ from pytest import fixture , raises
5
+ from textwrap import dedent
6
+
7
+ from mfd_switchmanagement import DellOS9
8
+ from mfd_switchmanagement .exceptions import SwitchException
9
+
10
+
11
+ class TestDellOS9 :
12
+ """Class for DellOS9 tests."""
13
+
14
+ @fixture
15
+ def switch (self , mocker ) -> DellOS9 :
16
+ switch = DellOS9 .__new__ (DellOS9 )
17
+ switch .__init__ = mocker .create_autospec (switch .__init__ , return_value = None )
18
+ return switch
19
+
20
+ def test_get_port_by_mac (self , switch , mocker ):
21
+ """Test get_port_by_mac method."""
22
+ switch ._connection = mocker .Mock ()
23
+ out = """
24
+ Codes: *N - VLT Peer Synced MAC
25
+ *I - Internal MAC Address used for Inter Process Communication
26
+ VlanId Mac Address Type Interface State
27
+ 1 68:05:ca:c1:c8:ea Dynamic Te 0/32 Active
28
+ """
29
+ switch ._connection .send_command = mocker .Mock (return_value = dedent (out ))
30
+ assert switch .get_port_by_mac ("68:05:ca:c1:c8:ea" ) == "Te 0/32"
31
+
32
+ def test_get_port_by_mac_not_found (self , switch , mocker ):
33
+ """Test get_port_by_mac method when MAC address is not found."""
34
+ switch ._connection = mocker .Mock ()
35
+ out = """
36
+ Codes: *N - VLT Peer Synced MAC
37
+ *I - Internal MAC Address used for Inter Process Communication
38
+ VlanId Mac Address Type Interface State
39
+ """
40
+ switch ._connection .send_command = mocker .Mock (return_value = dedent (out ))
41
+ with raises (SwitchException , match = "Could not find port for MAC address 68:05:ca:c1:c8:ea" ):
42
+ switch .get_port_by_mac ("68:05:ca:c1:c8:ea" )
43
+
44
+ def test_get_port_by_mac_invalid_mac (self , switch ):
45
+ """Test get_port_by_mac method with invalid MAC address."""
46
+ with raises (ValueError , match = "Incorrect MAC address: ZZ:ZZ:ZZ:ZZ:ZZ:ZZ" ):
47
+ switch .get_port_by_mac ("ZZ:ZZ:ZZ:ZZ:ZZ:ZZ" )
0 commit comments