# Path: libcloudforensics/providers/kubernetes/netpol.py
# class K8sNetworkPolicy(base.K8sNamespacedResource):
# class K8sNetworkPolicyWithSpec(K8sNetworkPolicy, metaclass=abc.ABCMeta):
# class K8sTargetedDenyAllNetworkPolicy(K8sNetworkPolicyWithSpec):
#   def Delete(self, cascade: bool = True) -> None:
#   def Read(self) -> client.V1NetworkPolicy:
#   def Patch(
#       self,
#       match_labels: Optional[Dict[str, str]] = None,
#       not_match_labels: Optional[Dict[str, str]] = None) -> None:
#   def _spec(self) -> client.V1NetworkPolicySpec:
#   def _metadata(self) -> client.V1ObjectMeta:
#   def _policy(self) -> client.V1NetworkPolicy:
#   def Create(self) -> None:
#   def __init__(self, api_client: client.ApiClient, namespace: str) -> None:
#   def _GenerateTag(self) -> None:
#   def labels(self) -> Dict[str, str]:
#   def _spec(self) -> client.V1NetworkPolicySpec:
# 
# Path: tests/providers/kubernetes/k8s_mocks.py
# MOCK_API_CLIENT = mock.Mock()
# def V1ObjectMeta(
#     name: Optional[str] = None,
#     namespace: Optional[str] = None,
#     labels: Optional[Labels] = None) -> client.V1ObjectMeta:
# def V1NodeList(amount: int) -> client.V1NodeList:
# def V1PodList(amount: int) -> client.V1PodList:
# def V1NetworkPolicyList(
#     amount: int, namespace: str) -> client.V1NetworkPolicyList:
# def V1NetworkPolicy(name: str, namespace: str) -> client.V1NetworkPolicy:
# def V1Service(selector_labels: Labels) -> client.V1Service:
# def V1Node(name: str) -> client.V1Node:
# def V1Pod(
#     name: Optional[str] = None,
#     namespace: Optional[str] = None,
#     node_name: Optional[str] = None,
#     labels: Optional[Labels] = None) -> client.V1Pod:
# def V1PodTemplateSpec(labels: Labels) -> client.V1PodTemplateSpec:
# def V1ReplicaSet(
#     name: Optional[str] = None,
#     namespace: Optional[str] = None,
#     template_spec_labels: Optional[Labels] = None) -> client.V1ReplicaSet:
# def V1Deployment(
#     name: Optional[str] = None,
#     namespace: Optional[str] = None,
#     template_spec_labels: Optional[Labels] = None,
#     match_labels: Optional[Labels] = None) -> client.V1Deployment:


import typing
import unittest
import mock
from kubernetes import client
from libcloudforensics.providers.kubernetes import netpol
from tests.providers.kubernetes import k8s_mocks

  @typing.no_type_check
  @mock.patch.object(netpol.K8sNetworkPolicyWithSpec, '_spec', mock_spec)
  def testNetworkPolicyCreationSpec(self, mock_create_func):
    """Test that creating a network policy provides the correct spec."""
    network_policy = netpol.K8sNetworkPolicyWithSpec(
        k8s_mocks.MOCK_API_CLIENT, 'name', 'namespace')
    network_policy.Create()
    self.assertEqual(self.mock_spec, mock_create_func.call_args.args[1].spec)

  @typing.no_type_check
  @mock.patch.object(netpol.K8sNetworkPolicyWithSpec, '_spec', mock_spec)
  def testNetworkPolicyCreationMetadata(self, mock_create_func):
    """Test that creating a network policy provides the correct metadata."""
    network_policy = netpol.K8sNetworkPolicyWithSpec(
        k8s_mocks.MOCK_API_CLIENT, 'name-jsdukbvx', 'namespace-jsdukbvx')
    network_policy.Create()
    self.assertEqual(
        client.V1ObjectMeta(
            name='name-jsdukbvx', namespace='namespace-jsdukbvx'),
        mock_create_func.call_args.args[1].metadata)


@mock.patch.object(client.NetworkingV1Api, 'create_namespaced_network_policy')
class K8sDenyAllNetworkPolicyCreationTest(unittest.TestCase):
  """Test K8sDenyAllNetworkPolicy creation API call."""

  @typing.no_type_check
  def testIsDenyAllNetworkPolicyCreationSpec(self, mock_create_func):
    """Test that a deny-all network policy creation has deny-all spec."""

