本文整理汇总了Python中ooni.director.Director.startSniffing方法的典型用法代码示例。如果您正苦于以下问题:Python Director.startSniffing方法的具体用法?Python Director.startSniffing怎么用?Python Director.startSniffing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ooni.director.Director
的用法示例。
在下文中一共展示了Director.startSniffing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestStartSniffing
# 需要导入模块: from ooni.director import Director [as 别名]
# 或者: from ooni.director.Director import startSniffing [as 别名]
class TestStartSniffing(unittest.TestCase):
def setUp(self):
self.director = Director()
self.testDetails = {
'test_name': 'foo',
'test_start_time': '2016-01-01 12:34:56'
}
# Each NetTestCase has a name attribute
class FooTestCase(object):
name = 'foo'
self.FooTestCase = FooTestCase
def test_start_sniffing_once(self):
with patch('ooni.settings.config.scapyFactory') as mock_scapy_factory:
with patch('ooni.utils.txscapy.ScapySniffer') as mock_scapy_sniffer:
self.director.startSniffing(self.testDetails)
sniffer = mock_scapy_sniffer.return_value
mock_scapy_factory.registerProtocol.assert_called_once_with(sniffer)
def test_start_sniffing_twice(self):
with patch('ooni.settings.config.scapyFactory') as mock_scapy_factory:
with patch('ooni.utils.txscapy.ScapySniffer') as mock_scapy_sniffer:
sniffer = mock_scapy_sniffer.return_value
sniffer.pcapwriter.filename = 'foo1_filename'
self.director.startSniffing(self.testDetails)
self.assertEqual(len(self.director.sniffers), 1)
self.testDetails = {
'test_name': 'bar',
'test_start_time': '2016-01-01 12:34:56'
}
with patch('ooni.utils.txscapy.ScapySniffer') as mock_scapy_sniffer:
sniffer = mock_scapy_sniffer.return_value
sniffer.pcapwriter.filename = 'foo2_filename'
self.director.startSniffing(self.testDetails)
self.assertEqual(len(self.director.sniffers), 2)
def test_measurement_succeeded(self):
with patch('ooni.settings.config.scapyFactory') as mock_scapy_factory:
with patch('ooni.utils.txscapy.ScapySniffer') as mock_scapy_sniffer:
self.director.startSniffing(self.testDetails)
self.assertEqual(len(self.director.sniffers), 1)
measurement = MagicMock()
measurement.testInstance = self.FooTestCase()
self.director.measurementSucceeded('awesome', measurement)
self.assertEqual(len(self.director.sniffers), 0)
sniffer = mock_scapy_sniffer.return_value
mock_scapy_factory.unRegisterProtocol.assert_called_once_with(sniffer)