# Path: dyndnsc/common/six.py
# def ipaddress(addr):
# def ipnetwork(addr):
# 
# Path: dyndnsc/common/six.py
# def ipaddress(addr):
#     """Return an ipaddress.ip_address object from the given string IP."""
#     return _ipaddress.ip_address(addr)
# 
# Path: dyndnsc/detector/base.py
# LOG = logging.getLogger(__name__)
# class IPDetector(Subject, DynamicCliMixin):
#     def __init__(self, *args, **kwargs):
#     def can_detect_offline(self):
#     def af(self):
#     def get_old_value(self):
#     def set_old_value(self, value):
#     def get_current_value(self, default=None):
#     def set_current_value(self, value):
#     def has_changed(self):
#     def configuration_key_prefix():
# 
# Path: dyndnsc/detector/dnswanip.py
# class IPDetector_DnsWanIp(IPDetector):
#     """Detect the internet visible IP address using publicly available DNS infrastructure."""
# 
#     configuration_key = "dnswanip"
# 
#     def __init__(self, family=None, *args, **kwargs):
#         """
#         Initialize.
# 
#         :param family: IP address family (default: '' (ANY), also possible: 'INET', 'INET6')
#         """
#         if family is None:
#             family = AF_INET
#         super(IPDetector_DnsWanIp, self).__init__(*args, family=family, **kwargs)
# 
#     def can_detect_offline(self):
#         """Return false, as this detector generates dns traffic.
# 
#         :return: False
#         """
#         return False
# 
#     def detect(self):
#         """
#         Detect the WAN IP of the current process through DNS.
# 
#         Depending on the 'family' option, either ipv4 or ipv6 resolution is
#         carried out.
# 
#         :return: ip address
#         """
#         theip = find_ip(family=self.opts_family)
#         self.set_current_value(theip)
#         return theip


import unittest
import pytest
    import socket
from dyndnsc.common.six import string_types
from dyndnsc.common.six import ipaddress
from dyndnsc.detector.base import AF_INET, AF_INET6
from dyndnsc.detector.dnswanip import IPDetector_DnsWanIp
# -*- coding: utf-8 -*-

"""Tests for detectors."""





HAVE_IPV6 = True
try:
    socket.socket(socket.AF_INET6, socket.SOCK_DGRAM).connect(("ipv6.google.com", 0))
except (OSError, socket.gaierror):
    HAVE_IPV6 = False


class TestIndividualDetectors(unittest.TestCase):
    """Test cases for detectors."""

    def test_dnswanip_detector_class(self):
        """Run basic tests for IPDetector_DnsWanIp."""
        self.assertEqual("dnswanip", IPDetector_DnsWanIp.configuration_key)
        detector = IPDetector_DnsWanIp()
        self.assertFalse(detector.can_detect_offline())
        self.assertEqual(None, detector.get_current_value())
        # default family should be ipv4:
        detector = IPDetector_DnsWanIp(family=None)
        self.assertEqual(AF_INET, detector.af())
        detector = IPDetector_DnsWanIp(family=AF_INET)

# Path: dyndnsc/common/six.py
# def ipaddress(addr):
# def ipnetwork(addr):
# 
# Path: dyndnsc/common/six.py
# def ipaddress(addr):
#     """Return an ipaddress.ip_address object from the given string IP."""
#     return _ipaddress.ip_address(addr)
# 
# Path: dyndnsc/detector/base.py
# LOG = logging.getLogger(__name__)
# class IPDetector(Subject, DynamicCliMixin):
#     def __init__(self, *args, **kwargs):
#     def can_detect_offline(self):
#     def af(self):
#     def get_old_value(self):
#     def set_old_value(self, value):
#     def get_current_value(self, default=None):
#     def set_current_value(self, value):
#     def has_changed(self):
#     def configuration_key_prefix():
# 
# Path: dyndnsc/detector/dnswanip.py
# class IPDetector_DnsWanIp(IPDetector):
#     """Detect the internet visible IP address using publicly available DNS infrastructure."""
# 
#     configuration_key = "dnswanip"
# 
#     def __init__(self, family=None, *args, **kwargs):
#         """
#         Initialize.
# 
#         :param family: IP address family (default: '' (ANY), also possible: 'INET', 'INET6')
#         """
#         if family is None:
#             family = AF_INET
#         super(IPDetector_DnsWanIp, self).__init__(*args, family=family, **kwargs)
# 
#     def can_detect_offline(self):
#         """Return false, as this detector generates dns traffic.
# 
#         :return: False
#         """
#         return False
# 
#     def detect(self):
#         """
#         Detect the WAN IP of the current process through DNS.
# 
#         Depending on the 'family' option, either ipv4 or ipv6 resolution is
#         carried out.
# 
#         :return: ip address
#         """
#         theip = find_ip(family=self.opts_family)
#         self.set_current_value(theip)
#         return theip


# Path: dyndnsc/tests/detector/test_dnswanip.py
import unittest
import pytest
    import socket
from dyndnsc.common.six import string_types
from dyndnsc.common.six import ipaddress
from dyndnsc.detector.base import AF_INET, AF_INET6
from dyndnsc.detector.dnswanip import IPDetector_DnsWanIp

# -*- coding: utf-8 -*-

"""Tests for detectors."""





HAVE_IPV6 = True
try:
    socket.socket(socket.AF_INET6, socket.SOCK_DGRAM).connect(("ipv6.google.com", 0))
except (OSError, socket.gaierror):
    HAVE_IPV6 = False


class TestIndividualDetectors(unittest.TestCase):
    """Test cases for detectors."""

    def test_dnswanip_detector_class(self):
        """Run basic tests for IPDetector_DnsWanIp."""
        self.assertEqual("dnswanip", IPDetector_DnsWanIp.configuration_key)
        detector = IPDetector_DnsWanIp()
        self.assertFalse(detector.can_detect_offline())
        self.assertEqual(None, detector.get_current_value())
        # default family should be ipv4:
        detector = IPDetector_DnsWanIp(family=None)
        self.assertEqual(AF_INET, detector.af())
        detector = IPDetector_DnsWanIp(family=AF_INET)

        self.assertEqual(AF_INET, detector.af())