def test_quicksight_api_create_template_from_dashboard(
        quicksight_application_resource_properties,
        quicksight_create_template_from_dashboard_stubber):
    resource_properties = quicksight_application_resource_properties
    qs_api = QuicksightApi(resource_properties)
    response = qs_api.create_template_from_dashboard()
    assert_success_response(response)
def test_quicksight_api_delete_template(
        quicksight_application_resource_properties):
    resource_properties = quicksight_application_resource_properties
    qs_api = QuicksightApi(resource_properties)
    sub_type = 'main'
    TemplateStubber.stub_delete_template_call(sub_type)

    response = qs_api.delete_template()
    assert_success_response(response, expected_status_list=[200])
def test_quicksight_api_update_template_permissions(
        quicksight_application_resource_properties):
    resource_properties = quicksight_application_resource_properties
    qs_api = QuicksightApi(resource_properties)
    sub_type = 'main'
    TemplateStubber.stub_update_template_permissions_call(sub_type)

    response = qs_api.update_template_permissions(
        permission=TemplatePermissionType.PUBLIC, principal=None)
    assert_success_response(response, expected_status_list=[200])
Example #4
0
def custom_resource_update(event, _):
    # For update we delete all the resources and re-create new ones. Any user customization on QuickSight may be lost
    try:
        process_delete_request(event)
        process_create_request(
            event)  # once deleted re-create all the resources
    except Exception as error:
        resource_properties = get_resource_propertices(event)
        qs_api = QuicksightApi(resource_properties)
        qs_api.delete_all_resources()
        # Do logging in addition to crhelper exception handeling
        log_exception(error)
        raise (error)

    return None
def test_quicksight_api_long_app_name(
        quicksight_application_resource_properties):
    resource_properties = quicksight_application_resource_properties
    stack_name = "MOCK" + "".join(["A" for _ in range(100)])
    resource_properties.update({"StackName": stack_name})
    QuicksightApplication.clear_global_states()
    qs_api = QuicksightApi(resource_properties)
    assert len(qs_api.quicksight_application.data_source.name) == 80
def test_quicksight_api_init_with_config_file(
        quicksight_application_resource_properties):
    resource_properties = quicksight_application_resource_properties
    qs_api = QuicksightApi(resource_properties)
    logger.debug(f'unit-test: Global data {qs_api.global_state}')
    dump_state(qs_api.global_state,
               'After initialization QuicksightApi global_state')
    assert set(qs_api.global_state.keys()) == set(
        ['dashboard', 'analysis', 'dataset', 'datasource'])
Example #7
0
def custom_resource_delete(event, _):
    request_type = "Delete"
    resource_properties = get_resource_propertices(event, _)
    resource = resource_properties["Resource"]
    qs_api = QuicksightApi(resource_properties)

    try:
        if resource == "all":
            qs_api.delete_all_resources()
        elif resource == "datasource":
            qs_api.delete_data_source()
        elif resource == "dataset":
            qs_api.delete_data_sets()
        elif resource == "analysis":
            qs_api.delete_analysis()
        elif resource == "dashboard":
            qs_api.delete_dashboard()
        else:
            logger.error(
                f"Not handling request resource:{resource}, request_type:{request_type}"
            )
            raise ValueError(
                f"Received unsupported request request_type:{request_type}, resource:{resource}"
            )
    except Exception as error:
        # Do logging in addition to crhelper exception handeling
        log_exception(error)
        raise (error)

    logger.info(
        f"finished with request_type:{request_type} resource:{resource}")
    return None
Example #8
0
def custom_resource_create(event, _):
    request_type = "Create"
    resource_properties = get_resource_propertices(event, _)
    resource = resource_properties["Resource"]
    qs_api = QuicksightApi(resource_properties)

    try:
        if resource == "all":
            qs_api.create_all_resources()
        elif resource == "datasource":
            qs_api.create_data_source()
        elif resource == "dataset":
            qs_api.create_data_sets()
        elif resource == "analysis":
            qs_api.create_analysis()
        elif resource == "dashboard":
            qs_api.create_dashboard()
        else:
            logger.error(
                f"Not handling request resource:{resource}, request_type:{request_type}"
            )
            raise ValueError(
                f"Received unsupported request request_type:{request_type}, resource:{resource}"
            )
        if resource in ["all", "analysis", "dashboard"]:
            analysis_url = qs_api.quicksight_application.get_analysis().url
            dashboard_url = qs_api.quicksight_application.get_dashboard().url
            helper.Data.update({
                "analysis_url": analysis_url,
                "dashboard_url": dashboard_url
            })
    except Exception as error:
        # Do logging in addition to crhelper exception handeling
        log_exception(error)
        qs_api.delete_all_resources()
        raise (error)

    logger.info(
        f"finished with request_type:{request_type} resource:{resource}")
    return None
