File: test_variables.py

package info (click to toggle)
python-ezsnmp 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,256 kB
  • sloc: cpp: 3,746; python: 1,987; javascript: 1,110; makefile: 17; sh: 12
file content (110 lines) | stat: -rw-r--r-- 3,177 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from __future__ import unicode_literals

from ezsnmp.variables import SNMPVariable, SNMPVariableList


def test_snmp_variable_regular():
    var = SNMPVariable("sysDescr", "0")
    assert var.oid == "sysDescr"
    assert var.oid_index == "0"


def test_snmp_variable_value():
    var = SNMPVariable("sysDescr", "0", "my thingo")
    assert var.value == "my thingo"
    assert var.oid == "sysDescr"
    assert var.oid_index == "0"


def test_snmp_variable_repr():
    var = SNMPVariable("sysDescr", "0", "my thingo", "OCTETSTR")
    assert var.__repr__() == (
        "<SNMPVariable value='my thingo' "
        "(oid='sysDescr', oid_index='0', snmp_type='OCTETSTR')>"
    )


def test_snmp_variable_repr_binary():
    var = SNMPVariable(
        "sysDescr", "0", (chr(20)) + "my thingo" + (chr(155)), "OCTETSTR"
    )
    assert var.__repr__() == (
        "<SNMPVariable value='my thingo (contains binary)' "
        "(oid='sysDescr', oid_index='0', snmp_type='OCTETSTR')>"
    )


def test_snmp_variable_repr_binary_only():
    var = SNMPVariable("sysDescr", "0", (chr(20)) + (chr(155)), "OCTETSTR")
    assert var.__repr__() == (
        "<SNMPVariable value='(contains binary)' "
        "(oid='sysDescr', oid_index='0', snmp_type='OCTETSTR')>"
    )


def test_snmp_variable_repr_none():
    var = SNMPVariable()
    assert var.__repr__() == (
        "<SNMPVariable value=None (oid=None, oid_index=None, snmp_type=None)>"
    )


def test_snmp_variable_eq_():
    var1 = SNMPVariable(
        "sysDescr", "0", (chr(20)) + "my thingo 1" + (chr(155)), "OCTETSTR"
    )

    var2 = SNMPVariable(
        "sysDescr", "0", (chr(20)) + "my thingo 1" + (chr(155)), "OCTETSTR"
    )

    assert var1 == var2


def test_snmp_variable_not_eq_():
    var1 = SNMPVariable(
        "sysDescr", "0", (chr(20)) + "my thingo 1" + (chr(155)), "OCTETSTR"
    )

    var2 = SNMPVariable(
        "sysDescr", "0", (chr(20)) + "my thingo 2" + (chr(155)), "OCTETSTR"
    )

    assert var1 != var2


def test_snmp_variable_extract_oid_index():
    var = SNMPVariable("sysDescr.0")
    assert var.oid == "sysDescr"
    assert var.oid_index == "0"
    assert var.value is None
    assert var.snmp_type is None


def test_snmp_variable_long():
    var = SNMPVariable(".iso.org.dod.internet.mgmt.mib-2.system.sysDescr", "0")
    assert var.oid == ".iso.org.dod.internet.mgmt.mib-2.system.sysDescr"
    assert var.oid_index == "0"
    assert var.value is None
    assert var.snmp_type is None


def test_snmp_variable_doesnt_extract_oid_index():
    var = SNMPVariable(".iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0")
    assert var.oid == ".iso.org.dod.internet.mgmt.mib-2.system.sysDescr"
    assert var.oid_index == "0"
    assert var.value is None
    assert var.snmp_type is None


def test_snmp_variable_numeric():
    var = SNMPVariable(".1.3.6.1.2.1.1.1.0")
    assert var.oid == ".1.3.6.1.2.1.1.1.0"
    assert var.oid_index == ""
    assert var.value is None
    assert var.snmp_type is None


def test_snmp_variable_list():
    varlist = SNMPVariableList(["sysContact.0", "sysLocation.0", "sysDescr.0"])
    assert varlist.varbinds == ["sysContact.0", "sysLocation.0", "sysDescr.0"]