added unit tests to help check new utils functions and usages within nodes for adding addresses and macs
This commit is contained in:
parent
834ceea55d
commit
7028d3e78f
3 changed files with 93 additions and 1 deletions
|
@ -1,4 +1,8 @@
|
|||
import netaddr
|
||||
import pytest
|
||||
|
||||
from core import utils
|
||||
from core.errors import CoreError
|
||||
|
||||
|
||||
class TestUtils:
|
||||
|
@ -20,3 +24,43 @@ class TestUtils:
|
|||
assert len(one_arg) == 1
|
||||
assert len(two_args) == 2
|
||||
assert len(unicode_args) == 3
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"data,expected",
|
||||
[
|
||||
("127", "127.0.0.0/32"),
|
||||
("10.0.0.1/24", "10.0.0.1/24"),
|
||||
("2001::", "2001::/128"),
|
||||
("2001::/64", "2001::/64"),
|
||||
],
|
||||
)
|
||||
def test_validate_ip(self, data, expected):
|
||||
value = utils.validate_ip(data)
|
||||
assert value == expected
|
||||
|
||||
@pytest.mark.parametrize("data", ["256", "1270.0.0.1", "127.0.0.0.1"])
|
||||
def test_validate_ip_exception(self, data):
|
||||
with pytest.raises(CoreError):
|
||||
utils.validate_ip("")
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"data,expected",
|
||||
[
|
||||
("AA-AA-AA-FF-FF-FF", "aa:aa:aa:ff:ff:ff"),
|
||||
("AA:AA:AA:FF:FF:FF", "aa:aa:aa:ff:ff:ff"),
|
||||
],
|
||||
)
|
||||
def test_validate_mac(self, data, expected):
|
||||
value = utils.validate_mac(data)
|
||||
assert value == expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"data", ["AAA:AA:AA:FF:FF:FF", "AA:AA:AA:FF:FF", "AA/AA/AA/FF/FF/FF"]
|
||||
)
|
||||
def test_validate_mac_exception(self, data):
|
||||
with pytest.raises(CoreError):
|
||||
utils.validate_mac(data)
|
||||
|
||||
def test_random_mac(self):
|
||||
value = utils.random_mac()
|
||||
assert netaddr.EUI(value) is not None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue