Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit 8fc54cb

Browse files
feat: add helper methods to parse resource paths (via synth) (#7)
1 parent c724e7d commit 8fc54cb

File tree

3 files changed

+84
-84
lines changed

3 files changed

+84
-84
lines changed

google/cloud/bigquery/reservation_v1/services/reservation_service/client.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -147,72 +147,72 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
147147
from_service_account_json = from_service_account_file
148148

149149
@staticmethod
150-
def assignment_path(
151-
project: str, location: str, reservation: str, assignment: str
150+
def capacity_commitment_path(
151+
project: str, location: str, capacity_commitment: str
152152
) -> str:
153-
"""Return a fully-qualified assignment string."""
154-
return "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}".format(
155-
project=project,
156-
location=location,
157-
reservation=reservation,
158-
assignment=assignment,
153+
"""Return a fully-qualified capacity_commitment string."""
154+
return "projects/{project}/locations/{location}/capacityCommitments/{capacity_commitment}".format(
155+
project=project, location=location, capacity_commitment=capacity_commitment
159156
)
160157

161158
@staticmethod
162-
def parse_assignment_path(path: str) -> Dict[str, str]:
163-
"""Parse a assignment path into its component segments."""
159+
def parse_capacity_commitment_path(path: str) -> Dict[str, str]:
160+
"""Parse a capacity_commitment path into its component segments."""
164161
m = re.match(
165-
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/reservations/(?P<reservation>.+?)/assignments/(?P<assignment>.+?)$",
162+
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/capacityCommitments/(?P<capacity_commitment>.+?)$",
166163
path,
167164
)
168165
return m.groupdict() if m else {}
169166

170167
@staticmethod
171-
def reservation_path(project: str, location: str, reservation: str) -> str:
172-
"""Return a fully-qualified reservation string."""
173-
return "projects/{project}/locations/{location}/reservations/{reservation}".format(
174-
project=project, location=location, reservation=reservation
168+
def bi_reservation_path(project: str, location: str) -> str:
169+
"""Return a fully-qualified bi_reservation string."""
170+
return "projects/{project}/locations/{location}/bireservation".format(
171+
project=project, location=location
175172
)
176173

177174
@staticmethod
178-
def parse_reservation_path(path: str) -> Dict[str, str]:
179-
"""Parse a reservation path into its component segments."""
175+
def parse_bi_reservation_path(path: str) -> Dict[str, str]:
176+
"""Parse a bi_reservation path into its component segments."""
180177
m = re.match(
181-
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/reservations/(?P<reservation>.+?)$",
178+
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/bireservation$",
182179
path,
183180
)
184181
return m.groupdict() if m else {}
185182

186183
@staticmethod
187-
def capacity_commitment_path(
188-
project: str, location: str, capacity_commitment: str
189-
) -> str:
190-
"""Return a fully-qualified capacity_commitment string."""
191-
return "projects/{project}/locations/{location}/capacityCommitments/{capacity_commitment}".format(
192-
project=project, location=location, capacity_commitment=capacity_commitment
184+
def reservation_path(project: str, location: str, reservation: str) -> str:
185+
"""Return a fully-qualified reservation string."""
186+
return "projects/{project}/locations/{location}/reservations/{reservation}".format(
187+
project=project, location=location, reservation=reservation
193188
)
194189

195190
@staticmethod
196-
def parse_capacity_commitment_path(path: str) -> Dict[str, str]:
197-
"""Parse a capacity_commitment path into its component segments."""
191+
def parse_reservation_path(path: str) -> Dict[str, str]:
192+
"""Parse a reservation path into its component segments."""
198193
m = re.match(
199-
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/capacityCommitments/(?P<capacity_commitment>.+?)$",
194+
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/reservations/(?P<reservation>.+?)$",
200195
path,
201196
)
202197
return m.groupdict() if m else {}
203198

204199
@staticmethod
205-
def bi_reservation_path(project: str, location: str) -> str:
206-
"""Return a fully-qualified bi_reservation string."""
207-
return "projects/{project}/locations/{location}/bireservation".format(
208-
project=project, location=location
200+
def assignment_path(
201+
project: str, location: str, reservation: str, assignment: str
202+
) -> str:
203+
"""Return a fully-qualified assignment string."""
204+
return "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}".format(
205+
project=project,
206+
location=location,
207+
reservation=reservation,
208+
assignment=assignment,
209209
)
210210

211211
@staticmethod
212-
def parse_bi_reservation_path(path: str) -> Dict[str, str]:
213-
"""Parse a bi_reservation path into its component segments."""
212+
def parse_assignment_path(path: str) -> Dict[str, str]:
213+
"""Parse a assignment path into its component segments."""
214214
m = re.match(
215-
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/bireservation$",
215+
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/reservations/(?P<reservation>.+?)/assignments/(?P<assignment>.+?)$",
216216
path,
217217
)
218218
return m.groupdict() if m else {}

synth.metadata

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"git": {
55
"name": ".",
66
"remote": "https://github.com/googleapis/python-bigquery-reservation.git",
7-
"sha": "46176500f8911a3559db8f757502aa05018ea7f7"
7+
"sha": "c724e7db67ea1efd73b7ab0d097475187d9f5cc8"
88
}
99
},
1010
{

tests/unit/reservation_v1/test_reservation_service.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,101 +2083,101 @@ def test_reservation_service_grpc_transport_channel_mtls_with_adc(
20832083
assert transport.grpc_channel == mock_grpc_channel
20842084

20852085

2086-
def test_assignment_path():
2086+
def test_capacity_commitment_path():
20872087
project = "squid"
20882088
location = "clam"
2089-
reservation = "whelk"
2090-
assignment = "octopus"
2089+
capacity_commitment = "whelk"
20912090

2092-
expected = "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}".format(
2093-
project=project,
2094-
location=location,
2095-
reservation=reservation,
2096-
assignment=assignment,
2091+
expected = "projects/{project}/locations/{location}/capacityCommitments/{capacity_commitment}".format(
2092+
project=project, location=location, capacity_commitment=capacity_commitment
20972093
)
2098-
actual = ReservationServiceClient.assignment_path(
2099-
project, location, reservation, assignment
2094+
actual = ReservationServiceClient.capacity_commitment_path(
2095+
project, location, capacity_commitment
21002096
)
21012097
assert expected == actual
21022098

21032099

2104-
def test_parse_assignment_path():
2100+
def test_parse_capacity_commitment_path():
21052101
expected = {
2106-
"project": "oyster",
2107-
"location": "nudibranch",
2108-
"reservation": "cuttlefish",
2109-
"assignment": "mussel",
2102+
"project": "octopus",
2103+
"location": "oyster",
2104+
"capacity_commitment": "nudibranch",
21102105
}
2111-
path = ReservationServiceClient.assignment_path(**expected)
2106+
path = ReservationServiceClient.capacity_commitment_path(**expected)
21122107

21132108
# Check that the path construction is reversible.
2114-
actual = ReservationServiceClient.parse_assignment_path(path)
2109+
actual = ReservationServiceClient.parse_capacity_commitment_path(path)
21152110
assert expected == actual
21162111

21172112

2118-
def test_reservation_path():
2113+
def test_bi_reservation_path():
21192114
project = "squid"
21202115
location = "clam"
2121-
reservation = "whelk"
21222116

2123-
expected = "projects/{project}/locations/{location}/reservations/{reservation}".format(
2124-
project=project, location=location, reservation=reservation
2117+
expected = "projects/{project}/locations/{location}/bireservation".format(
2118+
project=project, location=location
21252119
)
2126-
actual = ReservationServiceClient.reservation_path(project, location, reservation)
2120+
actual = ReservationServiceClient.bi_reservation_path(project, location)
21272121
assert expected == actual
21282122

21292123

2130-
def test_parse_reservation_path():
2131-
expected = {"project": "octopus", "location": "oyster", "reservation": "nudibranch"}
2132-
path = ReservationServiceClient.reservation_path(**expected)
2124+
def test_parse_bi_reservation_path():
2125+
expected = {"project": "whelk", "location": "octopus"}
2126+
path = ReservationServiceClient.bi_reservation_path(**expected)
21332127

21342128
# Check that the path construction is reversible.
2135-
actual = ReservationServiceClient.parse_reservation_path(path)
2129+
actual = ReservationServiceClient.parse_bi_reservation_path(path)
21362130
assert expected == actual
21372131

21382132

2139-
def test_capacity_commitment_path():
2133+
def test_reservation_path():
21402134
project = "squid"
21412135
location = "clam"
2142-
capacity_commitment = "whelk"
2136+
reservation = "whelk"
21432137

2144-
expected = "projects/{project}/locations/{location}/capacityCommitments/{capacity_commitment}".format(
2145-
project=project, location=location, capacity_commitment=capacity_commitment
2146-
)
2147-
actual = ReservationServiceClient.capacity_commitment_path(
2148-
project, location, capacity_commitment
2138+
expected = "projects/{project}/locations/{location}/reservations/{reservation}".format(
2139+
project=project, location=location, reservation=reservation
21492140
)
2141+
actual = ReservationServiceClient.reservation_path(project, location, reservation)
21502142
assert expected == actual
21512143

21522144

2153-
def test_parse_capacity_commitment_path():
2154-
expected = {
2155-
"project": "octopus",
2156-
"location": "oyster",
2157-
"capacity_commitment": "nudibranch",
2158-
}
2159-
path = ReservationServiceClient.capacity_commitment_path(**expected)
2145+
def test_parse_reservation_path():
2146+
expected = {"project": "octopus", "location": "oyster", "reservation": "nudibranch"}
2147+
path = ReservationServiceClient.reservation_path(**expected)
21602148

21612149
# Check that the path construction is reversible.
2162-
actual = ReservationServiceClient.parse_capacity_commitment_path(path)
2150+
actual = ReservationServiceClient.parse_reservation_path(path)
21632151
assert expected == actual
21642152

21652153

2166-
def test_bi_reservation_path():
2154+
def test_assignment_path():
21672155
project = "squid"
21682156
location = "clam"
2157+
reservation = "whelk"
2158+
assignment = "octopus"
21692159

2170-
expected = "projects/{project}/locations/{location}/bireservation".format(
2171-
project=project, location=location
2160+
expected = "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}".format(
2161+
project=project,
2162+
location=location,
2163+
reservation=reservation,
2164+
assignment=assignment,
2165+
)
2166+
actual = ReservationServiceClient.assignment_path(
2167+
project, location, reservation, assignment
21722168
)
2173-
actual = ReservationServiceClient.bi_reservation_path(project, location)
21742169
assert expected == actual
21752170

21762171

2177-
def test_parse_bi_reservation_path():
2178-
expected = {"project": "whelk", "location": "octopus"}
2179-
path = ReservationServiceClient.bi_reservation_path(**expected)
2172+
def test_parse_assignment_path():
2173+
expected = {
2174+
"project": "oyster",
2175+
"location": "nudibranch",
2176+
"reservation": "cuttlefish",
2177+
"assignment": "mussel",
2178+
}
2179+
path = ReservationServiceClient.assignment_path(**expected)
21802180

21812181
# Check that the path construction is reversible.
2182-
actual = ReservationServiceClient.parse_bi_reservation_path(path)
2182+
actual = ReservationServiceClient.parse_assignment_path(path)
21832183
assert expected == actual

0 commit comments

Comments
 (0)