Exemplo n.º 1
0
    def test_plugin_init_bad(self, data):
        """Tests plugin_init using an invalid set of values"""

        ocs._logger = MagicMock()

        with pytest.raises(Exception):
            ocs.plugin_init(data)
Exemplo n.º 2
0
    def test_plugin_init_good(self):
        """Tests plugin_init using a good set of values"""

        ocs._logger = MagicMock()

        # Used to check the conversions
        data = {
            "stream_id": {
                "value": 1
            },
            "_CONFIG_CATEGORY_NAME":
            module_sp.SendingProcess._CONFIG_CATEGORY_NAME,
            "URL": {
                "value": "test_URL"
            },
            "producerToken": {
                "value": "test_producerToken"
            },
            "OMFMaxRetry": {
                "value": "100"
            },
            "OMFRetrySleepTime": {
                "value": "100"
            },
            "OMFHttpTimeout": {
                "value": "100"
            },
            "StaticData": {
                "value":
                json.dumps({
                    "Location": "Palo Alto",
                    "Company": "Dianomic"
                })
            },
            'sending_process_instance': MagicMock(spec=SendingProcess),
            "formatNumber": {
                "value": "float64"
            },
            "formatInteger": {
                "value": "int32"
            },
        }

        config_default_omf_types = ocs._CONFIG_DEFAULT_OMF_TYPES
        config_default_omf_types["type-id"]["value"] = "0001"

        with patch.object(data['sending_process_instance'],
                          '_fetch_configuration',
                          return_value=config_default_omf_types):
            config = ocs.plugin_init(data)

        assert config[
            '_CONFIG_CATEGORY_NAME'] == module_sp.SendingProcess._CONFIG_CATEGORY_NAME
        assert config['URL'] == "test_URL"
        assert config['producerToken'] == "test_producerToken"
        assert config['OMFMaxRetry'] == 100
        assert config['OMFRetrySleepTime'] == 100
        assert config['OMFHttpTimeout'] == 100

        # Check conversion from String to Dict
        assert isinstance(config['StaticData'], dict)
Exemplo n.º 3
0
    def test_plugin_init_good(self):
        """Tests plugin_init using a good set of values"""

        ocs._logger = MagicMock()

        # Used to check the conversions
        data = {
            "stream_id": {
                "value": 1
            },
            "_CONFIG_CATEGORY_NAME":
            module_sp.SendingProcess._CONFIG_CATEGORY_NAME,
            "URL": {
                "value": "test_URL"
            },
            "producerToken": {
                "value": "test_producerToken"
            },
            "OMFMaxRetry": {
                "value": "100"
            },
            "OMFRetrySleepTime": {
                "value": "100"
            },
            "OMFHttpTimeout": {
                "value": "100"
            },
            "StaticData": {
                "value":
                json.dumps({
                    "Location": "Palo Alto",
                    "Company": "Dianomic"
                })
            },
            "destination_type": {
                "value": "3"
            },
            'sending_process_instance': MagicMock(spec=SendingProcess),
            "formatNumber": {
                "value": "float64"
            },
            "formatInteger": {
                "value": "int64"
            },
            "notBlockingErrors": {
                "value": "{'id': 400, 'message': 'none'}"
            },
            "compression": {
                "value": "true"
            },
            "namespace": {
                "value": "ocs_namespace_0001"
            },
            "tenant_id": {
                "value": "ocs_tenant_id"
            },
            "client_id": {
                "value": "ocs_client_id"
            },
            "client_secret": {
                "value": "ocs_client_secret"
            },
        }

        config_default_omf_types = ocs._CONFIG_DEFAULT_OMF_TYPES
        config_default_omf_types["type-id"]["value"] = "0001"
        data["debug_level"] = None
        data["log_performance"] = None
        data["destination_id"] = 1
        data["stream_id"] = 1

        with patch.object(data['sending_process_instance'],
                          '_fetch_configuration',
                          return_value=config_default_omf_types):
            config = ocs.plugin_init(data)

        assert config[
            '_CONFIG_CATEGORY_NAME'] == module_sp.SendingProcess._CONFIG_CATEGORY_NAME
        assert config['URL'] == "test_URL"
        assert config['producerToken'] == "test_producerToken"
        assert config['OMFMaxRetry'] == 100
        assert config['OMFRetrySleepTime'] == 100
        assert config['OMFHttpTimeout'] == 100

        # Check conversion from String to Dict
        assert isinstance(config['StaticData'], dict)