def test_build_from_config(self):

        config = {
            "PipelineOptions": {
                "Elements": [{
                    "elementName": "DeviceDetectionOnPremise",
                    "elementPath":
                    "fiftyone_devicedetection_onpremise.devicedetection_onpremise",
                    "elementParameters": {
                        "data_file_path": data_file,
                        "licence_keys": ""
                    }
                }]
            }
        }

        pipeline = PipelineBuilder().build_from_configuration(config)

        fd = pipeline.create_flowdata()

        fd.evidence.add("header.User-Agent", mobile_ua)

        fd.process()

        self.assertTrue(fd.device.ismobile.value())
Ejemplo n.º 2
0
    def testEngineProcessing(self):
    
        testPipeline = PipelineBuilder().add(ExampleAspectEngine()).build()

        flowdata = testPipeline.create_flowdata()

        flowdata.process()

        self.assertTrue(flowdata.example.integer == 5)
Ejemplo n.º 3
0
    def testMissingPropertyService(self):
        
        engine = ExampleAspectEngine()

        testPipeline = PipelineBuilder().add(engine).build()

        flowdata = testPipeline.create_flowdata()

        flowdata.process()

        try:
           flowdata.example.get("missing")
        except Exception as e:
            result = str(e)

        self.assertTrue(result == "Property missing not found in example")
Ejemplo n.º 4
0
    def testRestrictedProperty(self):
        
        engine = ExampleAspectEngine()

        engine.set_restricted_properties(["boolean"])

        testPipeline = PipelineBuilder().add(engine).build()

        flowdata = testPipeline.create_flowdata()

        flowdata.process()

        try:
            flowdata.example.get("integer")
        except Exception as e:
            result = str(e)

        self.assertTrue(result == "Property integer was excluded from example")
    def __init__(self, minify=None):

        if minify == None:
            pipelineSettings = {}
        else:
            jsSettings = {'minify': minify}
            pipelineSettings = {'javascript_builder_settings': jsSettings}

        self.Pipeline = PipelineBuilder(pipelineSettings)\
            .add(TestEngine())\
            .build()
Ejemplo n.º 6
0
    def testLRUCache(self):

        engine = ExampleAspectEngine()

        cache = LRUEngineCache()

        engine.set_cache(cache)

        testPipeline = PipelineBuilder().add(engine).build()

        flowdata = testPipeline.create_flowdata()

        flowdata.evidence.add("header.test", "test")

        flowdata.process()

        flowdata2 = testPipeline.create_flowdata()

        flowdata2.evidence.add("header.test", "test")

        flowdata2.process()

        self.assertEqual(cache.cache.currsize, 1)
Ejemplo n.º 7
0
    def test_build_from_config(self):

        config = {
            "PipelineOptions": {
                "Elements": [{
                    "elementName": "ExampleFlowElement1",
                    "elementPath": "classes.exampleflowelement1",
                    "elementParameters": {
                        "example_param": "hello"
                    }
                }]
            }
        }

        pipeline = PipelineBuilder().build_from_configuration(config)

        fd = pipeline.create_flowdata()

        fd.evidence.add("header.user-agent", "test")

        fd.process()

        getValue = fd.get("example1").get("integer")
        self.assertTrue(getValue == 5)
Ejemplo n.º 8
0
    def __init__(self):

        logger = MemoryLogger("info")
        self.flowElement1 = ExampleFlowElement1()
        self.pipeline = (PipelineBuilder())\
            .add(self.flowElement1)\
            .add(ErrorFlowData())\
            .add(APVFlowElement())\
            .add(StopFlowData())\
            .add(ExampleFlowElement2())\
            .add_logger(logger)\
            .build()
        self.flowdata = self.pipeline.create_flowdata()
        self.flowdata.evidence.add("header.user-agent", "test")
        self.flowdata.evidence.add("some.other-evidence", "test")
        self.pipeline.log("error", "test")
        self.flowdata.process()
    def test_jsonbundler_when_delayed_execution_false(self):

        pipeline = PipelineBuilder()

        pipeline.add(DelayedExecutionEngine1())
        pipeline = pipeline.build()

        flowdata = pipeline.create_flowdata()

        flowdata.process()

        expected = {"one": 1, "two": 2}
        actual = flowdata.jsonbundler.json["delayedexecutiontest1"]
        self.assertEqual(actual, expected)
    def test_jsonbundler_when_delayed_execution_true(self):

        pipeline = PipelineBuilder()

        pipeline.add(DelayedExecutionEngine2())
        pipeline = pipeline.build()

        flowdata = pipeline.create_flowdata()

        flowdata.process()

        expected = {
            "onedelayexecution": True,
            "one": 1,
            "twoevidenceproperties": ['delayedexecutiontest2.one'],
            "two": 2
        }

        actual = flowdata.jsonbundler.json["delayedexecutiontest2"]
        self.assertEqual(actual, expected)
