Example #1
0
    async def test_eom(self):
        '''
        A test for a walk operation which runs into the endOfMibView marker
        '''

        data_generator = readbytes_multiple('x690/multiwalk_endofmibview.hex')

        with patch('puresnmp.aio.api.raw.Transport') as mck:
            mck().send = AsyncMock()
            mck().get_request_id.return_value = 0
            mck().send.side_effect = data_generator
            result = []
            async for row in multiwalk('::1', 'public', [
                '1.3.6.1.6.3.16.1.5.2.1.6.6.95.110.111.110.101.95.1',
            ]):
                result.append(row)

        root = '1.3.6.1.6.3.16.1.5.2.1.6.6.95.110.111.110.101.95.1.'
        expected = [
            (root+'0', 1),
            (root+'1', 1),
            (root+'2', 1),
        ]

        simplified_result = [
           (str(oid), value.pythonize()) for oid, value in result
        ]

        assert simplified_result == expected
Example #2
0
    async def test_multi_walk(self):
        response_1 = readbytes('multiwalk_response_1.hex')
        response_2 = readbytes('multiwalk_response_2.hex')
        response_3 = readbytes('multiwalk_response_3.hex')

        expected = [VarBind(
            ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.1.1'), Integer(1)
        ), VarBind(
            ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.2.1'),
            OctetString(b'lo')
        ), VarBind(
            ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.1.78'), Integer(78)
        ), VarBind(
            ObjectIdentifier.from_string('1.3.6.1.2.1.2.2.1.2.78'),
            OctetString(b'eth0')
        )]

        with patch('puresnmp.aio.api.raw.Transport') as mck:
            mck().send = AsyncMock()
            mck().get_request_id.return_value = 0
            mck().send.side_effect = [response_1, response_2, response_3]
            result = []
            async for x in multiwalk('::1', 'public', [
                '1.3.6.1.2.1.2.2.1.1',
                '1.3.6.1.2.1.2.2.1.2'
            ]):
                result.append(x)
        # TODO (advanced): should order matter in the following result?
        assert len(result) == len(expected)