|
15 | 15 | import google.auth |
16 | 16 | import google.auth.credentials |
17 | 17 | import google.auth.transport.grpc |
18 | | -from google.cloud.gapic.pubsub.v1 import publisher_api |
| 18 | +from google.cloud.gapic.pubsub.v1 import publisher_client |
19 | 19 |
|
20 | 20 |
|
21 | | -def test_grpc_request(http_request): |
| 21 | +def test_grpc_request_with_regular_credentials(http_request): |
22 | 22 | credentials, project_id = google.auth.default() |
23 | 23 | credentials = google.auth.credentials.with_scopes_if_required( |
24 | 24 | credentials, ['https://www.googleapis.com/auth/pubsub']) |
25 | 25 |
|
26 | | - target = '{}:{}'.format( |
27 | | - publisher_api.PublisherApi.SERVICE_ADDRESS, |
28 | | - publisher_api.PublisherApi.DEFAULT_SERVICE_PORT) |
| 26 | + channel = google.auth.transport.grpc.secure_authorized_channel( |
| 27 | + credentials, |
| 28 | + http_request, |
| 29 | + publisher_client.PublisherClient.SERVICE_ADDRESS) |
| 30 | + |
| 31 | + # Create a pub/sub client. |
| 32 | + client = publisher_client.PublisherClient(channel=channel) |
| 33 | + |
| 34 | + # list the topics and drain the iterator to test that an authorized API |
| 35 | + # call works. |
| 36 | + list_topics_iter = client.list_topics( |
| 37 | + project='projects/{}'.format(project_id)) |
| 38 | + list(list_topics_iter) |
| 39 | + |
| 40 | + |
| 41 | +def test_grpc_request_with_jwt_credentials(http_request): |
| 42 | + credentials, project_id = google.auth.default() |
| 43 | + credentials = credentials.to_jwt_credentials() |
29 | 44 |
|
30 | 45 | channel = google.auth.transport.grpc.secure_authorized_channel( |
31 | | - credentials, http_request, target) |
| 46 | + credentials, |
| 47 | + http_request, |
| 48 | + publisher_client.PublisherClient.SERVICE_ADDRESS) |
32 | 49 |
|
33 | 50 | # Create a pub/sub client. |
34 | | - client = publisher_api.PublisherApi(channel=channel) |
| 51 | + client = publisher_client.PublisherClient(channel=channel) |
35 | 52 |
|
36 | 53 | # list the topics and drain the iterator to test that an authorized API |
37 | 54 | # call works. |
|
0 commit comments