def test_get_call_args(self): data = readbytes('dummy.hex') # any dump would do packet = Sequence(Integer(Version.V2C), OctetString('public'), GetNextRequest(0, ObjectIdentifier(1, 2, 3))) with patch('puresnmp.api.raw.send') as mck, \ patch('puresnmp.api.raw.get_request_id') as mck2: mck2.return_value = 0 mck.return_value = data getnext('::1', 'public', '1.2.3') mck.assert_called_with('::1', 161, to_bytes(packet), timeout=2)
def test_getnext_increasing_oid_strict(self): ''' When running "getnext" we expect a different OID than the one we passed in. If not, this can cause endless-loops in the worst case. Faulty SNMP implementations may behave this way! ''' requested_oid = ObjectIdentifier(1, 2, 3, 4) response_object = Sequence( Integer(1), OctetString(b'public'), GetResponse(234, [VarBind(requested_oid, Integer(123))])) response_bytes = to_bytes(response_object) with patch('puresnmp.api.raw.send') as mck: mck.return_value = response_bytes with self.assertRaises(FaultySNMPImplementation): getnext('::1', 'private', '1.2.3.4')
def test_getnext(self): data = readbytes('getnext_response.hex') expected = VarBind('1.3.6.1.6.3.1.1.6.1.0', Integer(354522558)) with patch('puresnmp.api.raw.send') as mck: mck.return_value = data result = getnext('::1', 'private', '1.3.6.1.5') self.assertEqual(result, expected)