Ejemplo n.º 11
0
import os
import unittest

from fiftyone_pipeline_core.pipelinebuilder import PipelineBuilder
from fiftyone_devicedetection_onpremise.devicedetection_onpremise import DeviceDetectionOnPremise
from fiftyone_devicedetection_onpremise.swig_data import SwigData
from fiftyone_devicedetection_shared.utils import *

data_file = "./fiftyone_devicedetection_onpremise/device-detection-cxx/device-detection-data/51Degrees-LiteV4.1.hash"

# Create a simple pipeline to access the engine with and process it with flow data
deviceDetectionOnPremiseEngine = DeviceDetectionOnPremise(
    data_file_path=data_file, licence_keys="", auto_update=False)
pipeline = PipelineBuilder() \
            .add(deviceDetectionOnPremiseEngine) \
            .build()


class SwigTests(unittest.TestCase):

    # Mock the native code parts so we are only testing the wrapper.
    class MockSwigResults:
        class MockSwigValue:
            def __init__(self, value, noValueMessage):
                self.value = value
                self.noValueMessage = noValueMessage

            def hasValue(self):
                return True
Ejemplo n.º 12
0
    """)
else:

    # Create an instance of the cloud request engine with your resource key

    request_engine_instance = CloudRequestEngine(
        {"resource_key": resource_key})

    # Now create an instance of the hardwareprofile cloud engine

    hardware_profile_engine_instance = HardwareProfileCloud()

    # Now create a pipeline and add those two engines
    # the Cloud Request Engine needs to go first

    pipeline = PipelineBuilder().add(request_engine_instance).add(
        hardware_profile_engine_instance).build()

    # we get a tac to test
    tac = "35925406"

    # We create a FlowData object from the pipeline
    # this is used to add evidence to and then process
    flowdata = pipeline.create_flowdata()

    # After creating a flowdata instance, add the native model name as evidence.
    flowdata.evidence.add('query.tac', tac)

    # Now we process the FlowData to get results

    flowdata.process()
        """
        get_evidence_key_filter - A filter (in this case a basic list) stating which evidence 
        the flowElement is interested in
        """
        return  BasicListEvidenceKeyFilter(["cookie.latitude", "query.dateOfBirth"])


# Add some callback settings for the page to make a request with extra evidence from the client side, in this case the Flask /json route we have made below

javascript_builder_settings = {
    "endpoint": "/json"
}

# Make the pipeline and add the element we want to it

myPipeline = (PipelineBuilder({"javascript_builder_settings": javascript_builder_settings})).add(AstrologyFlowElement()).build()

from flask import Flask, request

app = Flask(__name__)

# Make a route that returns back JSON encded properties for client side scripts to pick up

@app.route('/json', methods=['POST'])
def jsonroute():

    # Create the flowdata object for the JSON route
    flowdata = myPipeline.create_flowdata()

    # Add any information from the request (headers, cookies and additional 
    # client side provided information)
Ejemplo n.º 14
0
exclude_properties = ["setheaderbrowseraccept-ch", "setheaderplatformaccept-ch", "setheaderhardwareaccept-ch"]

if "resource_key" in os.environ:
    resource_key = os.environ["resource_key"]
else:
    raise Exception("To run the cloud tests, please set a valid 51Degrees "
                    "cloud resource key as the resource_key environment variable.")

# Get Properties list
properties_list = get_properties_from_header_file(header_file_path)

# Create a simple pipeline to access the engine with and process it with flow data
cloudRequestEngine = CloudRequestEngine({"resource_key": resource_key})
deviceDetectionCloudEngine = DeviceDetectionCloud()
pipeline = PipelineBuilder() \
        .add(cloudRequestEngine) \
        .add(deviceDetectionCloudEngine) \
        .build()
            
class PropertyTests(unittest.TestCase):

    def test_available_properties(self):

        """!
        Tests whether the all the properties present in the engine when initialised with a resource key are accessible.
        """

        flowData = pipeline.create_flowdata()
        flowData.evidence.add("header.user-agent", mobile_ua)
        flowData.process()
        elementData = flowData.get(deviceDetectionCloudEngine.datakey)