コード例 #1
0
def stages(operations, session_stage_configs, stack_resources, api_schema):

    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    print("Creating test stages")
    for config in session_stage_configs:

        print("\nSTAGE CONFIGURATION: {}".format(config))

        # Create the stage
        create_stage_response = api.create_stage_request(
            config, stack_resources)
        stage = create_stage_response.json()

        assert create_stage_response.status_code == 200
        validation.schema(stage, api_schema["create_stage_response"])

    yield session_stage_configs

    for config in session_stage_configs:
        #Delete the stage
        stage = {}
        stage["Name"] = config["Name"]

        delete_stage_response = api.delete_stage_request(
            stage, stack_resources)
        assert delete_stage_response.status_code == 200
コード例 #2
0
def udi_operations(udi_operation_configs, stack_resources, api_schema):

    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    print("Creating update/delete test operations")
    for config in udi_operation_configs:

        print("\nOPERATION CONFIGURATION: {}".format(config))

        # Create the operation
        create_operation_response = api.create_operation_request(
            config, stack_resources)
        operation = create_operation_response.json()

        assert create_operation_response.status_code == 200
        #validation.schema(operation, api_schema["create_operation_response"])
        validation.schema(operation, api_schema["create_operation_response"])

    yield udi_operation_configs

    for config in udi_operation_configs:
        #Delete the operation
        operation = {}
        operation["Name"] = config["Name"]

        delete_operation_response = api.delete_operation_request(
            operation, stack_resources)
        assert delete_operation_response.status_code == 200
コード例 #3
0
def operations(api, session_operation_configs, api_schema):
    api = api()
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    print("Creating test operations")
    for config in session_operation_configs:

        print("\nOPERATION CONFIGURATION: {}".format(config))

        # Create the operation
        create_operation_response = api.create_operation_request(config)
        operation = create_operation_response.json()
        assert create_operation_response.status_code == 200
        validation.schema(operation, api_schema["create_operation_response"])
コード例 #4
0
def stages(api, operations, session_stage_configs, api_schema):
    api = api()
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    print("Creating test stages")
    for config in session_stage_configs:

        print("\nSTAGE CONFIGURATION: {}".format(config))

        # Create the stage
        create_stage_response = api.create_stage_request(config)
        stage = create_stage_response.json()

        assert create_stage_response.status_code == 200
        validation.schema(stage, api_schema["create_stage_response"])
コード例 #5
0
ファイル: app.py プロジェクト: bulv1ne/imageresizer
def handle(request):
    print(request.path_qs)
    query_components = dict(parse_qsl(urlparse(request.path_qs).query))
    try:
        query_components = schema(query_components)
    except MultipleInvalid:
        raise web.HTTPBadRequest

    url = query_components['source']
    resize = query_components['resize']

    data = yield from download_file(url)
    try:
        img = Image.open(data)
    except OSError:
        raise web.HTTPBadRequest
    try:
        img.thumbnail(resize)
    except IndexError:
        raise web.HTTPBadRequest

    return stream_from_image(img, request=request)
コード例 #6
0
def test_stage_api(api, api_schema, operations, stages, stage_configs):
    api = api()
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    print("Running /workflow/stage API tests")
    for config in stage_configs:
        
        print("----------------------------------------")
        print("\nTEST STAGE CONFIGURATION: {}".format(config))

        # Create the stage
        create_stage_response = api.create_stage_request(config)
        stage = create_stage_response.json()
        
        print(stage)

        assert create_stage_response.status_code == 200
        validation.schema(stage, api_schema["create_stage_response"])

        get_stage_response = api.get_stage_request(stage)
        stage = get_stage_response.json()
        assert get_stage_response.status_code == 200
        validation.schema(stage, api_schema["create_stage_response"])

        # Create a singleton workflow to test executing this stage
        create_workflow_response = api.create_stage_workflow_request(stage)
        workflow = create_workflow_response.json()
        assert create_workflow_response.status_code == 200
        #FIXME - validate create_workflow_response
        # validation.schema(workflow, api_schema["create_workflow_response"])

        # Execute the stage and wait for it to complete
        create_workflow_execution_response = api.create_workflow_execution_request(workflow, config)
        workflow_execution = create_workflow_execution_response.json()
        assert create_workflow_execution_response.status_code == 200
        assert workflow_execution['Status'] == 'Queued'
        
        #FIXME - validate create_workflow_response
        #validation.schema(workflow_execution, api_schema["create_workflow_execution_response"])
        workflow_execution = api.wait_for_workflow_execution(workflow_execution, 120)
        if config["Status"] == "OK":
            assert workflow_execution["Status"] == "Complete"
            
            # Check output media for expected types
            for outputType in config["Outputs"]:
                if outputType != "None":
                    assert outputType in workflow_execution["Globals"]["Media"]
                     
        else:
            assert workflow_execution["Status"] == "Error"

        # Check output metadata for expected keys - each test operation writes a key with its operation name
        for metadataKey in config["ExecutedOperations"]:
            assert metadataKey in workflow_execution["Globals"]["MetaData"]
            if "TestCustomConfig" in config:
                assert "TestCustomConfig" in workflow_execution["Globals"]["MetaData"][metadataKey]
                assert workflow_execution["Globals"]["MetaData"][metadataKey]["TestCustomConfig"] == config["TestCustomConfig"]

        #validation.stage_execution(workflow_execution, config, stack_resources, api_schema)

        # Delete the workflow
        delete_workflow_response = api.delete_stage_workflow_request(workflow)
        assert delete_workflow_response.status_code == 200
        
        #Delete the stage
        delete_stage_response = api.delete_stage_request(stage)
        assert delete_stage_response.status_code == 200




