def test_prevent_expiring_table_created_when_expiring_count_is_positive(self): request_body = _build_request_body_for_start( delete_count=0, expiring_count=_DUMMY_EXPIRING_COUNT, upsert_count=0) prevent_expiring_query = bigquery_client.generate_query_string( main._QUERY_FILEPATH_FOR_PREVENT_EXPIRING, main._PROJECT_ID) self.test_app_client.post(_START_PATH, json=request_body) self.bigquery_client.return_value.initialize_dataset_and_table.assert_any_call( prevent_expiring_query)
def setUp(self): super(BigQueryClientTest, self).setUp() self.dataset_reference = dataset.DatasetReference( PROJECT_ID, DATASET_ID) self.table_reference = table.TableReference(self.dataset_reference, TABLE_ID) self.dummy_query = bigquery_client.generate_query_string( DUMMY_QUERY_FILEPATH, PROJECT_ID)
def test_generate_query_string(self): expected_generated_query = """/** A dummy query used in unittests. */ SELECT {}; """.format(PROJECT_ID) self.assertEqual( expected_generated_query, bigquery_client.generate_query_string(DUMMY_QUERY_FILEPATH, PROJECT_ID))
def test_delete_table_not_created_when_delete_count_is_not_positive(self): request_body = _build_request_body_for_start( delete_count=0, expiring_count=0, upsert_count=_DUMMY_UPSERT_COUNT) self.test_app_client.post(_START_PATH, json=request_body) delete_query = bigquery_client.generate_query_string( main._QUERY_FILEPATH_FOR_DELETE, main._PROJECT_ID) self.assert_not_called_with( self.bigquery_client.return_value.initialize_dataset_and_table, delete_query)
def _create_processing_table(table_suffix: str, query_filepath: str, timestamp: str) -> None: """Creates a processing table to allow uploader to load items from it. Args: table_suffix: name of the BigQuery table suffix. query_filepath: filepath to a query file. timestamp: timestamp to identify the run. """ try: query = bigquery_client.generate_query_string(query_filepath, _PROJECT_ID) except IOError as io_error: logging.exception(io_error.message) else: table_id = f'process_items_to_{table_suffix}_{timestamp}' bq_client = bigquery_client.BigQueryClient.from_service_account_json( _SERVICE_ACCOUNT, _DATASET_ID_PROCESSING_FEED_DATA, table_id) bq_client.initialize_dataset_and_table(query)
def test_generate_query_string_with_non_existing_file(self): with self.assertRaises(IOError): bigquery_client.generate_query_string('wrong_filepath', PROJECT_ID)