def test_check_valid_ip_address_fail_noexpecttype(value):
    """."""
    result_bool = check_valid_ip_address(value, convert=False)
    assert result_bool is False

    with pytest.raises(ValueError):
        check_valid_ip_address(value)
def test_check_valid_ip_address_ok_noexpecttype(value):
    """."""
    result_bool = check_valid_ip_address(value, convert=False)
    assert result_bool is True

    result_converted = check_valid_ip_address(value)
    assert isinstance(result_converted, (IPv4Address, IPv6Address))
Ejemplo n.º 3
0
    def __init__(self, address, closest_prefix, prefixes, reputation,
                 **kwargs):
        """."""
        self.address = check_valid_ip_address(
            address, expected_type=ipaddress.IPv4Address)

        self.closest_prefix = closest_prefix
        self.prefixes = prefixes
        self.reputation = reputation

        super().__init__(**kwargs)
def test_check_valid_ip_address_fail_expecttype(value, wrong_type):
    """."""
    with pytest.raises(ValueError):
        check_valid_ip_address(value, expected_type=wrong_type)
def test_check_valid_ip_address_ok_expecttype(values, expected_type):
    """."""
    for value in values:
        assert isinstance(
            check_valid_ip_address(value, expected_type=expected_type),
            expected_type)