-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2832 from lunkwill42/test/fix-broken-statemon-tests
Fix broken statemon tests
- Loading branch information
Showing
3 changed files
with
56 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def modulo_pid(): | ||
"""Returns this process' PID number, modulo 2^16. Because that's what pping uses | ||
to produce ping packet IDs | ||
""" | ||
yield os.getpid() % 2**16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,50 @@ | ||
from unittest import TestCase | ||
import os | ||
from nav.statemon.megaping import Host | ||
from nav.statemon.icmppacket import PacketV4, PacketV6 | ||
|
||
|
||
class HostTestcase(TestCase): | ||
def test_make_v4_packet(self): | ||
""" | ||
Test to make a v4 packet | ||
""" | ||
class TestHost: | ||
"""Tests for the Host class""" | ||
|
||
def test_make_v4_packet(self, modulo_pid): | ||
"""Test to make a v4 packet""" | ||
host = Host('127.0.0.1') | ||
pid = os.getpid() | ||
self.assertFalse(host.is_v6()) | ||
assert not host.is_v6() | ||
|
||
self.assertTrue(host.packet) | ||
self.assertTrue(isinstance(host.packet, PacketV4)) | ||
assert host.packet | ||
assert isinstance(host.packet, PacketV4) | ||
|
||
packet, cookie = host.make_packet(64) | ||
|
||
self.assertTrue(packet) | ||
self.assertTrue(cookie) | ||
self.assertEqual(len(packet), 64) | ||
self.assertEqual(len(cookie), 16) | ||
assert packet | ||
assert cookie | ||
assert len(packet) == 64 | ||
assert len(cookie) == 16 | ||
|
||
self.assertEqual(host.packet.sequence, 0) | ||
self.assertEqual(host.packet.id, pid) | ||
assert host.packet.sequence == 0 | ||
assert host.packet.id, modulo_pid | ||
|
||
def test_make_v6_packet(self): | ||
""" | ||
Test to make a v6 packet | ||
""" | ||
def test_make_v6_packet(self, modulo_pid): | ||
"""Test to make a v6 packet""" | ||
host = Host('2001:701::FFFF') | ||
pid = os.getpid() | ||
self.assertTrue(host.is_v6()) | ||
assert host.is_v6() | ||
|
||
self.assertTrue(host.packet) | ||
self.assertTrue(isinstance(host.packet, PacketV6)) | ||
assert host.packet | ||
assert isinstance(host.packet, PacketV6) | ||
|
||
packet, cookie = host.make_packet(64) | ||
|
||
self.assertTrue(packet) | ||
self.assertTrue(cookie) | ||
self.assertEqual(len(packet), 64) | ||
self.assertEqual(len(cookie), 16) | ||
assert packet | ||
assert cookie | ||
assert len(packet) == 64 | ||
assert len(cookie) == 16 | ||
|
||
self.assertEqual(host.packet.sequence, 0) | ||
self.assertEqual(host.packet.id, pid) | ||
assert host.packet.sequence == 0 | ||
assert host.packet.id == modulo_pid | ||
|
||
def test_ip_validation(self): | ||
""" | ||
Test the IP valdidation helper methods for both v6 & v4 | ||
""" | ||
self.assertTrue(Host('129.241.105.210').is_valid_ipv4()) | ||
self.assertFalse(Host('129.241.105.256').is_valid_ipv4()) | ||
|
||
self.assertTrue(Host('2001:701::FFFF').is_valid_ipv6()) | ||
self.assertFalse(Host('127.0.0.1').is_valid_ipv6()) | ||
"""Test the IP valdidation helper methods for both v6 & v4""" | ||
assert Host('129.241.105.210').is_valid_ipv4() | ||
assert not Host('129.241.105.256').is_valid_ipv4() | ||
|
||
assert Host('2001:701::FFFF').is_valid_ipv6() | ||
assert not Host('127.0.0.1').is_valid_ipv6() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters