| 
									
										
										
										
											2021-12-07 11:25:14 -05:00
										 |  |  | from unittest import mock | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-16 15:28:31 -05:00
										 |  |  | from aprsd import packets | 
					
						
							|  |  |  | from aprsd.packets import tracker | 
					
						
							| 
									
										
										
										
											2021-12-07 11:25:14 -05:00
										 |  |  | from aprsd.plugins import query as query_plugin | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .. import fake, test_plugin | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestQueryPlugin(test_plugin.TestPlugin): | 
					
						
							| 
									
										
										
										
											2022-12-16 15:28:31 -05:00
										 |  |  |     @mock.patch("aprsd.packets.tracker.PacketTrack.flush") | 
					
						
							| 
									
										
										
										
											2021-12-07 11:25:14 -05:00
										 |  |  |     def test_query_flush(self, mock_flush): | 
					
						
							|  |  |  |         packet = fake.fake_packet(message="!delete") | 
					
						
							|  |  |  |         query = query_plugin.QueryPlugin(self.config) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expected = "Deleted ALL pending msgs." | 
					
						
							|  |  |  |         actual = query.filter(packet) | 
					
						
							|  |  |  |         mock_flush.assert_called_once() | 
					
						
							|  |  |  |         self.assertEqual(expected, actual) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-16 15:28:31 -05:00
										 |  |  |     @mock.patch("aprsd.packets.tracker.PacketTrack.restart_delayed") | 
					
						
							| 
									
										
										
										
											2021-12-07 11:25:14 -05:00
										 |  |  |     def test_query_restart_delayed(self, mock_restart): | 
					
						
							| 
									
										
										
										
											2022-12-16 15:28:31 -05:00
										 |  |  |         track = tracker.PacketTrack() | 
					
						
							| 
									
										
										
										
											2021-12-07 11:25:14 -05:00
										 |  |  |         track.data = {} | 
					
						
							|  |  |  |         packet = fake.fake_packet(message="!4") | 
					
						
							|  |  |  |         query = query_plugin.QueryPlugin(self.config) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expected = "No pending msgs to resend" | 
					
						
							|  |  |  |         actual = query.filter(packet) | 
					
						
							|  |  |  |         mock_restart.assert_not_called() | 
					
						
							|  |  |  |         self.assertEqual(expected, actual) | 
					
						
							|  |  |  |         mock_restart.reset_mock() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # add a message | 
					
						
							| 
									
										
										
										
											2022-12-16 15:28:31 -05:00
										 |  |  |         pkt = packets.MessagePacket( | 
					
						
							|  |  |  |             from_call=self.fromcall, | 
					
						
							|  |  |  |             to_call="testing", | 
					
						
							|  |  |  |             msgNo=self.ack, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         track.add(pkt) | 
					
						
							| 
									
										
										
										
											2021-12-07 11:25:14 -05:00
										 |  |  |         actual = query.filter(packet) | 
					
						
							|  |  |  |         mock_restart.assert_called_once() |