Esempio n. 1
0
def test_template_delete(quicksight_application_stub, mininmal_data_sets_stub):
    obj = Template(quicksight_application=quicksight_application_stub,
                   data_sets=mininmal_data_sets_stub.data_sets_stub,
                   props=None)

    sub_type = 'main'
    TemplateStubber.stub_delete_template_call(sub_type)

    dump_state(obj)
    obj.delete()
    dump_state(obj, 'After template delete obj')
Esempio n. 2
0
def test_template_create_from_template(quicksight_application_stub,
                                       template_arn):
    obj = Template(quicksight_application=quicksight_application_stub,
                   data_sets=None,
                   props=None)

    sub_type = 'main'
    TemplateStubber.stub_create_template_call(sub_type)

    dump_state(obj)
    obj.create_from_template(template_arn)
    dump_state(obj, 'After template create_from_template obj')
Esempio n. 3
0
def test_template_update_template_permissions(quicksight_application_stub,
                                              mininmal_data_sets_stub):
    obj = Template(quicksight_application=quicksight_application_stub,
                   data_sets=mininmal_data_sets_stub.data_sets_stub,
                   props=None)

    sub_type = 'main'
    TemplateStubber.stub_update_template_permissions_call(sub_type)
    permission_type = TemplatePermissionType.PUBLIC
    logger.info(f"Testing with permission type {permission_type}")
    dump_state(obj)
    obj.update_template_permissions(permission=TemplatePermissionType.PUBLIC,
                                    principal=None)
    dump_state(obj, 'After template delete obj')
Esempio n. 4
0
def test_template_create_from_analysis(quicksight_application_stub,
                                       mininmal_data_sets_stub):
    obj = Template(quicksight_application=quicksight_application_stub,
                   data_sets=mininmal_data_sets_stub.data_sets_stub,
                   props=None)

    sub_type = 'main'
    TemplateStubber.stub_create_template_call(sub_type)

    class AnalysisStub:
        def __init__(self):
            self.arn = "MOCK_ANALYSIS"

    analysis = AnalysisStub()

    dump_state(obj)
    obj.create_from_analysis(analysis)
    dump_state(obj, 'After template create_from_analysis obj')
Esempio n. 5
0
def test_template_init_minimal_data_sets(quicksight_application_stub,
                                         mininmal_data_sets_stub):
    stub = mininmal_data_sets_stub

    obj = Template(quicksight_application=quicksight_application_stub,
                   data_sets=stub.data_sets_stub,
                   props=None)

    dump_state(obj)
Esempio n. 6
0
    def __init__(self, resource_properties):
        # TODO: use the config data / file to figure out the supported_data_set_types
        supported_data_set_types = ['sentiment', 'image-text', 'text', 'topic']

        self.resource_properties = resource_properties
        self.global_state = get_global_state()

        # use config data file if provided
        config_file = resource_properties.get('ConfigDataFile', None)
        if config_file:
            data = read_config(config_file)
            self.global_state.update(data)

        # TODO:RENAME: 'StackName' key name as this could be used out of stack. ApplicationName?
        # TODO: create/use a uuid if no attack provided
        self.prefix = resource_properties.get('StackName', 'Sample_Sol')

        # TODO:RENAME: quicksight_template_arn -> quicksight_source_template_arn
        self.quicksight_template_arn = resource_properties.get(
            'QuickSightSourceTemplateArn',
            'Uninitialized QuickSightSourceTemplateArn')
        logger.debug(
            f'Using QuickSightSourceTemplateArn: {self.quicksight_template_arn }'
        )

        self.quicksight_principal_arn = resource_properties.get(
            'QuickSightPrincipalArn', 'Uninitialized QuickSightPrincipalArn')
        logger.debug(
            f'Using QuickSightPrincipalArn: {self.quicksight_principal_arn }')

        self.data_source = DataSource(quicksight_application=self,
                                      props=self.global_state)
        self.data_source.athena_workgroup = resource_properties.get(
            'WorkGroupName', 'primary')

        self.data_set_sub_types = supported_data_set_types
        self.data_sets = dict()
        for data_set_sub_type in self.data_set_sub_types:
            data_set = DataSet(quicksight_application=self,
                               data_source=self.data_source,
                               data_set_sub_type=data_set_sub_type,
                               data_set_name=f"_{data_set_sub_type}_dataset",
                               props=self.global_state)
            self.data_sets[data_set_sub_type] = data_set

        self.analysis = Analysis(
            quicksight_application=self,
            data_sets=self.data_sets,
            quicksight_template_arn=self.quicksight_template_arn,
            data_source=self.data_source,
            props=self.global_state)

        self.dashboard = Dashboard(
            quicksight_application=self,
            data_sets=self.data_sets,
            quicksight_template_arn=self.quicksight_template_arn,
            props=self.global_state)

        self.template = Template(quicksight_application=self,
                                 data_sets=self.data_sets,
                                 props=self.global_state)

        global_state_json = json.dumps(self.global_state,
                                       indent=2,
                                       sort_keys=True)
        logger.debug(
            f'QuicksightApi: after init, global data json: {global_state_json}'
        )
