# Path: djangolg/fields.py
# class IPPrefixField(forms.CharField):
# class IPAddressField(forms.CharField):
# class RouterChoiceField(forms.ModelChoiceField):
#     def to_python(self, value=None):
#     def to_python(self, value=None):
#     def label_from_instance(self, obj):
# 
# Path: djangolg/models.py
# class Router(models.Model):
# class Location(models.Model):
# class Credential(models.Model):
# class Log(models.Model):
#     def label(self):
#     def __str__(self):
#     def __unicode__(self):
#     def __str__(self):
#     def __unicode__(self):
#     def __str__(self):
#     def __unicode__(self):
#     def __str__(self):
#     def __unicode__(self):
#     CRED_TYPE_PASSWD = 0
#     CRED_TYPE_PUBKEY = 1
#     CRED_TYPE_CHOICES = (
#         (CRED_TYPE_PASSWD, "Password"),
#         (CRED_TYPE_PUBKEY, "Public Key"),
#     )
# 
# Path: tests/models.py
# class DummyRouterWithLabel(models.Router):
#     """Dummy router subclass for testing."""
# 
#     class Meta:
#         """Meta class."""
# 
#         proxy = True
# 
#     label = "router-label-string"
# 
# class DummyRouterWithoutLabel(models.Router):
#     """Dummy router subclass for testing."""
# 
#     class Meta:
#         """Meta class."""
# 
#         proxy = True
# 
#     @property
#     def label(self):
#         """Raise error."""
#         raise NotImplementedError


from django.core.exceptions import ValidationError
from django.test import TestCase
from djangolg import fields, models
from tests.models import DummyRouterWithLabel, DummyRouterWithoutLabel
    def test_ip_prefix_field(self):
        """Test IPPrefixField deserialisation."""
        ipv4_prefix = "192.0.2.0/24"
        ipv6_prefix = "2001:db8::/32"
        not_prefix = "A.B.C.D/L"
        field = fields.IPPrefixField()
        assert field.to_python() is None
        assert "{}".format(field.to_python(ipv4_prefix)) == ipv4_prefix
        assert "{}".format(field.to_python(ipv6_prefix)) == ipv6_prefix
        try:
            field.to_python(not_prefix)
        except Exception as e:
            assert isinstance(e, ValidationError)

    def test_ip_address_field(self):
        """Test IPAddressField deserialisation."""
        ipv4_address = "192.0.2.1"
        ipv6_address = "2001:db8::1"
        not_address = "A.B.C.D"
        field = fields.IPAddressField()
        assert field.to_python() is None
        assert "{}".format(field.to_python(ipv4_address)) == ipv4_address
        assert "{}".format(field.to_python(ipv6_address)) == ipv6_address
        try:
            field.to_python(not_address)
        except Exception as e:
            assert isinstance(e, ValidationError)

    def test_router_label(self):
        """Test router label rendering."""

# Path: djangolg/fields.py
# class IPPrefixField(forms.CharField):
# class IPAddressField(forms.CharField):
# class RouterChoiceField(forms.ModelChoiceField):
#     def to_python(self, value=None):
#     def to_python(self, value=None):
#     def label_from_instance(self, obj):
# 
# Path: djangolg/models.py
# class Router(models.Model):
# class Location(models.Model):
# class Credential(models.Model):
# class Log(models.Model):
#     def label(self):
#     def __str__(self):
#     def __unicode__(self):
#     def __str__(self):
#     def __unicode__(self):
#     def __str__(self):
#     def __unicode__(self):
#     def __str__(self):
#     def __unicode__(self):
#     CRED_TYPE_PASSWD = 0
#     CRED_TYPE_PUBKEY = 1
#     CRED_TYPE_CHOICES = (
#         (CRED_TYPE_PASSWD, "Password"),
#         (CRED_TYPE_PUBKEY, "Public Key"),
#     )
# 
# Path: tests/models.py
# class DummyRouterWithLabel(models.Router):
#     """Dummy router subclass for testing."""
# 
#     class Meta:
#         """Meta class."""
# 
#         proxy = True
# 
#     label = "router-label-string"
# 
# class DummyRouterWithoutLabel(models.Router):
#     """Dummy router subclass for testing."""
# 
#     class Meta:
#         """Meta class."""
# 
#         proxy = True
# 
#     @property
#     def label(self):
#         """Raise error."""
#         raise NotImplementedError


# Path: tests/test_fields.py
from django.core.exceptions import ValidationError
from django.test import TestCase
from djangolg import fields, models
from tests.models import DummyRouterWithLabel, DummyRouterWithoutLabel

    def test_ip_prefix_field(self):
        """Test IPPrefixField deserialisation."""
        ipv4_prefix = "192.0.2.0/24"
        ipv6_prefix = "2001:db8::/32"
        not_prefix = "A.B.C.D/L"
        field = fields.IPPrefixField()
        assert field.to_python() is None
        assert "{}".format(field.to_python(ipv4_prefix)) == ipv4_prefix
        assert "{}".format(field.to_python(ipv6_prefix)) == ipv6_prefix
        try:
            field.to_python(not_prefix)
        except Exception as e:
            assert isinstance(e, ValidationError)

    def test_ip_address_field(self):
        """Test IPAddressField deserialisation."""
        ipv4_address = "192.0.2.1"
        ipv6_address = "2001:db8::1"
        not_address = "A.B.C.D"
        field = fields.IPAddressField()
        assert field.to_python() is None
        assert "{}".format(field.to_python(ipv4_address)) == ipv4_address
        assert "{}".format(field.to_python(ipv6_address)) == ipv6_address
        try:
            field.to_python(not_address)
        except Exception as e:
            assert isinstance(e, ValidationError)

    def test_router_label(self):
        """Test router label rendering."""

        field = fields.RouterChoiceField(queryset=models.Router.objects.all())