Code Duplication    Length = 26-28 lines in 2 locations

tests/unit/test_main.py 2 locations

@@ 153-180 (lines=28) @@
150
        assert response.status_code == 200
151
        assert len(response.json()) == 0
152
153
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
154
    async def test_bytes_count_per_flow(self, mock_from_flow):
155
        """Test bytes_count_per_flow rest call."""
156
        flow_info = {
157
            "byte_count": 10,
158
            "duration_sec": 20,
159
            "duration_nsec": 30,
160
            "packet_count": 40,
161
            "cookie": 12310228866111668291,
162
            "match": {"in_port": 1},
163
            "priority": 32768
164
            }
165
        flow_id = '6055f13593fad45e0b4699f49d56b105'
166
        flow_stats_dict_mock = {flow_id: flow_info}
167
        dpid = "00:00:00:00:00:00:00:01"
168
        flow_by_sw = {dpid: flow_stats_dict_mock}
169
        mock_from_flow.return_value = flow_by_sw
170
171
        self._patch_switch_flow(flow_id)
172
173
        endpoint = f"{self.base_endpoint}/bytes_count/per_flow/{dpid}"
174
        response = await self.api_client.get(endpoint)
175
        assert response.status_code == 200
176
177
        json_response = response.json()
178
        assert json_response[0]["flow_id"] == flow_id
179
        assert json_response[0]["bytes_counter"] == 10
180
        assert json_response[0]["bits_per_second"] == 4.0
181
182
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
183
    async def test_flows_counters_packet(self, mock_from_flow):
@@ 118-143 (lines=26) @@
115
        assert response.status_code == 200
116
        assert len(response.json()) == 0
117
118
    @patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id")
119
    async def test_packet_count_per_flow(self, mock_from_flow):
120
        """Test packet_count_per_flow rest call."""
121
        flow_info = {
122
            "byte_count": 10,
123
            "duration_sec": 20,
124
            "duration_nsec": 30,
125
            "packet_count": 40,
126
            "cookie": 12310228866111668291,
127
            "match": {"in_port": 1},
128
            "priority": 32768
129
            }
130
        flow_id = '6055f13593fad45e0b4699f49d56b105'
131
        flow_stats_dict_mock = {flow_id: flow_info}
132
        dpid = "00:00:00:00:00:00:00:01"
133
        flow_by_sw = {dpid: flow_stats_dict_mock}
134
        mock_from_flow.return_value = flow_by_sw
135
136
        self._patch_switch_flow(flow_id)
137
        endpoint = f"{self.base_endpoint}/packet_count/per_flow/{dpid}"
138
        response = await self.api_client.get(endpoint)
139
140
        json_response = response.json()
141
        assert json_response[0]["flow_id"] == flow_id
142
        assert json_response[0]["packet_counter"] == 40
143
        assert json_response[0]["packet_per_second"] == 2.0
144
145
    async def test_bytes_count_per_flow__empty(self):
146
        """Test bytes_count rest call with a flow that does not exist ."""