Code Duplication    Length = 24-25 lines in 2 locations

tests/unit/tracing/test_trace_pkt.py 2 locations

@@ 70-94 (lines=25) @@
67
68
        Switches(MagicMock())._switches = controller.switches
69
70
    @patch("napps.amlight.sdntrace.shared.extd_nw_types.randrange")
71
    def test_generate_trace_pkt_tcp(self, mock_rand):
72
        """Test trace manager new trace creation."""
73
        mock_rand.return_value = 0
74
        eth = {"dl_vlan": 100}
75
        dpid = {"dpid": "00:00:00:00:00:00:00:01", "in_port": 1}
76
        ip = {"nw_proto": 6}
77
        tp = {"tp_src": 1, "tp_dst": 2}
78
        switch = {"switch": dpid, "eth": eth, "ip": ip, "tp": tp}
79
        entries = {"trace": switch}
80
81
        trace_entries = TraceEntries()
82
        trace_entries.load_entries(entries)
83
        r_id = 999
84
        step = 9
85
86
        # Coloring REST response
87
        color = {"color_value": "ee:ee:ee:ee:ee:01"}
88
89
        # new_trace does not check duplicated request.
90
        in_port, pkt = trace_pkt.generate_trace_pkt(trace_entries, color, r_id, step)
91
92
        assert entries["trace"]["switch"]["in_port"] == in_port
93
        assert (
94
            pkt == b"\xca\xfe\xca\xfe\xca\xfe\xee\xee\xee\xee\xee\x01"
95
            b"\x81\x00\x00d\x08\x00E\x00\x00\x8f\x00\x00\x00\x00\xff\x06"
96
            b"\xb7d\x01\x01\x01\x01\x01\x01\x01\x02\x00\x01\x00\x02\x00"
97
            b"\x00\x00\x00\x00\x00\x00\x00P\x02\x00S\x86G\x00\x00\x80\x04"
@@ 103-126 (lines=24) @@
100
            b"\x94(\x8c\x0b_request_id\x94M\xe7\x03\x8c\x05_step\x94K\tub."
101
        )
102
103
    @patch("napps.amlight.sdntrace.shared.extd_nw_types.randrange")
104
    def test_generate_trace_pkt_udp(self, mock_rand):
105
        """Test trace manager new trace creation."""
106
        mock_rand.return_value = 0
107
        eth = {"dl_vlan": 100}
108
        dpid = {"dpid": "00:00:00:00:00:00:00:01", "in_port": 1}
109
        ip = {"nw_proto": 17}
110
        tp = {"tp_src": 1, "tp_dst": 2}
111
        switch = {"switch": dpid, "eth": eth, "ip": ip, "tp": tp}
112
        entries = {"trace": switch}
113
114
        trace_entries = TraceEntries()
115
        trace_entries.load_entries(entries)
116
        r_id = 999
117
        step = 9
118
119
        # Coloring REST response
120
        color = {"color_value": "ee:ee:ee:ee:ee:01"}
121
122
        # new_trace does not check duplicated request.
123
        in_port, pkt = trace_pkt.generate_trace_pkt(trace_entries, color, r_id, step)
124
        assert entries["trace"]["switch"]["in_port"] == in_port
125
        assert (
126
            pkt == b"\xca\xfe\xca\xfe\xca\xfe\xee\xee\xee\xee\xee\x01\x81"
127
            b"\x00\x00d\x08\x00E\x00\x00\x83\x00\x00\x00\x00\xff\x11\xb7e"
128
            b"\x01\x01\x01\x01\x01\x01\x01\x02\x00\x01\x00\x02\x00o\xd6."
129
            b"\x80\x04\x95\\\x00\x00\x00\x00\x00\x00\x00\x8c(napps.amlight"