1#!/usr/bin/env python3 2# 3# Copyright (C) 2018 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); you may not 6# use this file except in compliance with the License. You may obtain a copy of 7# the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14# License for the specific language governing permissions and limitations under 15# the License. 16"""Client object for testing infrastructure to store information in BigQuery""" 17 18from __future__ import absolute_import 19from __future__ import division 20from __future__ import print_function 21 22from acts.controllers.buds_lib.data_storage.bigquery.bigquery_logger_utils import add_row, BigqueryLoggerClient 23 24PROJECT_ID = 'google.com:wearables-qa' 25CREDENTIALS_PATH = '/google/data/ro/teams/wearables/test/automation/bigquery/wearables-service-key.json' 26 27 28class BigqueryLogger: 29 """Bigquery Logger specialized for automated test logging.""" 30 31 def __init__(self, dataset_id, table_id): 32 """Initialization method for BigqueryLogger class.""" 33 # An array of InsertEntry objects to insert into the BigQuery table 34 self.rows = [] 35 self.dataset_id = dataset_id 36 self.table_id = table_id 37 self.utils = BigqueryLoggerClient( 38 project_id=PROJECT_ID, 39 google_application_credentials_path=CREDENTIALS_PATH) 40 41 def __enter__(self): 42 return self 43 44 def __exit__(self, exc_type, exc_value, traceback): 45 self.utils.flush(self.rows, self.dataset_id, self.table_id) 46 47 def clear(self): 48 """Clear data structures""" 49 self.rows = [] 50 51 def get_rows(self): 52 """Getter method for self.rows().""" 53 return self.rows 54 55 def add_row(self, row_dict): 56 print('Adding row...') 57 return add_row(row_dict, self.rows) 58