Skip to content

Commit

Permalink
Duplicate branch name tests. (#66)
Browse files Browse the repository at this point in the history
* additional unit test

* bump to next release version
  • Loading branch information
philkra authored Mar 17, 2023
1 parent abf4f3b commit ca0207e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "xata"
version = "0.7.0"
version = "0.8.0"
description = "Python client for Xata.io"
authors = ["Xata <[email protected]>"]
license = "Apache-2.0"
Expand Down
8 changes: 8 additions & 0 deletions tests/unit-tests/client_internals_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def test_get_and_set_db_branch_name(self):
assert client.get_db_branch_name("foo") == f"foo:{branch_name}"
assert client.get_db_branch_name("foo", "bar") == "foo:bar"

def test_get_db_branch_name_with_db_url(self):
db_url = "https://py-sdk-unit-test-12345.eu-west-1.xata.sh/db/testopia-042:main"
client = XataClient(api_key="api_key", db_url=db_url)

assert "testopia-042" == client.get_config()["dbName"]
assert "main" == client.get_config()["branchName"]
assert "testopia-042:main" == client.get_db_branch_name()

def test_get_config(self):
api_key = "api_key-abc"
ws_id = "ws-idddddd"
Expand Down
6 changes: 3 additions & 3 deletions xata/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

# TODO this is a manual task, to keep in sync with pyproject.toml
# could/should be automated to keep in sync
__version__ = "0.7.0"
__version__ = "0.8.0"

PERSONAL_API_KEY_LOCATION = "~/.config/xata/key"
DEFAULT_DATA_PLANE_DOMAIN = "xata.sh"
Expand Down Expand Up @@ -309,14 +309,14 @@ def _parse_database_url(self, databaseURL: str) -> tuple[str, str, str, str, str
(_, _, host, _, db_branch_name) = databaseURL.split("/")
if host == "" or db_branch_name == "":
raise Exception(
"Invalid database URL: '%s', format: 'https://{workspace_id}.{region}.xata.sh/db/{db_name}' expected."
"Invalid database URL: '%s', format: 'https://{workspace_id}.{region}.xata.sh/db/{db_name}:{branch_name}' expected."
% databaseURL
)
# split host {workspace_id}.{region}
host_parts = host.split(".")
if len(host_parts) < 4:
raise Exception(
"Invalid format for workspaceId and region in the URL: '%s', expected: 'https://{workspace_id}.{region}.xata.sh/db/{db_name}'"
"Invalid format for workspaceId and region in the URL: '%s', expected: 'https://{workspace_id}.{region}.xata.sh/db/{db_name}:{branch_name}'"
% databaseURL
)
# build domain name
Expand Down

0 comments on commit ca0207e

Please sign in to comment.