#TODO: dynamoDB remove asset
コード例 #7
0
def test_workflow_execution_api(operations, stages, workflow_configs,
                                stack_resources, api_schema):

    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    print("Running /workflow/execution API tests")
    for config in workflow_configs:

        print("----------------------------------------")
        print("\nTEST WORKFLOW EXECUTION CONFIGURATION: {}".format(config))

        # Create the workflow
        create_workflow_response = api.create_workflow_request(
            config, stack_resources)
        workflow = create_workflow_response.json()

        assert create_workflow_response.status_code == 200
        validation.schema(workflow, api_schema["create_workflow_response"])

        get_workflow_response = api.get_workflow_request(
            workflow, stack_resources)
        workflow = get_workflow_response.json()
        assert get_workflow_response.status_code == 200
        validation.schema(workflow, api_schema["create_workflow_response"])

        # Execute the workflow and wait for it to complete
        create_workflow_execution_response = api.create_workflow_execution_request(
            workflow, config, stack_resources)
        workflow_execution = create_workflow_execution_response.json()
        assert create_workflow_execution_response.status_code == 200
        assert workflow_execution['Status'] == 'Queued'

        #FIXME - validate create_workflow_response
        #validation.schema(workflow_execution, api_schema["create_workflow_execution_response"])
        workflow_execution = api.wait_for_workflow_execution(
            workflow_execution, stack_resources, 120)
        if config["Status"] == "OK":
            assert workflow_execution["Status"] == "Complete"

            # Check output media for expected types
            for outputType in config["Outputs"]:
                if outputType != "None":
                    assert outputType in workflow_execution["Globals"]["Media"]

        else:
            assert workflow_execution["Status"] == "Error"

        # validation.stage_execution(workflow_execution, config, stack_resources, api_schema)

        # Delete the workflow
        delete_workflow_response = api.delete_stage_workflow_request(
            workflow, stack_resources)
        assert delete_workflow_response.status_code == 200

        #Delete the workflow
        delete_stage_response = api.delete_stage_request(
            workflow, stack_resources)
        assert delete_stage_response.status_code == 200


#TODO: dynamoDB remove asset
コード例 #8
0
def test_operation_api(operation_configs, stack_resources, api_schema):

    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    print("Running /workflow/operation API tests")
    for config in operation_configs:
        print("\n----------------------------------------")
        print("\nTEST CONFIGURATION: {}".format(config))

        # Create the operation
        create_operation_response = api.create_operation_request(
            config, stack_resources)
        operation = create_operation_response.json()

        assert create_operation_response.status_code == 200
        #validation.schema(operation, api_schema["create_operation_response"])
        validation.schema(operation, api_schema["create_operation_response"])

        get_operation_response = api.get_operation_request(
            operation, stack_resources)
        operation = create_operation_response.json()
        assert get_operation_response.status_code == 200
        validation.schema(operation, api_schema["create_operation_response"])

        # Create a singleton workflow to test executing this operation
        create_workflow_response = api.create_operation_workflow_request(
            operation, stack_resources)
        workflow = create_workflow_response.json()
        assert create_workflow_response.status_code == 200
        # FIXME - need to update schema manually
        # #validation.schema(workflow, api_schema["create_workflow_response"])

        # Execute the operation and wait for it to complete
        create_workflow_execution_response = api.create_workflow_execution_request(
            workflow, config, stack_resources)
        workflow_execution = create_workflow_execution_response.json()
        assert create_workflow_execution_response.status_code == 200
        assert workflow_execution['Status'] == 'Queued'
        # FIXME - need schema
        # #validation.schema(workflow_execution, api_schema["create_workflow_execution_response"])
        workflow_execution = api.wait_for_workflow_execution(
            workflow_execution, stack_resources, 120)
        if config["Status"] == "OK":
            assert workflow_execution["Status"] == "Complete"

            # FIXME - validate the execution result
            # Check output media, metadata, operation status, workflow status, ....
        else:
            assert workflow_execution["Status"] == "Error"

        validation.operation_execution(workflow_execution, config,
                                       stack_resources, api_schema)

        # Delete the workflow
        delete_workflow_response = api.delete_operation_workflow_request(
            workflow, stack_resources)
        assert delete_workflow_response.status_code == 200

        #Delete the operation
        delete_operation_response = api.delete_operation_request(
            operation, stack_resources)
        assert delete_operation_response.status_code == 200


