@@ -48,7 +48,7 @@ def _make_one(self, *args, **kwargs):
4848 def test_ctor_defaults (self , mock_auth ):
4949 from google .cloud .bigtable import __version__ as CLIENT_VERSION
5050
51- expected_exporter = BigtableMetricsExporter ("project" )
51+ expected_exporter = BigtableMetricsExporter ()
5252 with mock .patch .object (
5353 GoogleCloudMetricsHandler , "_generate_client_uid"
5454 ) as uid_mock :
@@ -64,7 +64,7 @@ def test_ctor_defaults(self, mock_auth):
6464 def test_ctor_explicit (self , mock_auth ):
6565 expected_version = "my_version"
6666 expected_uid = "my_uid"
67- expected_exporter = BigtableMetricsExporter ("project" )
67+ expected_exporter = BigtableMetricsExporter ()
6868 handler = self ._make_one (
6969 expected_exporter ,
7070 client_uid = expected_uid ,
@@ -133,22 +133,18 @@ def _make_one(self, *args, **kwargs):
133133 def test_ctor_defaults (self ):
134134 from google .cloud .monitoring_v3 import MetricServiceClient
135135
136- expected_project = "custom"
137- instance = self ._make_one (expected_project )
138- assert instance .project_id == expected_project
136+ instance = self ._make_one ()
139137 assert instance .prefix == "bigtable.googleapis.com/internal/client"
140138 assert isinstance (instance .client , MetricServiceClient )
141139
142140 def test_ctor_mocks (self ):
143- expected_project = "custom"
144141 with mock .patch (
145142 "google.cloud.monitoring_v3.MetricServiceClient.__init__" ,
146143 return_value = None ,
147144 ) as mock_client :
148145 args = [mock .Mock (), object ()]
149146 kwargs = {"a" : "b" }
150- instance = self ._make_one (expected_project , * args , ** kwargs )
151- assert instance .project_id == expected_project
147+ instance = self ._make_one (* args , ** kwargs )
152148 assert instance .prefix == "bigtable.googleapis.com/internal/client"
153149 mock_client .assert_called_once_with (* args , ** kwargs )
154150
@@ -161,7 +157,7 @@ def test_ctor_mocks(self):
161157 )
162158 def test__to_point_w_number (self , value , expected_field ):
163159 """Test that NumberDataPoint is converted to a Point correctly."""
164- instance = self ._make_one ("project" )
160+ instance = self ._make_one ()
165161 expected_start_time_nanos = 100
166162 expected_end_time_nanos = 200
167163 dp = NumberDataPoint (
@@ -182,7 +178,7 @@ def test__to_point_w_number(self, value, expected_field):
182178
183179 def test__to_point_w_histogram (self ):
184180 """Test that HistogramDataPoint is converted to a Point correctly."""
185- instance = self ._make_one ("project" )
181+ instance = self ._make_one ()
186182 expected_start_time_nanos = 100
187183 expected_end_time_nanos = 200
188184 expected_count = 10
@@ -220,7 +216,7 @@ def test__to_point_w_histogram(self):
220216
221217 def test__to_point_w_histogram_zero_count (self ):
222218 """Test that HistogramDataPoint with zero count is converted to a Point correctly."""
223- instance = self ._make_one ("project" )
219+ instance = self ._make_one ()
224220 dp = HistogramDataPoint (
225221 attributes = {},
226222 start_time_unix_nano = 100 ,
@@ -252,15 +248,16 @@ def test__batch_write(
252248 self , num_series , batch_size , expected_calls , expected_batch_sizes
253249 ):
254250 """Test that _batch_write splits series into batches correctly."""
255- instance = self ._make_one ("project" )
251+ instance = self ._make_one ()
256252 instance .client = mock .Mock ()
257253 series = [TimeSeries () for _ in range (num_series )]
258- instance ._batch_write (series , max_batch_size = batch_size )
254+ instance ._batch_write ("project" , series , max_batch_size = batch_size )
259255 assert instance .client .create_service_time_series .call_count == expected_calls
260256 for i , call in enumerate (
261257 instance .client .create_service_time_series .call_args_list
262258 ):
263259 call_args , _ = call
260+ assert call_args [0 ].name == "projects/project"
264261 assert len (call_args [0 ].time_series ) == expected_batch_sizes [i ]
265262
266263 def test__batch_write_with_deadline (self ):
@@ -269,12 +266,12 @@ def test__batch_write_with_deadline(self):
269266
270267 from google .api_core import gapic_v1
271268
272- instance = self ._make_one ("project" )
269+ instance = self ._make_one ()
273270 instance .client = mock .Mock ()
274271 series = [TimeSeries () for _ in range (10 )]
275272 # test with deadline
276273 deadline = time .monotonic () + 10
277- instance ._batch_write (series , deadline = deadline )
274+ instance ._batch_write ("project" , series , deadline = deadline )
278275 (
279276 call_args ,
280277 call_kwargs ,
@@ -283,7 +280,7 @@ def test__batch_write_with_deadline(self):
283280 assert 9 < call_kwargs ["timeout" ] < 10
284281 # test without deadline
285282 instance .client .create_service_time_series .reset_mock ()
286- instance ._batch_write (series , deadline = None )
283+ instance ._batch_write ("project" , series , deadline = None )
287284 (
288285 call_args ,
289286 call_kwargs ,
@@ -294,7 +291,7 @@ def test__batch_write_with_deadline(self):
294291 def test_export (self ):
295292 """Test that export correctly converts metrics and calls _batch_write."""
296293 project_id = "project"
297- instance = self ._make_one (project_id )
294+ instance = self ._make_one ()
298295 instance ._batch_write = mock .Mock ()
299296 # create mock metrics data
300297 expected_value = 123
@@ -334,7 +331,8 @@ def test_export(self):
334331 instance ._batch_write .assert_called_once ()
335332 # check the TimeSeries passed to _batch_write
336333 call_args , call_kwargs = instance ._batch_write .call_args_list [0 ]
337- series_list = call_args [0 ]
334+ assert call_args [0 ] == project_id
335+ series_list = call_args [1 ]
338336 assert len (series_list ) == 1
339337 series = series_list [0 ]
340338 assert series .metric .type == f"{ instance .prefix } /operation_latencies"
@@ -352,7 +350,7 @@ def test_export(self):
352350
353351 def test_export_no_attributes (self ):
354352 """Test that export skips data points with no attributes."""
355- instance = self ._make_one ("project" )
353+ instance = self ._make_one ()
356354 instance ._batch_write = mock .Mock ()
357355 data_point = NumberDataPoint (
358356 attributes = {}, start_time_unix_nano = 100 , time_unix_nano = 200 , value = 123
@@ -376,18 +374,17 @@ def test_export_no_attributes(self):
376374 metrics_data = MetricsData (resource_metrics = [resource_metric ])
377375 result = instance .export (metrics_data )
378376 assert result == MetricExportResult .SUCCESS
379- instance ._batch_write .assert_called_once ()
380- series_list = instance ._batch_write .call_args [0 ][0 ]
381- assert len (series_list ) == 0
377+ instance ._batch_write .assert_not_called ()
382378
383379 def test_exception_in_export (self ):
384380 """
385381 make sure exceptions don't raise
386382 """
387- instance = self ._make_one ("project" )
383+ instance = self ._make_one ()
388384 instance ._batch_write = mock .Mock (side_effect = Exception ("test" ))
389385 # create mock metrics data with one valid data point
390386 attributes = {
387+ "resource_project" : "project" ,
391388 "resource_instance" : "instance1" ,
392389 "resource_cluster" : "cluster1" ,
393390 "resource_table" : "table1" ,
0 commit comments