def test_data_set_create_exist(data_set_type, quicksight_application_stub): # stub data_source = DataSource( quicksight_application=quicksight_application_stub, props=None) data_source.arn = "STUBBED_DATA_SOURCE_ARN" quicksight_application_stub.data_source = data_source sub_type = data_set_type obj = DataSet( data_source=data_source, data_set_sub_type=sub_type, props=None, quicksight_application=quicksight_application_stub, ) DataSetStubber.stub_create_data_set_error_call(sub_type) DataSetStubber.stub_describe_data_set_call(sub_type) # Function under test response = obj.create() # This response is the response to describe_data_source as the code is remaps the response assert response # The describe_data_set reponse does not provide a status at the DataSet level, such # as "Status": "CREATION_SUCCESSFUL" # Therefore, we verify CreatedTime not being None assert response["CreatedTime"] assert obj.arn
def test_data_set_create_invalid_parameter(data_set_type, quicksight_application_stub): # stub data_source = DataSource( quicksight_application=quicksight_application_stub, props=None) data_source.arn = "STUBBED_DATA_SOURCE_ARN" quicksight_application_stub.data_source = data_source sub_type = data_set_type obj = DataSet( data_source=data_source, data_set_sub_type=sub_type, props=None, quicksight_application=quicksight_application_stub, ) [ DataSetStubber.stub_create_data_source_error_invalid_parameter_call( sub_type) for _ in range(3) ] response = None with pytest.raises(tenacity.RetryError): # Function under test response = obj.create() assert not response
def test_data_source_delete(quicksight_application_stub): obj = DataSource(quicksight_application=quicksight_application_stub, props=None) dump_state(obj) sub_type = 'main' dump_state(obj, 'Before delete') DataSourceStubber.stub_delete_data_source_call(sub_type) obj.delete() dump_state(obj, 'After delete')
def test_data_source_create(quicksight_application_stub): obj = DataSource(quicksight_application=quicksight_application_stub, props=None) assert obj.athena_workgroup assert obj.athena_workgroup == "primary" dump_state(obj) sub_type = 'main' dump_state(obj, 'Before create') DataSourceStubber.stub_create_data_source_call(sub_type) response = obj.create() assert response assert response["Status"] in [202] assert response["CreationStatus"] in ["CREATION_IN_PROGRESS"] assert obj.arn dump_state(obj, 'After create')
def test_data_source_create_exist(quicksight_application_stub): obj = DataSource(quicksight_application=quicksight_application_stub, props=None) assert obj.athena_workgroup assert obj.athena_workgroup == "primary" sub_type = "main" DataSourceStubber.stub_create_data_source_error_call(sub_type) DataSourceStubber.stub_describe_data_source_call(sub_type) # Function under test response = obj.create() # This response is the response to describe_data_source as the code is remaps the response assert response assert response["Status"] in ["CREATION_SUCCESSFUL"] assert obj.arn
def test_data_set_create_all_data_set_types(data_set_type, quicksight_application_stub): data_source = DataSource(quicksight_application=quicksight_application_stub, props=None) # stub data_source.arn = "STUBBED_DATA_SOURCE_ARN" quicksight_application_stub.data_source = data_source data_set = DataSet( data_source=data_source, data_set_sub_type=data_set_type, data_set_name=f"_{data_set_type}_DataSet", props=None, quicksight_application=quicksight_application_stub ) dump_state(data_set, 'Before create') DataSetStubber.stub_create_data_set(data_set_type) data_set.create() dump_state(data_set, 'After create')
def test_data_set_init_all_data_set_types(data_set_type, quicksight_application_stub): data_source = DataSource(quicksight_application=quicksight_application_stub, props=None) data_set = DataSet( data_source=data_source, data_set_sub_type=data_set_type, data_set_name=f"_{data_set_type}_DataSet", props=None, quicksight_application=quicksight_application_stub ) dump_state(data_set, 'After initialization')
def test_data_set_get_data(quicksight_application_stub, data_set_type): data_source = DataSource(quicksight_application=quicksight_application_stub, props=None) data_set = DataSet( data_source=data_source, data_set_sub_type=data_set_type, data_set_name=f"_{data_set_type}_DataSet", props=None, quicksight_application=quicksight_application_stub ) assert repr(data_set) == "{'id': 'DHT_Unit_Test_dataset', 'name': 'DHT_Unit_Test_dataset', 'arn': None}"
def test_data_set_invalid_sub_type(quicksight_application_stub): data_source = DataSource( quicksight_application=quicksight_application_stub, props=None) invalid_sub_type = "TEST_INVALID_SUB_TYPE" data_set = DataSet( data_source=data_source, data_set_sub_type=invalid_sub_type, props=None, quicksight_application=quicksight_application_stub, ) with pytest.raises(Exception): data_set.create()
def test_data_set_delete_all_data_set_types(data_set_type, quicksight_application_stub): data_source = DataSource(quicksight_application=quicksight_application_stub, props=None) # stub data_source.arn = "STUBBED_DATA_SOURCE_ARN" quicksight_application_stub.data_source = data_source logger.info(f'Initializing dataset object for type: {data_set_type}') data_set = DataSet( data_source=data_source, data_set_sub_type=data_set_type, data_set_name=f"_{data_set_type}_DataSet", props=None, quicksight_application=quicksight_application_stub ) logger.debug(f'After initializing dataset object for type: {data_set_type}') dump_state(data_set, 'Before delete') DataSetStubber.stub_delete_data_set(data_set_type) data_set.delete() dump_state(data_set, 'After delete')
def mininmal_data_source_stub(request): class GenericTestStub: pass # stubs quicksight_application_stub = GenericTestStub() quicksight_application_stub.prefix = "SOLUTION_UT" quicksight_application_stub.quicksight_principal_arn = "arn:MOCK_ARN" # We use the real object here but with a stubbed quicksight_application data_source_stub = DataSource( quicksight_application=quicksight_application_stub, props=None) quicksight_application_stub.data_source = data_source_stub return data_source_stub
def test_data_set_get_data(quicksight_application_stub, data_set_type): data_source = DataSource( quicksight_application=quicksight_application_stub, props=None) data_set = DataSet( data_source=data_source, data_set_sub_type=data_set_type, props=None, quicksight_application=quicksight_application_stub, ) expected_name = f"DHT_Unit_Test-dataset-{data_set_type}" assert data_set.get_data() == { "id": f"{expected_name}", "name": expected_name, "arn": f"arn:aws:quicksight:us-east-1:MOCK_ACCOUNT:dataset/{expected_name}", }
def test_data_source_init(quicksight_application_stub): obj = DataSource(quicksight_application=quicksight_application_stub, 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 = ['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}' )
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}" )