Пример #1
0
    def _default_test_transformer(self) -> RegexStrReplaceTransformer:
        config = ConfigFactory.from_dict({
            REGEX_REPLACE_TUPLE_LIST: [('a', 'b'), ('c', 'a')],
            ATTRIBUTE_NAME: 'val'
        })

        transformer = RegexStrReplaceTransformer()
        transformer.init(config)

        return transformer
    def _default_test_transformer(self):
        # type: () -> RegexStrReplaceTransformer
        config = ConfigFactory.from_dict({
            'regex_replace_tuple_list': [('a', 'b'), ('c', 'a')],
            'attribute_name':
            'val'
        })

        transformer = RegexStrReplaceTransformer()
        transformer.init(config)

        return transformer
Пример #3
0
    def test_dict_replace(self) -> None:
        config = ConfigFactory.from_dict({
            REGEX_REPLACE_TUPLE_LIST: [('\\', '\\\\')],
            ATTRIBUTE_NAME: 'val'
        })

        transformer = RegexStrReplaceTransformer()
        transformer.init(config)

        d = {'val': '\\'}

        actual = transformer.transform(d)

        self.assertEqual({'val': '\\\\'}, actual)
Пример #4
0
    def test(self):
        # type: () -> None
        config = ConfigFactory.from_dict({
            'regex_replace_tuple_list': [('a', 'b'), ('c', 'a')],
            'attribute_name':
            'val'
        })

        transformer = RegexStrReplaceTransformer()
        transformer.init(config)

        foo = Foo('abc')
        actual = transformer.transform(foo)

        self.assertEqual('bba', actual.val)
    def init(self, conf):
        # type: (ConfigTree) -> None
        self._conf = conf

        restapi_query = self._build_restapi_query()
        self._extractor = ModeDashboardUtils.create_mode_rest_api_extractor(
            restapi_query=restapi_query, conf=self._conf)

        # Constructing URL using several ID via TemplateVariableSubstitutionTransformer
        transformers = []
        variable_substitution_transformer = TemplateVariableSubstitutionTransformer(
        )
        variable_substitution_transformer.init(conf=Scoped.get_scoped_conf(
            self._conf,
            variable_substitution_transformer.get_scope()).with_fallback(
                ConfigFactory.from_dict({
                    FIELD_NAME:
                    'url',
                    TEMPLATE:
                    'https://app.mode.com/{organization}'
                    '/reports/{dashboard_id}/queries/{query_id}'
                })))

        transformers.append(variable_substitution_transformer)

        # Escape backslash as it breaks Cypher statement.
        replace_transformer = RegexStrReplaceTransformer()
        replace_transformer.init(conf=Scoped.get_scoped_conf(
            self._conf, replace_transformer.get_scope()).with_fallback(
                ConfigFactory.from_dict({
                    REGEX_REPLACE_TUPLE_LIST: [('\\', '\\\\')],
                    ATTRIBUTE_NAME:
                    'query_text'
                })))
        transformers.append(replace_transformer)

        dict_to_model_transformer = DictToModel()
        dict_to_model_transformer.init(conf=Scoped.get_scoped_conf(
            self._conf, dict_to_model_transformer.get_scope()
        ).with_fallback(
            ConfigFactory.from_dict({
                MODEL_CLASS:
                'databuilder.models.dashboard.dashboard_query.DashboardQuery'
            })))
        transformers.append(dict_to_model_transformer)

        self._transformer = ChainedTransformer(transformers=transformers)
Пример #6
0
    def init(self, conf):
        # type: (ConfigTree) -> None

        self._extractor = conf.get(RAW_EXTRACTOR)  # type: Extractor
        self._extractor.init(Scoped.get_scoped_conf(conf, self._extractor.get_scope()))

        regex_transformer = RegexStrReplaceTransformer()  # type: Any
        if conf.get(regex_transformer.get_scope(), None):
            regex_transformer.init(Scoped.get_scoped_conf(conf, regex_transformer.get_scope()))
        else:
            LOGGER.info('{} is not defined. Not using it'.format(regex_transformer.get_scope()))
            regex_transformer = NoopTransformer()

        sql_to_usage_transformer = SqlToTblColUsageTransformer()
        sql_to_usage_transformer.init(Scoped.get_scoped_conf(conf, sql_to_usage_transformer.get_scope()))

        self._transformer = ChainedTransformer((regex_transformer, sql_to_usage_transformer))