-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for util.py and update format_pfx logic
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
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
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
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,54 @@ | ||
import pytest | ||
|
||
from kartograf.util import format_pfx, get_root_network | ||
|
||
def test_valid_ipv4_network(): | ||
pfx = "192.144.11.0/21" | ||
assert format_pfx(pfx) == pfx | ||
|
||
|
||
def test_valid_ipv4_addr(): | ||
pfx = "192.144.11.0" | ||
assert format_pfx(pfx) == pfx | ||
|
||
|
||
def test_valid_ipv6_network(): | ||
pfx = "2001:db8::/64" | ||
assert format_pfx(pfx) == pfx | ||
|
||
|
||
def test_valid_ipv6_addr(): | ||
pfx = "2001:db8::1" | ||
assert format_pfx(pfx) == pfx | ||
|
||
|
||
def test_ipv4_prefix_with_leading_zeros(): | ||
pfx = "010.10.00.00/16" | ||
expected_output = "10.10.00.00/16" | ||
assert format_pfx(pfx) == expected_output | ||
|
||
|
||
def test_ipv6_prefix_with_leading_zeros(): | ||
pfx = "001:db8::0/24" | ||
expected_output = "1:db8::0/24" | ||
assert format_pfx(pfx) == expected_output | ||
|
||
|
||
def test_invalid_ip_network(): | ||
pfx = "192.1/asdf" | ||
assert format_pfx(pfx) == pfx | ||
|
||
|
||
def test_invalid_input(): | ||
pfx = "no.slash" | ||
assert format_pfx(pfx) == pfx | ||
|
||
|
||
def test_get_root_network(): | ||
ipv4 = "192.144.11.0/24" | ||
assert get_root_network(ipv4) == 192 | ||
ipv6 = "2001:db8::/64" | ||
assert get_root_network(ipv6) == int("2001", 16) | ||
invalid = "not.a.network" | ||
with pytest.raises(ValueError): | ||
get_root_network(invalid) |