Skip to content

Commit 7636c80

Browse files
Merge pull request #333 from tillahoffmann/gcp2
Update google-cloud-pubsub to major version 2.
2 parents 2504d21 + 934c8d8 commit 7636c80

File tree

8 files changed

+114
-86
lines changed

8 files changed

+114
-86
lines changed

google/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
url="https://github.com/testcontainers/testcontainers-python",
1313
install_requires=[
1414
"testcontainers-core",
15-
"google-cloud-pubsub < 2",
15+
"google-cloud-pubsub>=2",
1616
],
1717
python_requires=">=3.7",
1818
)

google/testcontainers/google/pubsub.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
# License for the specific language governing permissions and limitations
1212
# under the License.
1313
from google.cloud import pubsub
14-
import grpc
15-
from typing import Optional
14+
import os
1615
from testcontainers.core.container import DockerContainer
16+
from typing import Type
17+
from unittest.mock import patch
1718

1819

1920
class PubSubContainer(DockerContainer):
@@ -49,15 +50,12 @@ def __init__(self, image: str = "google/cloud-sdk:emulators", project: str = "te
4950
def get_pubsub_emulator_host(self) -> str:
5051
return f"{self.get_container_host_ip()}:{self.get_exposed_port(self.port)}"
5152

52-
def _get_channel(self, channel: Optional[grpc.Channel] = None) -> grpc.Channel:
53-
if channel is None:
54-
return grpc.insecure_channel(target=self.get_pubsub_emulator_host())
55-
return channel
53+
def _get_client(self, cls: Type, **kwargs) -> dict:
54+
with patch.dict(os.environ, PUBSUB_EMULATOR_HOST=self.get_pubsub_emulator_host()):
55+
return cls(**kwargs)
5656

5757
def get_publisher_client(self, **kwargs) -> pubsub.PublisherClient:
58-
kwargs['channel'] = self._get_channel(kwargs.get('channel'))
59-
return pubsub.PublisherClient(**kwargs)
58+
return self._get_client(pubsub.PublisherClient, **kwargs)
6059

6160
def get_subscriber_client(self, **kwargs) -> pubsub.SubscriberClient:
62-
kwargs['channel'] = self._get_channel(kwargs.get('channel'))
63-
return pubsub.SubscriberClient(**kwargs)
61+
return self._get_client(pubsub.SubscriberClient, **kwargs)

google/tests/test_google.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44

55

66
def test_pubsub_container():
7+
pubsub: PubSubContainer
78
with PubSubContainer() as pubsub:
8-
wait_for_logs(pubsub, r"Server started, listening on \d+", timeout=10)
9+
wait_for_logs(pubsub, r"Server started, listening on \d+", timeout=60)
910
# Create a new topic
1011
publisher = pubsub.get_publisher_client()
1112
topic_path = publisher.topic_path(pubsub.project, "my-topic")
12-
publisher.create_topic(topic_path)
13+
publisher.create_topic(name=topic_path)
1314

1415
# Create a subscription
1516
subscriber = pubsub.get_subscriber_client()
1617
subscription_path = subscriber.subscription_path(pubsub.project,
1718
"my-subscription")
18-
subscriber.create_subscription(subscription_path, topic_path)
19+
subscriber.create_subscription(name=subscription_path, topic=topic_path)
1920

2021
# Publish a message
2122
publisher.publish(topic_path, b"Hello world!")

requirements/3.10.txt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ charset-normalizer==3.1.0
112112
# via requests
113113
clickhouse-driver==0.2.5
114114
# via testcontainers-clickhouse
115-
# via -r requirements.in
116115
coverage[toml]==7.2.3
117-
# via
118-
# pytest-cov
116+
# via pytest-cov
119117
cryptography==36.0.2
120118
# via
121119
# -r requirements.in
@@ -159,7 +157,7 @@ google-api-core[grpc]==2.11.0
159157
# via google-cloud-pubsub
160158
google-auth==2.17.2
161159
# via google-api-core
162-
google-cloud-pubsub==1.7.2
160+
google-cloud-pubsub==2.16.0
163161
# via testcontainers-gcp
164162
googleapis-common-protos[grpc]==1.59.0
165163
# via
@@ -173,11 +171,14 @@ grpc-google-iam-v1==0.12.6
173171
grpcio==1.53.0
174172
# via
175173
# google-api-core
174+
# google-cloud-pubsub
176175
# googleapis-common-protos
177176
# grpc-google-iam-v1
178177
# grpcio-status
179-
grpcio-status==1.48.2
180-
# via google-api-core
178+
grpcio-status==1.53.0
179+
# via
180+
# google-api-core
181+
# google-cloud-pubsub
181182
h11==0.14.0
182183
# via wsproto
183184
idna==3.4
@@ -226,7 +227,7 @@ opensearch-py==2.2.0
226227
# via testcontainers-opensearch
227228
outcome==1.2.0
228229
# via trio
229-
packaging==23.0
230+
packaging==23.1
230231
# via
231232
# deprecation
232233
# docker
@@ -242,13 +243,16 @@ pkginfo==1.9.6
242243
# via twine
243244
pluggy==1.0.0
244245
# via pytest
245-
protobuf==3.20.3
246+
proto-plus==1.22.2
247+
# via google-cloud-pubsub
248+
protobuf==4.22.1
246249
# via
247250
# google-api-core
248251
# google-cloud-pubsub
249252
# googleapis-common-protos
250253
# grpc-google-iam-v1
251254
# grpcio-status
255+
# proto-plus
252256
psycopg2-binary==2.9.6
253257
# via testcontainers-postgres
254258
pyasn1==0.4.8
@@ -332,7 +336,7 @@ requests-toolbelt==0.10.1
332336
# twine
333337
rfc3986==2.0.0
334338
# via twine
335-
rich==13.3.3
339+
rich==13.3.4
336340
# via twine
337341
rsa==4.9
338342
# via

0 commit comments

Comments
 (0)