Skip to content

Commit

Permalink
Merge dd752cc into 0018882
Browse files Browse the repository at this point in the history
  • Loading branch information
chezou committed Sep 24, 2019
2 parents 0018882 + dd752cc commit bf5ad1b
Show file tree
Hide file tree
Showing 24 changed files with 33 additions and 345 deletions.
12 changes: 2 additions & 10 deletions tdclient/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def as_bytes(s, encoding):

def raise_error(self, msg, res, body):
status_code = res.status
s = body.decode("utf-8")
s = body if isinstance(body, str) else body.decode("utf-8")
if status_code == 404:
raise errors.NotFoundError("%s: %s" % (msg, s))
elif status_code == 409:
Expand Down Expand Up @@ -666,19 +666,11 @@ def _read_json_file(self, file_like, **kwargs):
def _read_csv_file(
self, file_like, dialect=csv.excel, columns=None, encoding="utf-8", **kwargs
):
try:
unicode
py2k = True
except NameError:
py2k = False
# `csv` module bundled with py2k doesn't support `unicode` :(
# https://docs.python.org/2/library/csv.html#examples
def getreader(file_like):
for s in codecs.getreader(encoding)(file_like):
yield s.encode(encoding) if py2k else s
yield s

def value(s):
s = s.decode(encoding) if py2k else s
try:
return int(s)
except (OverflowError, ValueError):
Expand Down
15 changes: 1 addition & 14 deletions tdclient/bulk_import_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,6 @@ def bulk_import_error_records(self, name, params=None):
body = io.BytesIO(res.read())
decompressor = gzip.GzipFile(fileobj=body)

content_type = res.getheader(
"content-type", "application/x-msgpack; charset=utf-8"
)
type_params = dict(
[
p.strip().split("=", 2)
for p in content_type.split(";")
if 0 < p.find("=")
]
)

unpacker = msgpack.Unpacker(
decompressor, encoding=str(type_params.get("charset", "utf-8"))
)
unpacker = msgpack.Unpacker(decompressor, raw=False)
for row in unpacker:
yield row
83 changes: 0 additions & 83 deletions tdclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,6 @@ def create_log_table(self, db_name, table_name):
"""
return self.api.create_log_table(db_name, table_name)

def create_item_table(self, db_name, table_name, primary_key, primary_key_type):
"""
Args:
db_name (str): name of a database
table_name (str): name of a table to create
primary_key (str): name of primary key column
primary_key_type (str): type of primary key column
Returns: `True` if success
"""
warnings.warn(
"item tables have been deprecated. will be deleted from future releases.",
category=DeprecationWarning,
)
return self.api.create_item_table(
db_name, table_name, primary_key, primary_key_type
)

def swap_table(self, db_name, table_name1, table_name2):
"""
Args:
Expand Down Expand Up @@ -842,17 +824,6 @@ def remove_user(self, name):
"""
return self.api.remove_user(name)

def change_email(self, name, email):
"""
TODO: remove
Args:
name (str): name of the user
email (str) new e-mail address
Returns: `True` if success
"""
return self.api.change_email(name, email)

def list_apikeys(self, name):
"""
Args:
Expand Down Expand Up @@ -881,60 +852,6 @@ def remove_apikey(self, name, apikey):
"""
return self.api.remove_apikey(name, apikey)

def change_password(self, name, password):
"""
Args:
name (str): name of the user
password (str): new password
Returns: `True` if success
"""
return self.api.change_password(name, password)

def change_my_password(self, old_password, password):
"""
TODO: remove
Args:
old_password (str): old password
password (str): new password
Returns: `True` if success
"""
return self.api.change_my_password(old_password, password)

def access_controls(self):
"""
Returns: a list of :class:`tdclient.models.AccessControl`
"""
results = self.api.list_access_controls()

def access_control(m):
subject, action, scope, grant_option = m
return models.AccessControl(self, subject, action, scope, grant_option)

return [access_control(m) for m in results]

def grant_access_control(self, subject, action, scope, grant_option):
"""
TODO: remove
=> True
"""
return self.api.grant_access_control(subject, action, scope, grant_option)

def revoke_access_control(self, subject, action, scope):
"""
TODO: remove
=> True
"""
return self.api.revoke_access_control(subject, action, scope)

def test_access_control(self, user, action, scope):
"""
TODO: remove
=> True
"""
return self.api.test_access_control(user, action, scope)

def close(self):
"""Close opened API connections.
"""
Expand Down
13 changes: 0 additions & 13 deletions tdclient/database_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@ def create_log_table(self, name):
"""
return self._client.create_log_table(self._db_name, name)

def create_item_table(self, name):
"""
Args:
name (str): name of new item table
Returns: :class:`tdclient.model.Table`
"""
warnings.warn(
"item tables have been deprecated. will be deleted from future releases.",
category=DeprecationWarning,
)
return self._client.create_item_table(self._db_name, name)

def table(self, table_name):
"""
Args:
Expand Down
2 changes: 1 addition & 1 deletion tdclient/job_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def job_result_format_each(self, job_id, format):
if code != 200:
self.raise_error("Get job result failed", res, "")
if format == "msgpack":
unpacker = msgpack.Unpacker(res, encoding=str("utf-8"))
unpacker = msgpack.Unpacker(res, raw=False)
for row in unpacker:
yield row
elif format == "json":
Expand Down
12 changes: 0 additions & 12 deletions tdclient/table_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ def create_log_table(self, db, table):
"""
return self._create_table(db, table, "log")

