Skip to content

Commit

Permalink
Added initial unit test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Sep 14, 2023
1 parent 15cd7b7 commit fc9c5fb
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 152 deletions.
4 changes: 4 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ esbonio = "*"
sphinx-sitemap = "*"
sphinx-rtd-theme = "*"
sphinx-copybutton = "*"
pysnmpcrypto = "*"

[dev-packages]
pytest = "*"
pytest-asyncio = "*"
typing_extensions = "*"

[requires]
python_version = "3.7"
441 changes: 289 additions & 152 deletions Pipfile.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions tests/hlapi/asyncio/agent/ntforg/test_default-v1-trap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
from pysnmp.hlapi.asyncio import *

@pytest.mark.asyncio
async def test_send_notification():
snmpEngine = SnmpEngine()
errorIndication, errorStatus, errorIndex, varBinds = await sendNotification(
snmpEngine,
CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.pysnmp.com', 162)),
ContextData(),
"trap",
NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")).addVarBinds(
("1.3.6.1.6.3.1.1.4.3.0", "1.3.6.1.4.1.20408.4.1.1.2"),
("1.3.6.1.2.1.1.1.0", OctetString("my system")),
),
)
assert errorIndication is None
assert errorStatus == 0
assert errorIndex == 0
assert varBinds == []
25 changes: 25 additions & 0 deletions tests/hlapi/asyncio/agent/ntforg/test_v3-inform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
from pysnmp.hlapi import *
from pysnmp.hlapi.asyncio.ntforg import sendNotification
from pysnmp.hlapi.asyncio.transport import UdpTransportTarget
from pysnmp.proto.errind import RequestTimedOut

@pytest.mark.asyncio
async def test_send_v3_inform_notification():
errorIndication, errorStatus, errorIndex, varBinds = await sendNotification(
SnmpEngine(),
UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
UdpTransportTarget(('demo.pysnmp.com', 162)),
ContextData(),
'inform',
NotificationType(
ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
).addVarBinds(
('1.3.6.1.2.1.1.1.0', OctetString('my system'))
)
)

assert isinstance(errorIndication, RequestTimedOut)
assert errorStatus == 0
assert errorIndex == 0
assert varBinds == []
36 changes: 36 additions & 0 deletions tests/hlapi/asyncio/manager/cmdgen/test_v1-next.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
SNMPv1
++++++
Send SNMP GET request using the following options:
* with SNMPv1, community 'public'
* over IPv4/UDP
* to an Agent at demo.pysnmp.com:161
* for an instance of SNMPv2-MIB::sysDescr.0 MIB object
* Based on asyncio I/O framework
Functionally similar to:
| $ snmpgetnext -v1 -c public demo.pysnmp.com SNMPv2-MIB::sysDescr.0
"""#
import asyncio
import pytest
from pysnmp.hlapi.asyncio.slim import Slim
from pysnmp.smi.rfc1902 import ObjectIdentity, ObjectType

@pytest.mark.asyncio
async def test_v1_next():
slim = Slim(1)
errorIndication, errorStatus, errorIndex, varBinds = await slim.next(
'public',
'demo.pysnmp.com',
161,
ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)),
)

assert errorIndication is None
assert errorStatus == 0
assert errorIndex == 0
assert len(varBinds) > 0
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tox]
envlist = py37, py38, py39, py310, py311, py312

[testenv]
deps =
pytest
pytest-asyncio
commands =
pytest tests

0 comments on commit fc9c5fb

Please sign in to comment.