# Path: libcloudforensics/providers/kubernetes/netpol.py
# class K8sNetworkPolicy(base.K8sNamespacedResource):
# class K8sNetworkPolicyWithSpec(K8sNetworkPolicy, metaclass=abc.ABCMeta):
# class K8sTargetedDenyAllNetworkPolicy(K8sNetworkPolicyWithSpec):
#   def Delete(self, cascade: bool = True) -> None:
#   def Read(self) -> client.V1NetworkPolicy:
#   def Patch(
#       self,
#       match_labels: Optional[Dict[str, str]] = None,
#       not_match_labels: Optional[Dict[str, str]] = None) -> None:
#   def _spec(self) -> client.V1NetworkPolicySpec:
#   def _metadata(self) -> client.V1ObjectMeta:
#   def _policy(self) -> client.V1NetworkPolicy:
#   def Create(self) -> None:
#   def __init__(self, api_client: client.ApiClient, namespace: str) -> None:
#   def _GenerateTag(self) -> None:
#   def labels(self) -> Dict[str, str]:
#   def _spec(self) -> client.V1NetworkPolicySpec:
# 
# Path: tests/providers/kubernetes/k8s_mocks.py
# MOCK_API_CLIENT = mock.Mock()
# def V1ObjectMeta(
#     name: Optional[str] = None,
#     namespace: Optional[str] = None,
#     labels: Optional[Labels] = None) -> client.V1ObjectMeta:
# def V1NodeList(amount: int) -> client.V1NodeList:
# def V1PodList(amount: int) -> client.V1PodList:
# def V1NetworkPolicyList(
#     amount: int, namespace: str) -> client.V1NetworkPolicyList:
# def V1NetworkPolicy(name: str, namespace: str) -> client.V1NetworkPolicy:
# def V1Service(selector_labels: Labels) -> client.V1Service:
# def V1Node(name: str) -> client.V1Node:
# def V1Pod(
#     name: Optional[str] = None,
#     namespace: Optional[str] = None,
#     node_name: Optional[str] = None,
#     labels: Optional[Labels] = None) -> client.V1Pod:
# def V1PodTemplateSpec(labels: Labels) -> client.V1PodTemplateSpec:
# def V1ReplicaSet(
#     name: Optional[str] = None,
#     namespace: Optional[str] = None,
#     template_spec_labels: Optional[Labels] = None) -> client.V1ReplicaSet:
# def V1Deployment(
#     name: Optional[str] = None,
#     namespace: Optional[str] = None,
#     template_spec_labels: Optional[Labels] = None,
#     match_labels: Optional[Labels] = None) -> client.V1Deployment:


# Path: tests/providers/kubernetes/test_netpol.py
import typing
import unittest
import mock
from kubernetes import client
from libcloudforensics.providers.kubernetes import netpol
from tests.providers.kubernetes import k8s_mocks


  @typing.no_type_check
  @mock.patch.object(netpol.K8sNetworkPolicyWithSpec, '_spec', mock_spec)
  def testNetworkPolicyCreationSpec(self, mock_create_func):
    """Test that creating a network policy provides the correct spec."""
    network_policy = netpol.K8sNetworkPolicyWithSpec(
        k8s_mocks.MOCK_API_CLIENT, 'name', 'namespace')
    network_policy.Create()
    self.assertEqual(self.mock_spec, mock_create_func.call_args.args[1].spec)

  @typing.no_type_check
  @mock.patch.object(netpol.K8sNetworkPolicyWithSpec, '_spec', mock_spec)
  def testNetworkPolicyCreationMetadata(self, mock_create_func):
    """Test that creating a network policy provides the correct metadata."""
    network_policy = netpol.K8sNetworkPolicyWithSpec(
        k8s_mocks.MOCK_API_CLIENT, 'name-jsdukbvx', 'namespace-jsdukbvx')
    network_policy.Create()
    self.assertEqual(
        client.V1ObjectMeta(
            name='name-jsdukbvx', namespace='namespace-jsdukbvx'),
        mock_create_func.call_args.args[1].metadata)


@mock.patch.object(client.NetworkingV1Api, 'create_namespaced_network_policy')
class K8sDenyAllNetworkPolicyCreationTest(unittest.TestCase):
  """Test K8sDenyAllNetworkPolicy creation API call."""

  @typing.no_type_check
  def testIsDenyAllNetworkPolicyCreationSpec(self, mock_create_func):
    """Test that a deny-all network policy creation has deny-all spec."""

    network_policy = netpol.K8sTargetedDenyAllNetworkPolicy(