Code Duplication    Length = 26-28 lines in 2 locations

tests/unit/test_main.py 2 locations

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