<commit_before>import mock
import unittest
from cloudify.mocks import MockCloudifyContext, MockNodeInstanceContext
from network_plugin import floatingip, network, security_group
from server_plugin.server import VCLOUD_VAPP_NAME
from network_plugin import isExternalIpAssigned
from cloudify import exceptions as cfy_exc
from tests.integration import TestCase, IntegrationTestConfig

# for skipping test add this before test function:
# @unittest.skip("demonstrating skipping")


@unittest.skip("demonstrating skipping")
class NatRulesOperationsTestCase(TestCase):
    def setUp(self):
        super(NatRulesOperationsTestCase, self).setUp()

        name = "testnode"
        self.ctx = MockCloudifyContext(
            node_id=name,
            node_name=name,
            properties={'floatingip': {}})

        network_relationship = mock.Mock()
        network_relationship.target = mock.Mock()
        network_relationship.target.instance = MockNodeInstanceContext(
            runtime_properties={VCLOUD_VAPP_NAME: IntegrationTestConfig().get()['test_vm']})
        self.ctx.instance.relationships = [network_relationship]

        ctx_patch1 = mock.patch('network_plugin.floatingip.ctx', self.ctx)
        ctx_patch2 = mock.patch('vcloud_plugin_common.ctx', self.ctx)
        ctx_patch1.start()
        ctx_patch2.start()
        self.addCleanup(ctx_patch1.stop)
        self.addCleanup(ctx_patch2.stop)

    def tearDown(self):
        super(NatRulesOperationsTestCase, self).tearDown()

    def test_nat_rules_create_delete_with_explicit_ip(self):
        self.ctx.node.properties['floatingip'].update(IntegrationTestConfig().get()['floatingip'])
        public_ip = self.ctx.node.properties['floatingip']['public_ip']
        check_external = lambda: isExternalIpAssigned(public_ip, self._get_gateway())
        self.assertFalse(check_external())
        floatingip.connect_floatingip()
        self.assertTrue(check_external())
        self.assertRaises(cfy_exc.NonRecoverableError,
                          floatingip.connect_floatingip)
        floatingip.disconnect_floatingip()
        self.assertFalse(check_external())

    def test_nat_rules_create_delete_with_autoget_ip(self):
        self.ctx.node.properties['floatingip'].update(IntegrationTestConfig().get()['floatingip'])
        del self.ctx.node.properties['floatingip']['public_ip']

        floatingip.connect_floatingip()
        public_ip = self.ctx.instance.runtime_properties['public_ip']
        check_external = lambda: isExternalIpAssigned(public_ip, self._get_gateway())
        self.assertTrue(public_ip)
        self.assertTrue(check_external())
        self.assertRaises(cfy_exc.NonRecoverableError,
                          floatingip.connect_floatingip)
        floatingip.disconnect_floatingip()
        self.assertFalse(check_external())

    def _get_gateway(self):
        return self.vcd_client.get_gateway(
            self.ctx.node.properties['floatingip']['gateway'])


@unittest.skip("demonstrating skipping")
class OrgNetworkOperationsTestCase(TestCase):
    def setUp(self):
        super(OrgNetworkOperationsTestCase, self).setUp()

        self.net_name = "test_network"
        self.ctx = MockCloudifyContext(<commit_msg>Remove skipped tests<commit_after>import mock
import unittest
from cloudify.mocks import MockCloudifyContext, MockNodeInstanceContext
from network_plugin import floatingip, network, security_group
from server_plugin.server import VCLOUD_VAPP_NAME
from network_plugin import isExternalIpAssigned
from cloudify import exceptions as cfy_exc
from tests.integration import TestCase, IntegrationTestConfig

# for skipping test add this before test function:
# @unittest.skip("demonstrating skipping")


class NatRulesOperationsTestCase(TestCase):
    def setUp(self):
        super(NatRulesOperationsTestCase, self).setUp()

        name = "testnode"
        self.ctx = MockCloudifyContext(
            node_id=name,
            node_name=name,
            properties={'floatingip': {}})

        network_relationship = mock.Mock()
        network_relationship.target = mock.Mock()
        network_relationship.target.instance = MockNodeInstanceContext(
            runtime_properties={VCLOUD_VAPP_NAME: IntegrationTestConfig().get()['test_vm']})
        self.ctx.instance.relationships = [network_relationship]

        ctx_patch1 = mock.patch('network_plugin.floatingip.ctx', self.ctx)
        ctx_patch2 = mock.patch('vcloud_plugin_common.ctx', self.ctx)
        ctx_patch1.start()
        ctx_patch2.start()
        self.addCleanup(ctx_patch1.stop)
        self.addCleanup(ctx_patch2.stop)

    def tearDown(self):
        super(NatRulesOperationsTestCase, self).tearDown()

    def test_nat_rules_create_delete_with_explicit_ip(self):
        self.ctx.node.properties['floatingip'].update(IntegrationTestConfig().get()['floatingip'])
        public_ip = self.ctx.node.properties['floatingip']['public_ip']
        check_external = lambda: isExternalIpAssigned(public_ip, self._get_gateway())
        self.assertFalse(check_external())
        floatingip.connect_floatingip()
        self.assertTrue(check_external())
        self.assertRaises(cfy_exc.NonRecoverableError,
                          floatingip.connect_floatingip)
        floatingip.disconnect_floatingip()
        self.assertFalse(check_external())

    def test_nat_rules_create_delete_with_autoget_ip(self):
        self.ctx.node.properties['floatingip'].update(IntegrationTestConfig().get()['floatingip'])
        del self.ctx.node.properties['floatingip']['public_ip']

        floatingip.connect_floatingip()
        public_ip = self.ctx.instance.runtime_properties['public_ip']
        check_external = lambda: isExternalIpAssigned(public_ip, self._get_gateway())
        self.assertTrue(public_ip)
        self.assertTrue(check_external())
        self.assertRaises(cfy_exc.NonRecoverableError,
                          floatingip.connect_floatingip)
        floatingip.disconnect_floatingip()
        self.assertFalse(check_external())

    def _get_gateway(self):
        return self.vcd_client.get_gateway(
            self.ctx.node.properties['floatingip']['gateway'])


class OrgNetworkOperationsTestCase(TestCase):
    def setUp(self):
        super(OrgNetworkOperationsTestCase, self).setUp()

        self.net_name = "test_network"
        self.ctx = MockCloudifyContext(
{'fraction_non_alphanumeric': 0.09750744630819878, 'fraction_numerical': 0.0018811725975858284, 'mean_word_length': 3.7576435495898584, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6947520', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1815, 'n_words': 265}