Skip to content

Commit

Permalink
Fixes in preparation for 1.5.0 release (#87)
Browse files Browse the repository at this point in the history
* Fixes in preparation for 1.5.0 release

* Address flake8 warnings
  • Loading branch information
rflprr authored Dec 15, 2017
1 parent f708773 commit d75a5ae
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion datadotworld/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)
from datadotworld.datadotworld import DataDotWorld, UriParam # noqa: F401

__version__ = '1.4.3'
__version__ = '1.5.0'

# Convenience top-level functions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def url(self, url):
raise ValueError("Invalid value for `url`, length must be less than or equal to `4096`")
if url is not None and len(url) < 1:
raise ValueError("Invalid value for `url`, length must be greater than or equal to `1`")
if url is not None and not re.search('^https?.*', url):
if url is not None and not re.search('^(https?|stream).*', url):
raise ValueError("Invalid value for `url`, must be a follow pattern or equal to `/^https?.*/`")

self._url = url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def url(self, url):
raise ValueError("Invalid value for `url`, length must be less than or equal to `4096`")
if url is not None and len(url) < 1:
raise ValueError("Invalid value for `url`, length must be greater than or equal to `1`")
if url is not None and not re.search('^https?.*', url):
if url is not None and not re.search('^(https?|stream).*', url):
raise ValueError("Invalid value for `url`, must be a follow pattern or equal to `/^https?.*/`")

self._url = url
Expand Down
15 changes: 10 additions & 5 deletions datadotworld/client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import functools

import requests
import six

from datadotworld.client import _swagger
from datadotworld.client.content_negotiating_api_client import (
Expand Down Expand Up @@ -197,7 +198,8 @@ def update_dataset(self, dataset_key, **kwargs):
name=name,
source=_swagger.FileSourceCreateOrUpdateRequest(
url=url,
expand_archive=expand_archive),
expand_archive=expand_archive)
if url is not None else None,
description=description,
labels=labels),
kwargs)
Expand Down Expand Up @@ -614,7 +616,7 @@ def sql(self, dataset_key, query, desired_mimetype='application/json',
:type include_table_schema: bool
:returns: file object that can be used in file parsers and
data handling modules.
:rtype: file object
:rtype: file-like object
:raises RestApiException: If a server error occurs
Examples
Expand All @@ -628,7 +630,9 @@ def sql(self, dataset_key, query, desired_mimetype='application/json',
sql_api = kwargs.get('sql_api_mock', _swagger.SqlApi(api_client))
owner_id, dataset_id = parse_dataset_key(dataset_key)
try:
return sql_api.sql_post(owner_id, dataset_id, query, **kwargs)
response = sql_api.sql_post(
owner_id, dataset_id, query, _preload_content=False, **kwargs)
return six.BytesIO(response.data)
except _swagger.rest.ApiException as e:
raise RestApiError(cause=e)

Expand Down Expand Up @@ -660,8 +664,9 @@ def sparql(self, dataset_key, query,
_swagger.SparqlApi(api_client))
owner_id, dataset_id = parse_dataset_key(dataset_key)
try:
return sparql_api.sparql_post(owner_id, dataset_id, query,
**kwargs)
response = sparql_api.sparql_post(
owner_id, dataset_id, query, _preload_content=False, **kwargs)
return six.BytesIO(response.data)
except _swagger.rest.ApiException as e:
raise RestApiError(cause=e)

Expand Down
33 changes: 18 additions & 15 deletions tests/datadotworld/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import pytest
import responses
from doublex import assert_that, Spy, called
from doublex import assert_that, Spy, called, Mock
from hamcrest import (equal_to, has_entries, has_properties, is_, described_as,
empty, raises, calling, has_key)

Expand Down Expand Up @@ -61,7 +61,6 @@ def datasets_api(self):
@pytest.fixture()
def uploads_api(self):
with Spy(UploadsApi) as api:
api.get_dataset = lambda o, d: DatasetSummaryResponse(o, d)
return api

@pytest.fixture()
Expand All @@ -72,15 +71,23 @@ def download_api(self):
return api

@pytest.fixture()
def sql_api(self):
def query_resp(self):
with Mock() as response:
response.data = 'result'.encode()
return response

@pytest.fixture()
def sql_api(self, query_resp):
with Spy(SqlApi) as api:
api.sql_post
api.sql_post = \
lambda o, d, q, sql_api_mock, _preload_content: query_resp
return api

@pytest.fixture()
def sparql_api(self):
def sparql_api(self, query_resp):
with Spy(SparqlApi) as api:
api.sparql_post
api.sparql_post = \
lambda o, d, q, sparql_api_mock, _preload_content: query_resp
return api

@pytest.fixture()
Expand Down Expand Up @@ -272,17 +279,13 @@ def test_download_file(self, api_client, dataset_key, download_api):
'file'))

def test_sql(self, api_client, dataset_key, sql_api):
api_client.sql(dataset_key, 'query', sql_api_mock=sql_api)
assert_that(sql_api.sql_post,
called().times(1).with_args('agentid', 'datasetid',
'query', sql_api_mock=sql_api))
result = api_client.sql(dataset_key, 'query', sql_api_mock=sql_api)
assert_that(result.read().decode('utf-8'), equal_to('result'))

def test_sparql(self, api_client, dataset_key, sparql_api):
api_client.sparql(dataset_key, 'query', sparql_api_mock=sparql_api)
assert_that(sparql_api.sparql_post,
called().times(1).with_args('agentid', 'datasetid',
'query',
sparql_api_mock=sparql_api))
result = api_client.sparql(dataset_key, 'query',
sparql_api_mock=sparql_api)
assert_that(result.read().decode('utf-8'), equal_to('result'))

def test_get_user_data(self, api_client):
user_data_response = api_client.get_user_data()
Expand Down

0 comments on commit d75a5ae

Please sign in to comment.