Skip to content
Permalink
Browse files
feat: add helper methods to parse resource paths (via synth) (#7)
  • Loading branch information
yoshi-automation committed May 27, 2020
1 parent c724e7d commit 8fc54cb70be698f6d265f60d7b8ee4561d12d2c9
Showing with 84 additions and 84 deletions.
  1. +34 −34 google/cloud/bigquery/reservation_v1/services/reservation_service/client.py
  2. +1 −1 synth.metadata
  3. +49 −49 tests/unit/reservation_v1/test_reservation_service.py
@@ -147,72 +147,72 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
from_service_account_json = from_service_account_file

@staticmethod
def assignment_path(
project: str, location: str, reservation: str, assignment: str
def capacity_commitment_path(
project: str, location: str, capacity_commitment: str
) -> str:
"""Return a fully-qualified assignment string."""
return "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}".format(
project=project,
location=location,
reservation=reservation,
assignment=assignment,
"""Return a fully-qualified capacity_commitment string."""
return "projects/{project}/locations/{location}/capacityCommitments/{capacity_commitment}".format(
project=project, location=location, capacity_commitment=capacity_commitment
)

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

@staticmethod
def reservation_path(project: str, location: str, reservation: str) -> str:
"""Return a fully-qualified reservation string."""
return "projects/{project}/locations/{location}/reservations/{reservation}".format(
project=project, location=location, reservation=reservation
def bi_reservation_path(project: str, location: str) -> str:
"""Return a fully-qualified bi_reservation string."""
return "projects/{project}/locations/{location}/bireservation".format(
project=project, location=location
)

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

@staticmethod
def capacity_commitment_path(
project: str, location: str, capacity_commitment: str
) -> str:
"""Return a fully-qualified capacity_commitment string."""
return "projects/{project}/locations/{location}/capacityCommitments/{capacity_commitment}".format(
project=project, location=location, capacity_commitment=capacity_commitment
def reservation_path(project: str, location: str, reservation: str) -> str:
"""Return a fully-qualified reservation string."""
return "projects/{project}/locations/{location}/reservations/{reservation}".format(
project=project, location=location, reservation=reservation
)

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

@staticmethod
def bi_reservation_path(project: str, location: str) -> str:
"""Return a fully-qualified bi_reservation string."""
return "projects/{project}/locations/{location}/bireservation".format(
project=project, location=location
def assignment_path(
project: str, location: str, reservation: str, assignment: str
) -> str:
"""Return a fully-qualified assignment string."""
return "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}".format(
project=project,
location=location,
reservation=reservation,
assignment=assignment,
)

@staticmethod
def parse_bi_reservation_path(path: str) -> Dict[str, str]:
"""Parse a bi_reservation path into its component segments."""
def parse_assignment_path(path: str) -> Dict[str, str]:
"""Parse a assignment path into its component segments."""
m = re.match(
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/bireservation$",
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/reservations/(?P<reservation>.+?)/assignments/(?P<assignment>.+?)$",
path,
)
return m.groupdict() if m else {}
@@ -4,7 +4,7 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/python-bigquery-reservation.git",
"sha": "46176500f8911a3559db8f757502aa05018ea7f7"
"sha": "c724e7db67ea1efd73b7ab0d097475187d9f5cc8"
}
},
{
@@ -2083,101 +2083,101 @@ def test_reservation_service_grpc_transport_channel_mtls_with_adc(
assert transport.grpc_channel == mock_grpc_channel


def test_assignment_path():
def test_capacity_commitment_path():
project = "squid"
location = "clam"
reservation = "whelk"
assignment = "octopus"
capacity_commitment = "whelk"

expected = "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}".format(
project=project,
location=location,
reservation=reservation,
assignment=assignment,
expected = "projects/{project}/locations/{location}/capacityCommitments/{capacity_commitment}".format(
project=project, location=location, capacity_commitment=capacity_commitment
)
actual = ReservationServiceClient.assignment_path(
project, location, reservation, assignment
actual = ReservationServiceClient.capacity_commitment_path(
project, location, capacity_commitment
)
assert expected == actual


def test_parse_assignment_path():
def test_parse_capacity_commitment_path():
expected = {
"project": "oyster",
"location": "nudibranch",
"reservation": "cuttlefish",
"assignment": "mussel",
"project": "octopus",
"location": "oyster",
"capacity_commitment": "nudibranch",
}
path = ReservationServiceClient.assignment_path(**expected)
path = ReservationServiceClient.capacity_commitment_path(**expected)

# Check that the path construction is reversible.
actual = ReservationServiceClient.parse_assignment_path(path)
actual = ReservationServiceClient.parse_capacity_commitment_path(path)
assert expected == actual


def test_reservation_path():
def test_bi_reservation_path():
project = "squid"
location = "clam"
reservation = "whelk"

expected = "projects/{project}/locations/{location}/reservations/{reservation}".format(
project=project, location=location, reservation=reservation
expected = "projects/{project}/locations/{location}/bireservation".format(
project=project, location=location
)
actual = ReservationServiceClient.reservation_path(project, location, reservation)
actual = ReservationServiceClient.bi_reservation_path(project, location)
assert expected == actual


def test_parse_reservation_path():
expected = {"project": "octopus", "location": "oyster", "reservation": "nudibranch"}
path = ReservationServiceClient.reservation_path(**expected)
def test_parse_bi_reservation_path():
expected = {"project": "whelk", "location": "octopus"}
path = ReservationServiceClient.bi_reservation_path(**expected)

# Check that the path construction is reversible.
actual = ReservationServiceClient.parse_reservation_path(path)
actual = ReservationServiceClient.parse_bi_reservation_path(path)
assert expected == actual


def test_capacity_commitment_path():
def test_reservation_path():
project = "squid"
location = "clam"
capacity_commitment = "whelk"
reservation = "whelk"

expected = "projects/{project}/locations/{location}/capacityCommitments/{capacity_commitment}".format(
project=project, location=location, capacity_commitment=capacity_commitment
)
actual = ReservationServiceClient.capacity_commitment_path(
project, location, capacity_commitment
expected = "projects/{project}/locations/{location}/reservations/{reservation}".format(
project=project, location=location, reservation=reservation
)
actual = ReservationServiceClient.reservation_path(project, location, reservation)
assert expected == actual


def test_parse_capacity_commitment_path():
expected = {
"project": "octopus",
"location": "oyster",
"capacity_commitment": "nudibranch",
}
path = ReservationServiceClient.capacity_commitment_path(**expected)
def test_parse_reservation_path():
expected = {"project": "octopus", "location": "oyster", "reservation": "nudibranch"}
path = ReservationServiceClient.reservation_path(**expected)

# Check that the path construction is reversible.
actual = ReservationServiceClient.parse_capacity_commitment_path(path)
actual = ReservationServiceClient.parse_reservation_path(path)
assert expected == actual


def test_bi_reservation_path():
def test_assignment_path():
project = "squid"
location = "clam"
reservation = "whelk"
assignment = "octopus"

expected = "projects/{project}/locations/{location}/bireservation".format(
project=project, location=location
expected = "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}".format(
project=project,
location=location,
reservation=reservation,
assignment=assignment,
)
actual = ReservationServiceClient.assignment_path(
project, location, reservation, assignment
)
actual = ReservationServiceClient.bi_reservation_path(project, location)
assert expected == actual


def test_parse_bi_reservation_path():
expected = {"project": "whelk", "location": "octopus"}
path = ReservationServiceClient.bi_reservation_path(**expected)
def test_parse_assignment_path():
expected = {
"project": "oyster",
"location": "nudibranch",
"reservation": "cuttlefish",
"assignment": "mussel",
}
path = ReservationServiceClient.assignment_path(**expected)

# Check that the path construction is reversible.
actual = ReservationServiceClient.parse_bi_reservation_path(path)
actual = ReservationServiceClient.parse_assignment_path(path)
assert expected == actual

0 comments on commit 8fc54cb

Please sign in to comment.