Example #9
0
def custom_resource_update(event, _):
    # For update we delete all the resources and re-create new ones. Any user customization on QuickSight may be lost
    request_type = "Update"
    resource_properties = get_resource_propertices(event, _)
    resource = resource_properties["Resource"]
    qs_api = QuicksightApi(resource_properties)

    try:
        # First delete all the resources
        if resource == "all":
            qs_api.delete_all_resources()
        elif resource == "datasource":
            qs_api.delete_data_source()
        elif resource == "dataset":
            qs_api.delete_data_sets()
        elif resource == "analysis":
            qs_api.delete_analysis()
        elif resource == "dashboard":
            qs_api.delete_dashboard()
        else:
            logger.error(
                f"Not handling request resource:{resource}, request_type:{request_type}"
            )
            raise ValueError(
                f"Received unsupported request request_type:{request_type}, resource:{resource}"
            )

        # once deleted re-create all the resources
        if resource == "all":
            qs_api.create_all_resources()
        elif resource == "datasource":
            qs_api.create_data_source()
        elif resource == "dataset":
            qs_api.create_data_sets()
        elif resource == "analysis":
            qs_api.create_analysis()
        elif resource == "dashboard":
            qs_api.create_dashboard()
        else:
            logger.error(
                f"Not handling request resource:{resource}, request_type:{request_type}"
            )
            raise ValueError(
                f"Received unsupported request request_type:{request_type}, resource:{resource}"
            )
        if resource in ["all", "analysis", "dashboard"]:
            analysis_url = qs_api.quicksight_application.get_analysis().url
            dashboard_url = qs_api.quicksight_application.get_dashboard().url
            helper.Data.update({
                "analysis_url": analysis_url,
                "dashboard_url": dashboard_url
            })

        logger.error(
            f"Not handling request resource:{resource}, request_type:{request_type}"
        )
        raise ValueError(
            f"Received unsupported request request_type:{request_type}, resource:{resource}"
        )

    except Exception as error:
        qs_api.delete_all_resources()
        # Do logging in addition to crhelper exception handeling
        log_exception(error)
        raise (error)

    return None
def test_quicksight_api_init(quicksight_application_resource_properties):
    resource_properties = quicksight_application_resource_properties
    qs_api = QuicksightApi(resource_properties)
    logger.debug(f'unit-test: Global data {qs_api.global_state}')
    dump_state(qs_api.global_state,
               'After initialization QuicksightApi global_state')
def custom_resource_create(event, _):
    request_type = 'Create'
    resource_properties = get_resource_propertices(event, _)
    resource = resource_properties['Resource']
    qs_api = QuicksightApi(resource_properties)

    try:
        if resource == 'all':
            qs_api.create_all_resources()
        elif resource == 'datasource':
            qs_api.create_data_source()
        elif resource == 'dataset':
            qs_api.create_data_sets()
        elif resource == 'analysis':
            qs_api.create_analysis()
        elif resource == 'dashboard':
            qs_api.create_dashboard()
        else:
            logger.error(
                f'Not handling request resource:{resource}, request_type:{request_type}'
            )
            raise ValueError(
                f'Received unsupported request request_type:{request_type}, resource:{resource}'
            )
        if resource in ['all', 'analysis', 'dashboard']:
            analysis_url = qs_api.quicksight_application.get_analysis().url
            dashboard_url = qs_api.quicksight_application.get_dashboard().url
            helper.Data.update({
                'analysis_url': analysis_url,
                'dashboard_url': dashboard_url
            })
    except Exception as error:
        # Do logging in addition to crhelper exception handeling
        log_exception(error)
        qs_api.delete_all_resources()
        raise (error)

    logger.info(
        f'finished with request_type:{request_type} resource:{resource}')
    return None