def test_make_tag_for_query_no_model_connection_should_succeed(self):
        tag_template = \
            self.__tag_template_factory.make_tag_template_for_query()

        query_data = {
            'id': 5,
            'runtime': 0.5,
            'client_id': 'test-client-id',
            'query_timezone': 'America/Sao_Paulo',
            'model': 'test-model',
            'view': 'test-view',
        }

        # yapf: disable
        assembled_metadata = entities.AssembledQueryMetadata(
            serialize.deserialize31(
                data=json.dumps(query_data),
                structure=models.Query),
            'select *',
            None,
            None)
        # yapf: enable

        tag = self.__factory.make_tag_for_query(tag_template,
                                                assembled_metadata)

        self.assertEqual(5, tag.fields['id'].double_value)
        self.assertFalse('lookml_project' in tag.fields)
        self.assertFalse('host' in tag.fields)
Ejemplo n.º 2
0
    def test_make_assembled_entries_list_should_process_queries(self):
        entry_factory = self.__entry_factory
        entry_factory.make_entry_for_query = self.__mock_make_entry

        tag_factory = self.__tag_factory
        tag_factory.make_tag_for_query = self.__mock_make_tag

        tag_templates_dict = {
            'looker_query_metadata': {
                'name': 'tagTemplates/looker_query_metadata',
            }
        }

        query_metadata = entities.AssembledQueryMetadata(
            self.__make_fake_query(), 'select *', {}, {})

        assembled_entries = \
            self.__assembled_data_factory.make_assembled_entries_list(
                [], [query_metadata], tag_templates_dict)

        self.assertEqual(1, len(assembled_entries))

        assembled_entry = assembled_entries[0]

        self.assertEqual(837, assembled_entry.entry_id)
        self.assertEqual('fake_entries/837', assembled_entry.entry.name)

        tags = assembled_entry.tags

        self.assertEqual(1, len(tags))
        self.assertEqual('tagTemplates/looker_query_metadata',
                         tags[0].template)
Ejemplo n.º 3
0
    def test_constructor_should_set_instance_attributes(self):
        assembled_metadata = \
            entities.AssembledQueryMetadata({}, 'select *', {}, {})

        self.assertIsNotNone(assembled_metadata.__dict__['query'])
        self.assertEqual('select *',
                         assembled_metadata.__dict__['generated_sql'])
        self.assertIsNotNone(assembled_metadata.__dict__['model_explore'])
        self.assertIsNotNone(assembled_metadata.__dict__['connection'])
    def __scrape_query(self, query_id):
        query = self.__metadata_scraper.scrape_query(query_id)

        model_explore = None
        connection = None
        generated_sql = None

        try:
            model_explore = self.__metadata_scraper\
                .scrape_lookml_model_explore(query.model, query.view)
            connection = self.__metadata_scraper.scrape_connection(
                model_explore.connection_name)
            generated_sql = \
                self.__metadata_scraper.scrape_query_generated_sql(query_id)
        except error.SDKError:
            pass

        return entities.AssembledQueryMetadata(query, generated_sql,
                                               model_explore, connection)
    def test_make_tag_for_query_should_set_all_available_fields(self):
        tag_template = \
            self.__tag_template_factory.make_tag_template_for_query()

        query_data = {
            'id': 5,
            'fields': [
                'field_a',
                'field_b',
            ],
            'pivots': [
                'pivot_a',
                'pivot_b',
            ],
            'sorts': [
                'sort_a',
                'sort_b',
            ],
            'runtime': 0.5,
            'client_id': 'test-client-id',
            'query_timezone': 'America/Sao_Paulo',
            'model': 'test-model',
            'view': 'test-view',
        }

        explore_data = {
            'project_name': 'test-project',
            'connection_name': 'test-connection',
        }

        connection_data = {
            'host': '127.0.0.1',
            'database': 'test_database',
            'dialect_name': 'bigquery_dialect',
            'username': '******'
        }

        assembled_metadata = entities.AssembledQueryMetadata(
            serialize.deserialize(json.dumps(query_data), models.Query),
            'select *',
            serialize.deserialize(json.dumps(explore_data),
                                  models.LookmlModelExplore),
            serialize.deserialize(json.dumps(connection_data),
                                  models.DBConnection))

        tag = self.__factory.make_tag_for_query(tag_template,
                                                assembled_metadata)

        self.assertEqual(tag_template.name, tag.template)

        self.assertEqual(5, tag.fields['id'].double_value)
        self.assertEqual('field_a, field_b', tag.fields['fields'].string_value)
        self.assertEqual('pivot_a, pivot_b', tag.fields['pivots'].string_value)
        self.assertEqual('sort_a, sort_b', tag.fields['sorts'].string_value)
        self.assertEqual(0.5, tag.fields['runtime'].double_value)
        self.assertEqual('test-client-id',
                         tag.fields['client_id'].string_value)
        self.assertEqual('America/Sao_Paulo',
                         tag.fields['query_timezone'].string_value)
        self.assertEqual('test-model', tag.fields['lookml_model'].string_value)
        self.assertEqual('test-view', tag.fields['explore_name'].string_value)
        self.assertEqual('select *', tag.fields['sql'].string_value)
        self.assertEqual('test-project',
                         tag.fields['lookml_project'].string_value)
        self.assertEqual('test-connection',
                         tag.fields['connection'].string_value)
        self.assertEqual('127.0.0.1', tag.fields['host'].string_value)
        self.assertEqual('test_database', tag.fields['database'].string_value)
        self.assertEqual('bigquery_dialect',
                         tag.fields['connection_dialect'].string_value)
        self.assertEqual('user@database',
                         tag.fields['connection_username'].string_value)

        self.assertEqual('https://test.server.com',
                         tag.fields['instance_url'].string_value)