def _build_extractor(self) -> RestAPIExtractor:

        extractor = RestAPIExtractor()
        rest_api_extractor_conf = ConfigFactory.from_dict(
            {REST_API_QUERY: self._build_restapi_query()})
        extractor.init(rest_api_extractor_conf)
        return extractor
    def test_static_data(self) -> None:

        conf = ConfigFactory.from_dict(
            {
                REST_API_QUERY: RestApiQuerySeed(seed_record=[{'foo': 'bar'}]),
                STATIC_RECORD_DICT: {'john': 'doe'}
            }
        )
        extractor = RestAPIExtractor()
        extractor.init(conf=conf)

        record = extractor.extract()
        expected = {'foo': 'bar', 'john': 'doe'}

        self.assertDictEqual(expected, record)
    def test_model_construction(self) -> None:
        conf = ConfigFactory.from_dict(
            {
                REST_API_QUERY: RestApiQuerySeed(
                    seed_record=[{'dashboard_group': 'foo',
                                  'dashboard_name': 'bar',
                                  'description': 'john',
                                  'dashboard_group_description': 'doe'}]),
                MODEL_CLASS: 'databuilder.models.dashboard.dashboard_metadata.DashboardMetadata',
            }
        )
        extractor = RestAPIExtractor()
        extractor.init(conf=conf)

        record = extractor.extract()
        expected = DashboardMetadata(dashboard_group='foo', dashboard_name='bar', description='john',
                                     dashboard_group_description='doe')

        self.assertEqual(expected.__repr__(), record.__repr__())
Exemplo n.º 4
0
    def create_mode_rest_api_extractor(restapi_query: BaseRestApiQuery,
                                       conf: ConfigTree) -> RestAPIExtractor:
        """
        Creates RestAPIExtractor. Note that RestAPIExtractor is already initialized
        :param restapi_query:
        :param conf:
        :return: RestAPIExtractor. Note that RestAPIExtractor is already initialized
        """
        extractor = RestAPIExtractor()
        rest_api_extractor_conf = \
            Scoped.get_scoped_conf(conf, extractor.get_scope())\
                  .with_fallback(conf)\
                  .with_fallback(ConfigFactory.from_dict({REST_API_QUERY: restapi_query,
                                                          STATIC_RECORD_DICT: {'product': 'mode'}
                                                          }
                                                         )
                                 )

        extractor.init(conf=rest_api_extractor_conf)
        return extractor