def test_analysis_create_exist(
    quicksight_application_stub,
    mininmal_data_source_stub,
    mininmal_data_sets_stub,
    template_arn,
):
    obj = Analysis(
        quicksight_application=quicksight_application_stub,
        data_source=mininmal_data_source_stub,
        data_sets=mininmal_data_sets_stub.data_sets_stub,
        quicksight_template_arn=template_arn,
        props=None,
    )

    sub_type = "main"
    AnalysisStubber.stub_create_data_source_error_call(sub_type)
    AnalysisStubber.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_analysis_delete(quicksight_application_stub, mininmal_data_sets_stub, template_arn):
    obj = Analysis(
        quicksight_application=quicksight_application_stub,
        data_sets=mininmal_data_sets_stub.data_sets_stub,
        quicksight_template_arn=template_arn,
        props=None
    )

    sub_type = 'main'

    dump_state(obj, 'Before create')
    AnalysisStubber.stub_delete_analysis(sub_type)
    obj.delete()
    dump_state(obj, 'After create')
def test_analysis_init(quicksight_application_stub, mininmal_data_sets_stub):
    stub = mininmal_data_sets_stub
    template_arn_param = template_arn

    obj = Analysis(
        quicksight_application=quicksight_application_stub,
        data_sets=stub.data_sets_stub,
        quicksight_template_arn=template_arn_param,
        props=None
    )
    dump_state(obj, 'Dump analysis')
def test_analysis_create_invalid_parameter(
    quicksight_application_stub,
    mininmal_data_source_stub,
    mininmal_data_sets_stub,
    template_arn,
):
    obj = Analysis(
        quicksight_application=quicksight_application_stub,
        data_source=mininmal_data_source_stub,
        data_sets=mininmal_data_sets_stub.data_sets_stub,
        quicksight_template_arn=template_arn,
        props=None,
    )

    sub_type = "main"
    [AnalysisStubber.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_analysis_update_source_entity(quicksight_application_stub, mininmal_data_sets_stub, template_arn):
    obj = Analysis(
        quicksight_application=quicksight_application_stub,
        data_sets=mininmal_data_sets_stub.data_sets_stub,
        quicksight_template_arn=template_arn,
        props=None
    )

    sub_type = 'main'
    assert sub_type in obj.config_data
    assert 'SourceEntity' in obj.config_data[sub_type]

    source_entity = obj.source_entity._get_map(sub_type, "SourceEntity")
    dump_state(source_entity, 'Dump SourceEntity before update')

    assert 'SourceTemplate' in source_entity
    source_template = source_entity.get('SourceTemplate', None)
    assert 'DataSetReferences' in source_template
    assert 'Arn' in source_template
    obj.source_entity._update_source_entity(source_entity)

    dump_state(source_entity, 'Dump SourceEntity after update')

    assert template_arn == source_template['Arn']
Exemple #6
0
from io import BytesIO
from pymongo import MongoClient
import requests
import glob
import cv2
from PIL import Image

from flask import Flask, request, make_response
from flask_cors import CORS, cross_origin
from model.tf_run import TFRun
from util.analysis import Analysis
from bson import json_util
import bson
app = Flask(__name__)
tf_run = TFRun()
analysis = Analysis()
CORS(app, supports_credentials=True)

conn = conn = MongoClient('localhost', 27017)
db = conn.fashion_base  #连接mydb数据库,没有则自动创建
my_table = db.fashion_match
RECOMMEND_NUM = 5


@app.after_request
def af_request(resp):
    """
    #请求钩子,在所有的请求发生后执行,加入headers。
    :param resp:
    :return:
    """
Exemple #7
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}'
        )
    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}"
        )