-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splitting the integration tests files (#25)
* first part of splitting the integration tests * isolated tests for search and filter namespace * parts moved of to namespaced endpoints * bump to next version * add new db branch name method with tests * teardown and setup for search_and_filter * stub more namespaces * more tests for table namespace * complete integration tests for table namespace * completed databases namespace * add authentication namespace * users namespace * add workspaces namespace * add partially branch tests * linter improvements * add faker dependency and update deps * added one more tests for records * add records tests * codegen bugfix for duplicate params * add tests for records namespace
- Loading branch information
Showing
19 changed files
with
1,654 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "xata" | ||
version = "0.2.1" | ||
version = "0.3.0" | ||
description = "Python client for Xata.io" | ||
authors = ["Xata <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
@@ -24,6 +24,7 @@ flake8-bugbear = "^22.10.27" | |
flake8-annotations = "^2.9.1" | ||
Mako = "1.2.4" | ||
pdoc3 = "^0.10.0" | ||
Faker = "^17.0.0" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# | ||
# Licensed to Xatabase, Inc under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Xatabase, Inc licenses this file to you under the | ||
# Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You | ||
# may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
import utils | ||
|
||
from xata.client import XataClient | ||
|
||
|
||
class TestClass(object): | ||
@classmethod | ||
def setup_class(self): | ||
self.db_name = utils.get_db_name() | ||
self.branch_name = "main" | ||
self.new_api_key = "one-key-to-rule-them-all-%s" % utils.get_random_string(6) | ||
self.client = XataClient(db_name=self.db_name, branch_name=self.branch_name) | ||
|
||
def test_get_user_api_keys(self): | ||
r = self.client.authentication().getUserAPIKeys() | ||
assert r.status_code == 200 | ||
assert "keys" in r.json() | ||
assert len(r.json()["keys"]) > 0 | ||
assert "name" in r.json()["keys"][0] | ||
assert "createdAt" in r.json()["keys"][0] | ||
|
||
def test_create_user_api_keys(self): | ||
r = self.client.authentication().getUserAPIKeys() | ||
assert r.status_code == 200 | ||
count = len(r.json()["keys"]) | ||
|
||
r = self.client.authentication().createUserAPIKey(self.new_api_key) | ||
assert r.status_code == 201 | ||
assert "name" in r.json() | ||
assert "key" in r.json() | ||
assert "createdAt" in r.json() | ||
assert self.new_api_key == r.json()["name"] | ||
|
||
r = self.client.authentication().getUserAPIKeys() | ||
assert len(r.json()["keys"]) == (count + 1) | ||
|
||
r = self.client.authentication().createUserAPIKey(self.new_api_key) | ||
assert r.status_code == 409 | ||
|
||
r = self.client.authentication().createUserAPIKey("") | ||
assert r.status_code == 404 | ||
|
||
def test_delete_user_api_key(self): | ||
r = self.client.authentication().deleteUserAPIKey(self.new_api_key) | ||
assert r.status_code == 204 | ||
|
||
r = self.client.authentication().deleteUserAPIKey("NonExistingApiKey") | ||
assert r.status_code == 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# | ||
# Licensed to Xatabase, Inc under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Xatabase, Inc licenses this file to you under the | ||
# Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You | ||
# may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
import utils | ||
|
||
from xata.client import XataClient | ||
|
||
|
||
class TestClass(object): | ||
@classmethod | ||
def setup_class(self): | ||
self.db_name = utils.get_db_name() | ||
self.branch_name = "main" | ||
self.client = XataClient(db_name=self.db_name, branch_name=self.branch_name) | ||
|
||
# create database | ||
r = self.client.databases().createDatabase( | ||
self.client.get_config()["workspaceId"], | ||
self.db_name, | ||
{ | ||
"region": self.client.get_config()["region"], | ||
"branchName": self.client.get_config()["branchName"], | ||
}, | ||
) | ||
assert r.status_code == 201 | ||
|
||
# create table posts | ||
r = self.client.table().createTable(self.client.get_db_branch_name(), "Posts") | ||
assert r.status_code == 201 | ||
|
||
# create schema | ||
r = self.client.table().setTableSchema( | ||
self.client.get_db_branch_name(), | ||
"Posts", | ||
{ | ||
"columns": [ | ||
{"name": "title", "type": "string"}, | ||
{"name": "labels", "type": "multiple"}, | ||
{"name": "slug", "type": "string"}, | ||
{"name": "text", "type": "text"}, | ||
] | ||
}, | ||
) | ||
assert r.status_code == 200 | ||
|
||
@classmethod | ||
def teardown_class(self): | ||
r = self.client.databases().deleteDatabase( | ||
self.client.get_config()["workspaceId"], self.db_name | ||
) | ||
assert r.status_code == 200 | ||
|
||
def test_get_branch_list(self): | ||
r = self.client.branch().getBranchList(self.db_name) | ||
assert r.status_code == 200 | ||
assert "databaseName" in r.json() | ||
assert "branches" in r.json() | ||
assert r.json()["databaseName"] == self.db_name | ||
assert len(r.json()["branches"]) == 1 | ||
assert "name" in r.json()["branches"][0] | ||
assert "createdAt" in r.json()["branches"][0] | ||
assert r.json()["branches"][0]["name"] == "main" | ||
|
||
r = self.client.branch().getBranchList("NonExistingDatabase") | ||
assert r.status_code == 404 | ||
|
||
def test_get_branch_details(self): | ||
r = self.client.branch().getBranchDetails(self.client.get_db_branch_name()) | ||
assert r.status_code == 200 | ||
assert "databaseName" in r.json() | ||
assert "branchName" in r.json() | ||
assert "metadata" in r.json() | ||
assert "schema" in r.json() | ||
assert r.json()["databaseName"] == self.client.get_config()["dbName"] | ||
# TODO be exhastive testing the ^ dict keys | ||
|
||
r = self.client.branch().getBranchDetails("NonExistingDatabase") | ||
assert r.status_code == 400 | ||
|
||
def test_create_database_branch(self): | ||
payload = { | ||
"from": "main", | ||
"metadata": { | ||
"repository": "github.com/xataio/xata-py", | ||
"branch": "integration-testing-%s" % utils.get_random_string(6), | ||
"stage": "testing", | ||
}, | ||
} | ||
""" | ||
r = self.client.branch().createBranch(self.client.get_db_branch_name(), payload) | ||
assert r.json() == "" | ||
assert r.status_code == 201 | ||
assert "databaseName" in r.json() | ||
assert "branchName" in r.json() | ||
assert "status" in r.json() | ||
assert r.json()["databaseName"] == self.client.get_config()["dbName"] | ||
assert r.json()["branchName"] == payload["metadata"]["branch"] | ||
assert r.json()["status"] == "completed" | ||
pytest.branch["branch"] = payload | ||
r = self.client.branch().createBranch(self.client.get_db_branch_name(), payload) | ||
assert r.status_code == 422 | ||
""" | ||
r = self.client.branch().createBranch("NonExistingDbBranchName", payload) | ||
assert r.status_code == 400 | ||
|
||
r = self.client.branch().createBranch(self.client.get_db_branch_name(), {}) | ||
assert r.status_code == 422 | ||
|
||
def test_get_branch_metadata(self): | ||
r = self.client.branch().getBranchMetadata(self.client.get_db_branch_name()) | ||
assert r.status_code == 200 | ||
|
||
# TODO test from a previously created branch | ||
# assert "repository" in r.json() | ||
# assert "branch" in r.json() | ||
# assert "stage" in r.json() | ||
|
||
r = self.client.branch().getBranchMetadata("NonExistingDbBranchName") | ||
assert r.status_code == 400 | ||
|
||
def test_get_branch_stats(self): | ||
r = self.client.branch().getBranchStats(self.client.get_db_branch_name()) | ||
assert r.status_code == 200 | ||
assert "timestamp" in r.json() | ||
assert "interval" in r.json() | ||
# TODO test more ^ dict keys | ||
|
||
r = self.client.branch().getBranchStats("NonExistingDbBranchName") | ||
assert r.status_code == 400 |
Oops, something went wrong.