# Path: sen/net.py
# class NetData:
#     def __init__(self, inspect_data):
#         self.inspect_data = inspect_data
#         self.net_settings = graceful_chain_get(self.inspect_data, "NetworkSettings")
#         self._ports = None
#         self._ips = None
# 
#     @property
#     def ports(self):
#         """
#         :return: dict
#             {
#                 # container -> host
#                 "1234": "2345"
#             }
#         """
# 
#         if self._ports is None:
#             self._ports = {}
#             if self.net_settings["Ports"]:
#                 for key, value in self.net_settings["Ports"].items():
#                     cleaned_port = key.split("/")[0]
#                     self._ports[cleaned_port] = graceful_chain_get(value, 0, "HostPort")
# 
#             # in case of --net=host, there's nothing in network settings, let's get it from "Config"
#             exposed_ports_section = graceful_chain_get(self.inspect_data, "HostConfig", "PortBindings")
#             if exposed_ports_section:
#                 for key, value in exposed_ports_section.items():
#                     cleaned_port = key.split("/")[0]
#                     if cleaned_port not in self._ports:
#                         self._ports[cleaned_port] = graceful_chain_get(value, 0, "HostPort")
#                         
#             exposed_ports_section = graceful_chain_get(self.inspect_data, "Config", "ExposedPorts")
#             if exposed_ports_section:
#                 for key, value in exposed_ports_section.items():
#                     cleaned_port = key.split("/")[0]
#                     if cleaned_port not in self._ports:
#                         self._ports[cleaned_port] = None  # extremely docker specific
#         return self._ports
# 
#     @property
#     def ips(self):
#         """
#         :return: dict:
#         {
#             "default": {
#                 "ip_address4": "12.34.56.78"
#                 "ip_address6": "ff:fa:..."
#             }
#             "other": {
#                 ...
#             }
#         }
#         """
#         if self._ips is None:
#             self._ips = {}
#             default_net = extract_data_from_inspect("default", self.net_settings)
#             if default_net:
#                 self._ips["default"] = default_net
#             # this can be None
#             networks = self.inspect_data["NetworkSettings"]["Networks"]
#             if networks:
#                 for network_name, network_data in networks.items():
#                     self._ips[network_name] = extract_data_from_inspect(network_name, network_data)
# 
#         return self._ips


from sen.net import NetData
                "GlobalIPv6PrefixLen": 0,
                "Aliases": None,
                "IPv6Gateway": "",
                "Gateway": "172.17.0.1",
                "EndpointID": "4ec3605fe3c70ef85cacee52d29db70c67f87cf85fd8021bf9e35ae09d4a5be2",
                "IPPrefixLen": 16
            }
        },
        "Bridge": "",
        "LinkLocalIPv6PrefixLen": 0,
        "IPv6Gateway": "",
        "Gateway": "172.17.0.1",
        "GlobalIPv6PrefixLen": 0,
        "IPPrefixLen": 16
    },
    "Config": {
        "ExposedPorts": {
            "8787/tcp": {}
        },
    }
}


def test_empty_network():
    nd = NetData(empty_inspect)
    assert nd.ips == {}
    assert nd.ports == {}


def test_populated_network():

# Path: sen/net.py
# class NetData:
#     def __init__(self, inspect_data):
#         self.inspect_data = inspect_data
#         self.net_settings = graceful_chain_get(self.inspect_data, "NetworkSettings")
#         self._ports = None
#         self._ips = None
# 
#     @property
#     def ports(self):
#         """
#         :return: dict
#             {
#                 # container -> host
#                 "1234": "2345"
#             }
#         """
# 
#         if self._ports is None:
#             self._ports = {}
#             if self.net_settings["Ports"]:
#                 for key, value in self.net_settings["Ports"].items():
#                     cleaned_port = key.split("/")[0]
#                     self._ports[cleaned_port] = graceful_chain_get(value, 0, "HostPort")
# 
#             # in case of --net=host, there's nothing in network settings, let's get it from "Config"
#             exposed_ports_section = graceful_chain_get(self.inspect_data, "HostConfig", "PortBindings")
#             if exposed_ports_section:
#                 for key, value in exposed_ports_section.items():
#                     cleaned_port = key.split("/")[0]
#                     if cleaned_port not in self._ports:
#                         self._ports[cleaned_port] = graceful_chain_get(value, 0, "HostPort")
#                         
#             exposed_ports_section = graceful_chain_get(self.inspect_data, "Config", "ExposedPorts")
#             if exposed_ports_section:
#                 for key, value in exposed_ports_section.items():
#                     cleaned_port = key.split("/")[0]
#                     if cleaned_port not in self._ports:
#                         self._ports[cleaned_port] = None  # extremely docker specific
#         return self._ports
# 
#     @property
#     def ips(self):
#         """
#         :return: dict:
#         {
#             "default": {
#                 "ip_address4": "12.34.56.78"
#                 "ip_address6": "ff:fa:..."
#             }
#             "other": {
#                 ...
#             }
#         }
#         """
#         if self._ips is None:
#             self._ips = {}
#             default_net = extract_data_from_inspect("default", self.net_settings)
#             if default_net:
#                 self._ips["default"] = default_net
#             # this can be None
#             networks = self.inspect_data["NetworkSettings"]["Networks"]
#             if networks:
#                 for network_name, network_data in networks.items():
#                     self._ips[network_name] = extract_data_from_inspect(network_name, network_data)
# 
#         return self._ips


# Path: tests/test_net.py
from sen.net import NetData

                "GlobalIPv6PrefixLen": 0,
                "Aliases": None,
                "IPv6Gateway": "",
                "Gateway": "172.17.0.1",
                "EndpointID": "4ec3605fe3c70ef85cacee52d29db70c67f87cf85fd8021bf9e35ae09d4a5be2",
                "IPPrefixLen": 16
            }
        },
        "Bridge": "",
        "LinkLocalIPv6PrefixLen": 0,
        "IPv6Gateway": "",
        "Gateway": "172.17.0.1",
        "GlobalIPv6PrefixLen": 0,
        "IPPrefixLen": 16
    },
    "Config": {
        "ExposedPorts": {
            "8787/tcp": {}
        },
    }
}


def test_empty_network():
    nd = NetData(empty_inspect)
    assert nd.ips == {}
    assert nd.ports == {}


def test_populated_network():

    nd = NetData(populated_inspect)