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

Commit

Permalink
feat: add resource path parse methods (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation committed May 28, 2020
1 parent 3528a72 commit 1b85e6c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
Expand Up @@ -134,37 +134,37 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
from_service_account_json = from_service_account_file

@staticmethod
def game_server_deployment_rollout_path(
def game_server_deployment_path(
project: str, location: str, deployment: str
) -> str:
"""Return a fully-qualified game_server_deployment_rollout string."""
return "projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout".format(
"""Return a fully-qualified game_server_deployment string."""
return "projects/{project}/locations/{location}/gameServerDeployments/{deployment}".format(
project=project, location=location, deployment=deployment
)

@staticmethod
def parse_game_server_deployment_rollout_path(path: str) -> Dict[str, str]:
"""Parse a game_server_deployment_rollout path into its component segments."""
def parse_game_server_deployment_path(path: str) -> Dict[str, str]:
"""Parse a game_server_deployment path into its component segments."""
m = re.match(
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/gameServerDeployments/(?P<deployment>.+?)/rollout$",
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/gameServerDeployments/(?P<deployment>.+?)$",
path,
)
return m.groupdict() if m else {}

@staticmethod
def game_server_deployment_path(
def game_server_deployment_rollout_path(
project: str, location: str, deployment: str
) -> str:
"""Return a fully-qualified game_server_deployment string."""
return "projects/{project}/locations/{location}/gameServerDeployments/{deployment}".format(
"""Return a fully-qualified game_server_deployment_rollout string."""
return "projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout".format(
project=project, location=location, deployment=deployment
)

@staticmethod
def parse_game_server_deployment_path(path: str) -> Dict[str, str]:
"""Parse a game_server_deployment path into its component segments."""
def parse_game_server_deployment_rollout_path(path: str) -> Dict[str, str]:
"""Parse a game_server_deployment_rollout path into its component segments."""
m = re.match(
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/gameServerDeployments/(?P<deployment>.+?)$",
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/gameServerDeployments/(?P<deployment>.+?)/rollout$",
path,
)
return m.groupdict() if m else {}
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Expand Up @@ -138,7 +138,7 @@ def docs(session):
"""Build the docs for this library."""

session.install("-e", ".")
session.install("sphinx<3.0.0", "alabaster", "recommonmark")
session.install("sphinx", "alabaster", "recommonmark")

shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
Expand Down
8 changes: 4 additions & 4 deletions synth.metadata
Expand Up @@ -4,22 +4,22 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/python-game-servers.git",
"sha": "bdadd8e6afa749a776ee9018b5cd64e543c69f53"
"sha": "3528a72c887b51b2dd0484869d028ed8f98c8c79"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "551cf1e6e3addcc63740427c4f9b40dedd3dac27",
"internalRef": "302792195"
"sha": "eafa840ceec23b44a5c21670288107c661252711",
"internalRef": "313488995"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "274dd49554809834287c24b6dd324a85283f1182"
"sha": "71b8a272549c06b5768d00fa48d3ae990e871bec"
}
}
],
Expand Down
32 changes: 16 additions & 16 deletions tests/unit/gaming_v1/test_game_server_deployments_service.py
Expand Up @@ -1108,51 +1108,51 @@ def test_game_server_deployments_service_grpc_lro_client():
assert transport.operations_client is transport.operations_client


def test_game_server_deployment_rollout_path():
def test_game_server_deployment_path():
project = "squid"
location = "clam"
deployment = "whelk"

expected = "projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout".format(
expected = "projects/{project}/locations/{location}/gameServerDeployments/{deployment}".format(
project=project, location=location, deployment=deployment
)
actual = GameServerDeploymentsServiceClient.game_server_deployment_rollout_path(
actual = GameServerDeploymentsServiceClient.game_server_deployment_path(
project, location, deployment
)
assert expected == actual


def test_parse_game_server_deployment_rollout_path():
def test_parse_game_server_deployment_path():
expected = {"project": "octopus", "location": "oyster", "deployment": "nudibranch"}
path = GameServerDeploymentsServiceClient.game_server_deployment_rollout_path(
**expected
)
path = GameServerDeploymentsServiceClient.game_server_deployment_path(**expected)

# Check that the path construction is reversible.
actual = GameServerDeploymentsServiceClient.parse_game_server_deployment_rollout_path(
path
)
actual = GameServerDeploymentsServiceClient.parse_game_server_deployment_path(path)
assert expected == actual


def test_game_server_deployment_path():
def test_game_server_deployment_rollout_path():
project = "squid"
location = "clam"
deployment = "whelk"

expected = "projects/{project}/locations/{location}/gameServerDeployments/{deployment}".format(
expected = "projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout".format(
project=project, location=location, deployment=deployment
)
actual = GameServerDeploymentsServiceClient.game_server_deployment_path(
actual = GameServerDeploymentsServiceClient.game_server_deployment_rollout_path(
project, location, deployment
)
assert expected == actual


def test_parse_game_server_deployment_path():
def test_parse_game_server_deployment_rollout_path():
expected = {"project": "octopus", "location": "oyster", "deployment": "nudibranch"}
path = GameServerDeploymentsServiceClient.game_server_deployment_path(**expected)
path = GameServerDeploymentsServiceClient.game_server_deployment_rollout_path(
**expected
)

# Check that the path construction is reversible.
actual = GameServerDeploymentsServiceClient.parse_game_server_deployment_path(path)
actual = GameServerDeploymentsServiceClient.parse_game_server_deployment_rollout_path(
path
)
assert expected == actual

0 comments on commit 1b85e6c

Please sign in to comment.