def create_item_table(self, db, table, primary_key, primary_key_type):
"""[Deprecated] Create a new table for item.
=> True
"""
warnings.warn(
"item tables have been deprecated. will be deleted from future releases.",
category=DeprecationWarning,
)
params = {"primary_key": primary_key, "primary_key_type": primary_key_type}
return self._create_table(db, table, "item", params)

def _create_table(self, db, table, type, params=None):
params = {} if params is None else params
with self.post(
Expand Down
73 changes: 2 additions & 71 deletions tdclient/test/client_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python

try:
from unittest import mock
except ImportError:
import mock
from unittest import mock

import pytest

from tdclient import api, client
Expand Down Expand Up @@ -105,16 +103,6 @@ def test_create_log_table():
td.api.create_log_table.assert_called_with("db_name", "table_name")


def test_create_item_table():
td = client.Client("APIKEY")
td._api = mock.MagicMock()
td._api.create_item_table = mock.MagicMock()
td.create_item_table("db_name", "table_name", "primary_key", "primary_key_type")
td.api.create_item_table.assert_called_with(
"db_name", "table_name", "primary_key", "primary_key_type"
)


def test_swap_table():
td = client.Client("APIKEY")
td._api = mock.MagicMock()
Expand Down Expand Up @@ -576,14 +564,6 @@ def test_remove_user():
td.api.remove_user("name")


def test_change_email():
td = client.Client("APIKEY")
td._api = mock.MagicMock()
td._api.change_email = mock.MagicMock()
td.change_email("user", "email")
td.api.change_email("user", "email")


def test_list_apikeys():
td = client.Client("APIKEY")
td._api = mock.MagicMock()
Expand All @@ -606,52 +586,3 @@ def test_remove_apikey():
td._api.remove_apikey = mock.MagicMock()
td.remove_apikey("user", "apikey")
td.api.remove_apikey("user", "apikey")


def test_change_password():
td = client.Client("APIKEY")
td._api = mock.MagicMock()
td._api.change_password = mock.MagicMock()
td.change_password("user", "password")
td.api.change_password("user", "password")


def test_change_my_password():
td = client.Client("APIKEY")
td._api = mock.MagicMock()
td._api.change_my_password = mock.MagicMock()
td.change_my_password("old_password", "password")
td.api.change_my_password("old_password", "password")


def test_access_controls():
td = client.Client("APIKEY")
td._api = mock.MagicMock()
td._api.list_access_controls = mock.MagicMock(return_value=[])
access_controls = td.access_controls()
td.api.list_access_controls.assert_called_with()
assert len(access_controls) == 0


def test_grant_access_control():
td = client.Client("APIKEY")
td._api = mock.MagicMock()
td._api.grant_access_control = mock.MagicMock()
td.grant_access_control("subject", "action", "scope", "grant_option")
td.api.grant_access_control("subject", "action", "scope", "grant_option")


def test_revoke_access_control():
td = client.Client("APIKEY")
td._api = mock.MagicMock()
td._api.revoke_access_control = mock.MagicMock()
td.revoke_access_control("subject", "action", "scope")
td.api.revoke_access_control("subject", "action", "scope")


def test_test_access_control():
td = client.Client("APIKEY")
td._api = mock.MagicMock()
td._api.test_access_control = mock.MagicMock()
td.test_access_control("subject", "action", "scope")
td.api.test_access_control("subject", "action", "scope")
6 changes: 2 additions & 4 deletions tdclient/test/connection_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python

try:
from unittest import mock
except ImportError:
import mock
from unittest import mock

import pytest

from tdclient import connection, cursor, errors
Expand Down
6 changes: 2 additions & 4 deletions tdclient/test/cursor_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python

try:
from unittest import mock
except ImportError:
import mock
from unittest import mock

import pytest

from tdclient import cursor, errors
Expand Down
6 changes: 2 additions & 4 deletions tdclient/test/database_api_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python

try:
from unittest import mock
except ImportError:
import mock
from unittest import mock

import pytest

from tdclient import api
Expand Down
6 changes: 2 additions & 4 deletions tdclient/test/export_api_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python

try:
from unittest import mock
except ImportError:
import mock
from unittest import mock

import pytest

from tdclient import api
Expand Down
6 changes: 2 additions & 4 deletions tdclient/test/partial_delete_api_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python

try:
from unittest import mock
except ImportError:
import mock
from unittest import mock

import pytest

from tdclient import api
Expand Down
5 changes: 1 addition & 4 deletions tdclient/test/pseudo_certifi_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env python

try:
from unittest import mock
except ImportError:
import mock
import functools
from unittest import mock

from tdclient import pseudo_certifi as certifi

Expand Down
6 changes: 2 additions & 4 deletions tdclient/test/result_api_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python

try:
from unittest import mock
except ImportError:
import mock
from unittest import mock

import pytest

from tdclient import api
Expand Down
5 changes: 1 addition & 4 deletions tdclient/test/result_model_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/usr/bin/env python

try:
from unittest import mock
except ImportError:
import mock
from unittest import mock

from tdclient import models
from tdclient.test.test_helper import *
Expand Down

0 comments on commit bf5ad1b

Please sign in to comment.