Skip to content

Commit

Permalink
Address issues found while testing with tap-salesforce (#11)
Browse files Browse the repository at this point in the history
* Address issues found while testing with tap-salesforce

- Recognize ACTIVE_VERSION messages
- Disable GzipAdapter
- Update dependencies
  • Loading branch information
rflprr authored Dec 29, 2017
1 parent 7a7b84f commit 712e947
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ def find_version(*paths):
],
packages=find_packages(),
install_requires=[
'backoff>=1.4.3,<2.0a',
'backoff>=1.3.0,<2.0a',
'click>=6.7,<7.0a',
'jsonschema>=2.6.0,<3.0a',
'pyjwt>=1.5.3,<2.0a',
'requests>=2.18.4,<3.0a',
'singer-python==2.1.0',
'requests>=2.4.0,<3.0a',
'singer-python>=5.0.4,<6.0a',
],
setup_requires=[
'pytest-runner>=2.11,<3.0a',
Expand Down
2 changes: 1 addition & 1 deletion target_datadotworld/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

import singer

__version__ = '1.0.0b2'
__version__ = '1.0.0b3'

logger = copy(singer.get_logger()) # copy needed in order to set level
10 changes: 7 additions & 3 deletions target_datadotworld/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def __init__(self, api_token, **kwargs):
'User-Agent': 'target-datadotworld - {}'.format(__version__)
}
self._session.headers.update(default_headers)

# TODO Fix and turn GzipAdapter back on (GH Issue #10)
self._session.mount(self._api_url,
BackoffAdapter(GzipAdapter(HTTPAdapter())))
BackoffAdapter(HTTPAdapter()))

# Create a limited thread pool.
self._executor = ThreadPoolExecutor(
Expand Down Expand Up @@ -101,7 +103,8 @@ def append_stream(self, owner, dataset, stream, records):
'{}/streams/{}/{}/{}'.format(
self._api_url, owner, dataset, stream),
data=to_jsonlines(records).encode('utf-8'),
headers={'Content-Type': 'application/json-l'}
headers={'Content-Type':
'application/json-l; charset=utf-8'}
).raise_for_status()
except RequestException as e:
raise convert_requests_exception(e)
Expand Down Expand Up @@ -210,7 +213,8 @@ def create_dataset(self, owner, dataset, **kwargs):
raise convert_requests_exception(e)


class GzipAdapter(BaseAdapter):
# TODO Re-enable test coverage (GH issue #10)
class GzipAdapter(BaseAdapter): # pragma: no cover
def __init__(self, delegate):
"""Requests adapter for compressing request bodies
Expand Down
4 changes: 4 additions & 0 deletions target_datadotworld/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ async def process_lines(self, lines, loop=None):
elif isinstance(msg, singer.StateMessage):
logger.info('State message found: {}'.format(msg.value))
state = msg.value
elif isinstance(msg, singer.ActivateVersionMessage):
logger.info('Version message found: {}/{}'.format(
msg.stream, msg.version))
# TODO Handle Active Version Messages (GH Issue #2)
else:
raise Error('Unrecognized message'.format(msg))

Expand Down
5 changes: 2 additions & 3 deletions tests/target_datadotworld/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# data.world, Inc.(http://data.world/).

import asyncio
import gzip
import time

import pytest
Expand Down Expand Up @@ -48,7 +47,7 @@ def verify_body_and_count(req):
nonlocal call_count, all_records

assert_that(
gzip.decompress(req.body).decode('utf-8'),
req.body.decode('utf-8'),
equal_to(to_jsonlines(all_records)))

call_count += 1
Expand Down Expand Up @@ -83,7 +82,7 @@ def verify_body_and_count(req):
expected_records = all_records[first_record:last_record]

assert_that(
gzip.decompress(req.body).decode('utf-8'),
req.body.decode('utf-8'),
equal_to(to_jsonlines(expected_records)))

call_count += 1
Expand Down

0 comments on commit 712e947

Please sign in to comment.