def test_integration_check_if_address_object_in_group(self):
        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = CheckIfAddressObjectInGroup()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open(
                    "../tests/check_if_address_object_in_group.json") as file:
                test_json = json.loads(file.read()).get("body")
                connection_params = test_json.get("connection")
                action_params = test_json.get("input")
        except Exception as e:
            message = """
            Could not find or read sample tests from /tests directory
            
            An exception here likely means you didn't fill out your samples correctly in the /tests directory 
            Please use 'icon-plugin generate samples', and fill out the resulting test files in the /tests directory
            """
            self.fail(message)

        test_conn.connect(connection_params)
        test_action.connection = test_conn
        results = test_action.run(action_params)

        self.assertTrue(results.get("found"))
        self.assertTrue(results.get("address_object_name"))
    def test_integration_set_address_object(self):
        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = SetAddressObject()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/set_address_object.json") as file:
                test_json = json.loads(file.read()).get("body")
                connection_params = test_json.get("connection")
                action_params = test_json.get("input")
        except Exception as e:
            message = """
            Could not find or read sample tests from /tests directory

            An exception here likely means you didn't fill out your samples correctly in the /tests directory 
            Please use 'icon-plugin generate samples', and fill out the resulting test files in the /tests directory
            """
            self.fail(message)

        test_conn.connect(connection_params)
        test_action.connection = test_conn
        results = test_action.run(action_params)

        self.assertIsNotNone(results)
        self.assertEquals(
            {
                'code': '20',
                'message': 'command succeeded',
                'status': 'success'
            }, results)
Example #3
0
    def test_integration_get_policy(self):
        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = GetPolicy()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/get_policy.json") as file:
                test_json = json.loads(file.read()).get("body")
                connection_params = test_json.get("connection")
                action_params = test_json.get("input")
        except Exception as e:
            message = """
            Could not find or read sample tests from /tests directory
            
            An exception here likely means you didn't fill out your samples correctly in the /tests directory 
            Please use 'icon-plugin generate samples', and fill out the resulting test files in the /tests directory
            """
            self.fail(message)

        test_conn.connect(connection_params)
        test_action.connection = test_conn
        results = test_action.run(action_params)

        keys = [
            'to', 'from', 'source', 'destination', 'source_user', 'category',
            'application', 'service', 'hip_profiles', 'action'
        ]

        self.assertEquals(list(results.keys()), keys)
    def test_integration_remove_address_object_from_group(self):
        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = RemoveAddressObjectFromGroup()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open(
                    "../tests/remove_address_object_from_group.json") as file:
                test_json = json.loads(file.read()).get("body")
                connection_params = test_json.get("connection")
                action_params = test_json.get("input")
        except Exception as e:
            message = """
            Could not find or read sample tests from /tests directory
            
            An exception here likely means you didn't fill out your samples correctly in the /tests directory 
            Please use 'icon-plugin generate samples', and fill out the resulting test files in the /tests directory
            """
            self.fail(message)

        test_conn.connect(connection_params)
        test_action.connection = test_conn
        results = test_action.run(action_params)

        # For example: self.assertEquals({"success": True}, results)
        self.assertEquals({"success": True}, results)
Example #5
0
    def test_integration_add_to_policy(self):
        """
        TODO: Implement assertions at the end of this test case

        This is an integration test that will connect to the services your plugin uses. It should be used
        as the basis for tests below that can run independent of a "live" connection.

        This test assumes a normal plugin structure with a /tests directory. In that /tests directory should
        be json samples that contain all the data needed to run this test. To generate samples run:

        icon-plugin generate samples

        """

        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = AddToPolicy()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/add_to_policy.json") as file:
                test_json = json.loads(file.read()).get("body")
                connection_params = test_json.get("connection")
                action_params = test_json.get("input")
        except Exception as e:
            message = """
            Could not find or read sample tests from /tests directory
            
            An exception here likely means you didn't fill out your samples correctly in the /tests directory 
            Please use 'icon-plugin generate samples', and fill out the resulting test files in the /tests directory
            """
            self.fail(message)


        test_conn.connect(connection_params)
        test_action.connection = test_conn
        results = test_action.run(action_params)

        # TODO: Remove this line
        self.fail("Unimplemented test case")

        # TODO: The following assert should be updated to look for data from your action
        # For example: self.assertEquals({"success": True}, results) 
        self.assertEquals({}, results)