예제 #1
0
 def test_cloud_storage_api_insert_bucket__already_exists_error(self):
     """Test the Cloud Storage Bucket creation for an existing bucket."""
     test_cloud_storage_api = storage.CloudStorageAPI(
         self.config, mock.Mock())
     test_cloud_storage_api._client.create_bucket.side_effect = (
         exceptions.Conflict('This bucket already exists.'))
     with self.assertRaises(storage.AlreadyExistsError):
         test_cloud_storage_api.insert_bucket()
예제 #2
0
  def testMissingTable_Conflict(self):

    mock_client = mock.Mock(spec=tables.bigquery.Client)
    mock_client.insert_rows.side_effect = [exceptions.NotFound('OMG'), []]
    mock_client.get_table.side_effect = exceptions.NotFound('OMG')
    mock_client.create_table.side_effect = exceptions.Conflict('WTF')
    self.Patch(tables.bigquery, 'Client', return_value=mock_client)

    tables._SendToBigQuery(TEST_TABLE, self.row_dict)

    insert_rows_call = mock.call(
        mock.ANY, [self.row_dict], selected_fields=TEST_TABLE.schema,
        row_ids=[self.row_id])

    mock_client.insert_rows.assert_has_calls([insert_rows_call] * 2)
    mock_client.get_dataset.assert_called_once()
    mock_client.create_dataset.assert_not_called()
    mock_client.get_table.assert_called_once()
    mock_client.create_table.assert_called_once()