Skip to content

Commit

Permalink
Re-factored tests to correctly cover all versions of SNMP
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimian committed May 30, 2015
1 parent 483bcc5 commit 427a9df
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 386 deletions.
44 changes: 33 additions & 11 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,46 @@
snmp_logger.disabled = True


@pytest.fixture
def sess_v1_args():
return {
'version': 1,
'hostname': 'localhost',
'community': 'public'
}


@pytest.fixture
def sess_v2_args():
return {
'version': 2,
'hostname': 'localhost',
'community': 'public'
}


@pytest.fixture
def sess_v3_args():
return {
'version': 3,
'hostname': 'localhost',
'security_level': 'authPriv',
'security_username': 'initial',
'privacy_password': 'priv_pass',
'auth_password': 'auth_pass'
}


@pytest.fixture
def sess_v1():
return easysnmp.Session(
version=1, hostname='localhost', community='public'
)
return easysnmp.Session(**sess_v1_args())


@pytest.fixture
def sess_v2():
return easysnmp.Session(
version=2, hostname='localhost', community='public'
)
return easysnmp.Session(**sess_v2_args())


@pytest.fixture
def sess_v3():
return easysnmp.Session(
version=3, hostname='localhost',
security_level='authPriv', security_username='initial',
privacy_password='priv_pass', auth_password='auth_pass'
)
return easysnmp.Session(**sess_v3_args())
13 changes: 8 additions & 5 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ def test_invalid_snmp_version():
easysnmp.Session(version=4)


def test_invalid_hostname():
@pytest.mark.parametrize('version', [1, 2, 3])
def test_invalid_hostname(version):
with pytest.raises(easysnmp.EasySNMPConnectionError):
session = easysnmp.Session(hostname='invalid', version=2)
session = easysnmp.Session(hostname='invalid', version=version)
session.get('sysContact.0')


def test_invalid_port():
@pytest.mark.parametrize('version', [1, 2, 3])
def test_invalid_port(version):
with pytest.raises(easysnmp.EasySNMPTimeoutError):
session = easysnmp.Session(remote_port=1234, version=2, timeout=0.2,
retries=1)
session = easysnmp.Session(
remote_port=1234, version=version, timeout=0.2, retries=1
)
session.get('sysContact.0')
Loading

0 comments on commit 427a9df

Please sign in to comment.