Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDL-20481 Update pks in schema of users stream #95

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions tap_jira/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def discover():
def generate_metadata(stream, schema):
mdata = metadata.new()

# Update pk for users stream to key for on prem jira instance
# Update pk for users stream to key for on-prem Jira instance
if stream.tap_stream_id == "users" and Context.client.is_on_prem_instance:
stream.pk_fields = ["key"]

Expand All @@ -79,9 +79,14 @@ def generate_metadata(stream, schema):
return metadata.to_list(mdata)


def output_schema(stream):
schema = load_schema(stream.tap_stream_id)
singer.write_schema(stream.tap_stream_id, schema, stream.pk_fields)
def write_schema(stream_obj):
stream = Context.catalog.get_stream(stream_obj.tap_stream_id)
schema = stream.schema.to_dict()
try:
singer.write_schema(stream_obj.tap_stream_id, schema, stream.key_properties)
except OSError as err:
LOGGER.info('OS Error writing schema for: %s', stream_obj.tap_stream_id)
raise err


def sync():
Expand All @@ -93,7 +98,7 @@ def sync():
# data for the second stream, but the second stream hasn't output its
# schema yet
for stream in streams_.ALL_STREAMS:
output_schema(stream)
write_schema(stream)

for stream in streams_.ALL_STREAMS:
if not Context.is_selected(stream.tap_stream_id):
Expand All @@ -109,7 +114,6 @@ def sync():
Context.state["currently_syncing"] = None
singer.write_state(Context.state)


@singer.utils.handle_top_exception(LOGGER)
def main():
args = get_args()
Expand All @@ -128,7 +132,7 @@ def main():

try:
if args.discover:
discover().dump()
catalog.dump()
print()
else:
sync()
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/test_basic_auth_in_discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def test_basic_auth_no_access_401(self, mocked_discover, mocked_send, mocked_arg
def test_basic_auth_access_200(self, mocked_discover, mocked_send, mocked_args):
'''
Verify discover mode is called if basic auth credentials are valid
and dicover function is called twice for setup Context and dicover mode.
and discover function is called once for setup Context.
'''
mocked_send.return_value = get_mock_http_response(200, {})
mocked_args.return_value = Args()
tap_jira.main()
self.assertEqual(mocked_discover.call_count, 2)
self.assertEqual(mocked_discover.call_count, 1)