Esempio n. 7
0
def test_template_init(quicksight_application_stub):
    obj = Template(quicksight_application=quicksight_application_stub,
                   data_sets=None,
                   props=None)

    dump_state(obj)
    def __init__(self, resource_properties):
        # TODO: use the config data / file to figure out the supported_data_set_types
        supported_data_set_types = [
            "image-text", "topic", "image-moderation-label", "geo",
            "topic-mapping", "feed"
        ]

        self.resource_properties = resource_properties
        self.global_state = get_global_state()

        # use config data file if provided
        config_file = resource_properties.get("ConfigDataFile", None)
        if config_file:
            data = read_config(config_file)
            self.global_state.update(data)

        self.prefix = resource_properties.get("StackName", "Sample_Sol")

        # TODO:RENAME: quicksight_template_arn -> quicksight_source_template_arn
        self.quicksight_template_arn = resource_properties.get(
            "QuickSightSourceTemplateArn",
            "Uninitialized QuickSightSourceTemplateArn")
        logger.debug(
            f"Using QuickSightSourceTemplateArn: {self.quicksight_template_arn }"
        )

        self.quicksight_principal_arn = resource_properties.get(
            "QuickSightPrincipalArn", "Uninitialized QuickSightPrincipalArn")
        logger.debug(
            f"Using QuickSightPrincipalArn: {self.quicksight_principal_arn }")

        self.data_source = DataSource(quicksight_application=self,
                                      props=self.global_state)
        self.data_source.athena_workgroup = resource_properties.get(
            "WorkGroupName", "primary")

        self.data_set_sub_types = supported_data_set_types
        self.data_sets = dict()
        for data_set_sub_type in self.data_set_sub_types:
            data_set = DataSet(
                quicksight_application=self,
                data_source=self.data_source,
                data_set_sub_type=data_set_sub_type,
                props=self.global_state,
            )
            self.data_sets[data_set_sub_type] = data_set

        self.analysis = Analysis(
            quicksight_application=self,
            data_sets=self.data_sets,
            quicksight_template_arn=self.quicksight_template_arn,
            data_source=self.data_source,
            props=self.global_state,
        )

        self.dashboard = Dashboard(
            quicksight_application=self,
            data_source=self.data_source,
            data_sets=self.data_sets,
            quicksight_template_arn=self.quicksight_template_arn,
            props=self.global_state,
        )

        self.template = Template(quicksight_application=self,
                                 data_sets=self.data_sets,
                                 props=self.global_state)

        global_state_json = json.dumps(self.global_state,
                                       indent=2,
                                       sort_keys=True)
        logger.debug(
            f"QuicksightApi: after init, global data json: {global_state_json}"
        )