def test_excluded_property(self):
        """!
        Test error if accessing property that has been restricted
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file,
            licence_keys="",
            restricted_properties=["ismobile"]).build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        result = ""

        try:
            fd.device.get("screenpixelsheight")
        except Exception as e:
            result = str(e)

        self.assertEqual(
            result, "Property screenpixelsheight was excluded from device")
    def test_missing_property_service_not_found_anywhere(self):
        """!
        Trigger the missing property service by requesting a property
        not available in any datafile
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        result = ""

        try:
            fd.device.get("notpresent")
        except Exception as e:
            result = str(e)

        self.assertEqual(
            result,
            "Property notpresent not found in data for element device. Please check that the element and property names are correct."
        )
    def test_missing_property_service_not_found_in_current(self):
        """!
        Trigger the missing property service by requesting a property
        not available in the current datafile
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        # Add mock property not in datafile

        pipeline.get_element("device").properties["mock"] = {
            "datafiles": ["Enterprise"]
        }

        fd.process()

        result = ""

        try:
            fd.device.get("mock")
        except Exception as e:
            result = str(e)

        self.assertEqual(
            result,
            "Property mock not found in data for element device. This is because your datafile does not contain the property. The property is available in['Enterprise']"
        )
    def test_engine_init_performance(self):
        """!
        Test how long it takes for the engine to be initialised
        by looking at the metadata dictionary created on init
        """

        start = time.time()

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        properties = fd.pipeline.get_element("device").get_properties()

        for engine_property in properties:
            self.assertNotEqual(fd.device.get(engine_property), None)

        end = time.time()

        total = end - start

        self.assertLess(total, 1)
    def test_validate_data_false(self):
        """!
        Validate whether has_value returns correctly with invalid evidence
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        properties = fd.pipeline.get_element("device").get_properties()

        for engine_property in properties:
            data_property = fd.device.get(engine_property)
            if properties[engine_property]["category"] == "Device metrics":
                self.assertEqual(data_property.has_value(), True)
            elif engine_property == "deviceid":
                self.assertEqual(fd.device.deviceid.value(), "0-0-0-0")
            else:
                self.assertEqual(data_property.has_value(), False)
    def test_process_with_no_evidence(self):
        """!
        Process a FlowData which does not have any evidence. This should not throw an error and all 51Degrees engines should set the default aspect properties
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

        fd.process()

        self.assertTrue(fd.device.difference.has_value())
    def test_engine_reload(self):
        """!
        Refresh the engine
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

        fd.process()

        fd.pipeline.get_element("device").engine.refreshData()
    def test_matched_user_agents(self):
        """!
        Test aspect property value returns false for has value
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        self.assertEqual(fd.device.useragents.value(), 1)
    def test_has_value_false(self):
        """!
        Test aspect property value returns false for has value
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        self.assertFalse(fd.device.ismobile.has_value())
    def test_device_id(self):
        """!
        Test profile overrides with device ids
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        self.assertEqual(fd.device.deviceid.value(), "12280-81243-82102-0")
    def test_case_insensitive_evidence_keys(self):
        """!
        Process a FlowData with case insensitive evidence keys
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        self.assertTrue(fd.device.ismobile.value())
    def test_process_with_no_useful_headers(self):
        """!
        Process a FlowData with no useful headers
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

        fd.evidence.add("header.irrelevant", "some-evidence")

        fd.process()

        self.assertFalse(fd.device.ismobile.has_value())
    def test_process_with_empty_user_agent(self):
        """!
        Process a FlowData with an empty user agent
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        self.assertFalse(fd.device.ismobile.has_value())
    def test_profile_overrides_deviceid(self):
        """!
        Test profile overrides with device ids
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

        fd.evidence.add("query.51D_ProfileIds", "12280-17779-17470-18092")

        fd.process()

        self.assertEqual(fd.device.deviceid.value(), "12280-17779-17470-18092")
    def test_basic_get_onpremise(self):
        """!
        Check property lookup works
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        self.assertTrue(fd.device.ismobile.value())
    def test_available_properties(self):
        """!
        Test properties that come back from getProperties actually exist in engine
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        properties = fd.pipeline.get_element("device").get_properties()

        for engine_property in properties:
            self.assertNotEqual(fd.device.get(engine_property), None)
    def test_value_types(self):
        """!
        Test type is returned correctly for property
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

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

        fd.process()

        ismobile = fd.pipeline.get_element(
            "device").get_properties()["ismobile"]

        self.assertEqual(ismobile["type"],
                         type(fd.device.ismobile.value()).__name__)
    def test_no_element_exists(self):
        """!
        Access flow element that doesn't exist in pipeline
        """

        pipeline = DeviceDetectionOnPremisePipelineBuilder(
            data_file_path=data_file, usage_sharing=False,
            licence_keys="").build()

        fd = pipeline.create_flowdata()

        fd.process()

        message = ""

        try:
            message = fd.devisce
        except Exception as e:
            message = str(e)

        self.assertEqual(
            message,
            "There is no element data for devisce against this flow data. Available element data keys are: ['device']"
        )
Beispiel #19
0
    auto_update=False).build()

# Now we see what properties are available in the pipeline

properties = pipeline.get_properties()

# Now we find out the details of the properties in the device engine

for property_key, property_meta in properties["device"].items():
        print(property_key + " of category " + property_meta["category"])

# Now we can take a User-Agent, run it through this pipeline and check 
# the supported media properties against it

# First we create a FlowData object from the pipeline
flowdata = pipeline.create_flowdata()

# Then we add the User-Agent we are interested in as evidence
iphone_ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114"

flowdata.evidence.add("header.user-agent", iphone_ua)

# Now we process the FlowData using the engines in the Pipeline

flowdata.process()

# To get all properties of a specific category, we can use the "getWhere" function

mediaSupport = flowdata.get_where("category", "Supported Media")

for supportedMediaProperty, supportedValue in mediaSupport.items():
from fiftyone_devicedetection_onpremise.devicedetection_onpremise_pipelinebuilder import DeviceDetectionOnPremisePipelineBuilder

# First create the device detection pipeline with the desired settings.

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

pipeline = DeviceDetectionOnPremisePipelineBuilder(
    data_file_path=data_file,
    licence_keys="",
    performance_profile='MaxPerformance',
    auto_update=False).build()

# We create a FlowData object from the pipeline
# this is used to add evidence to and then process

flowdata1 = pipeline.create_flowdata()

# Here we add a User-Agent of a desktop as evidence

desktop_ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"

flowdata1.evidence.add("header.user-agent", desktop_ua)

# Now we process the FlowData

flowdata1.process()

# To check whether the User-Agent is a mobile device we look at the ismobile property
# inside the Device Detection Engine

# first we check if this has a meaningful result