#TODO: dynamoDB remove asset
コード例 #9
0
def test_workflow_api(workflow_api, api_schema, operation_configs,
                      stage_configs, workflow_configs):
    api = workflow_api()
    schema = api_schema
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    print("Running /workflow/operation API create tests")

    for operation_config in operation_configs:
        print("\n----------------------------------------")
        print("\nTEST CONFIGURATION: {}".format(operation_config))
        start_lambda = operation_config["Input"] + operation_config[
            "Type"] + operation_config["Status"] + "Lambda"

        # Create the operation

        operation_body = {
            "StartLambdaArn": api.stack_resources[start_lambda],
            "Configuration": {
                "MediaType": operation_config["Input"],
                "Enabled": True
            },
            "Type": operation_config["Type"],
            "Name": operation_config["Name"]
        }

        if (operation_config["Type"] == "Async"):
            monitor_lambda = operation_config["Input"] + operation_config[
                "Type"] + operation_config["Status"] + "MonitorLambda"
            operation_body["MonitorLambdaArn"] = api.stack_resources[
                monitor_lambda]

        if "OutputMediaType" in operation_config:
            operation_body["Configuration"][
                "OutputMediaType"] = operation_config["OutputMediaType"]

        if "TestCustomConfig" in operation_config:
            operation_body["Configuration"][
                "TestCustomConfig"] = operation_config["TestCustomConfig"]

        create_operation_response = api.create_operation_request(
            operation_body)
        assert create_operation_response.status_code == 200
        validation.schema(create_operation_response.json(),
                          api_schema["create_operation_response"])

        # Read the operation

        print("Running /workflow/operation API read tests")

        get_operation_response = api.get_operation_request(
            operation_config["Name"])
        assert get_operation_response.status_code == 200

    print("Running /workflow/stage API create tests")

    for stage_config in stage_configs:
        print("\n----------------------------------------")
        print("\nTEST CONFIGURATION: {}".format(stage_config))

        # Create the stage

        stage_body = {
            "Name": stage_config["Name"],
            "Operations": stage_config["Operations"]
        }

        create_stage_response = api.create_stage_request(stage_body)
        assert create_stage_response.status_code == 200
        validation.schema(create_stage_response.json(),
                          api_schema["create_stage_response"])

        # Read the stage

        print("Running /workflow/stage API read tests")

        get_stage_response = api.get_stage_request(stage_config["Name"])
        assert get_stage_response.status_code == 200

    print("Running /workflow API create tests")

    for workflow_config in workflow_configs:
        print("\n----------------------------------------")
        print("\nTEST CONFIGURATION: {}".format(workflow_config))

        workflow_body = {
            "Name": workflow_config["Name"],
            "StartAt": stage_configs[0]["Name"]
        }

        workflow_stages = {}
        num_stages = len(stage_configs)
        i = 1
        for stages in stage_configs:
            if i == num_stages:
                workflow_stages[stages["Name"]] = {"End": True}
            else:
                workflow_stages[stages["Name"]] = {
                    "Next": stage_configs[i]["Name"]
                }
            i = i + 1

        workflow_body["Stages"] = workflow_stages

        create_workflow_response = api.create_workflow_request(workflow_body)
        assert create_workflow_response.status_code == 200
        # FIXME - need to update schema manually
        # #validation.schema(workflow, api_schema["create_workflow_response"])

    print("Running /workflow API delete tests")

    # Delete the workflow
    time.sleep(10)
    for workflow_config in workflow_configs:
        delete_workflow_response = api.delete_workflow_request(
            workflow_config["Name"])
        print(delete_workflow_response.json())
        assert delete_workflow_response.status_code == 200

    print("Running /workflow/stage API delete tests")

    # Delete the stages
    for stage_config in stage_configs:
        delete_stage_response = api.delete_stage_request(stage_config["Name"])
        assert delete_stage_response.status_code == 200

    print("Running /workflow/operation API delete tests")

    # Delete the operations
    for operation_config in operation_configs:
        delete_workflow_response = api.delete_operation_request(
            operation_config["Name"])
        assert delete_workflow_response.status_code == 200