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-14397-Add skipped log when first row is empty #46

Merged
Merged
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
5 changes: 5 additions & 0 deletions tap_google_sheets/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def get_sheet_schema_columns(sheet):
prior_header = None
i = 0
skipped = 0

# if no headers are present, log the message that sheet is skipped
if not headers:
LOGGER.warn('SKIPPING THE SHEET AS HEADERS ROW IS EMPTY. SHEET: {}'.format(sheet_title))

# Read column headers until end or 2 consecutive skipped headers
for header in headers:
# LOGGER.info('header = {}'.format(json.dumps(header, indent=2, sort_keys=True)))
Expand Down
77 changes: 77 additions & 0 deletions tests/unittests/test_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import unittest
from unittest import mock
import tap_google_sheets
from tap_google_sheets import schema


class TestLogger(unittest.TestCase):
@mock.patch('tap_google_sheets.schema.LOGGER.warn')
def test_logger_message(self, mocked_logger):
"""
Test if the logger statement is printed when the header row is empty and the sheet is being skipped.
"""
sheet_data = {
"properties":{
"sheetId":2074712559,
"title":"Sheet5",
"index":1,
"sheetType":"GRID",
"gridProperties":{
"rowCount":1000,
"columnCount":26
}
},
"data":[
{
"rowData":[
{},
{
"values":[
{
"userEnteredValue":{
"numberValue":1
},
"effectiveValue":{
"numberValue":1
},
"formattedValue":"1",
},
{
"userEnteredValue":{
"numberValue":2
},
"effectiveValue":{
"numberValue":2
},
"formattedValue":"2"
},
{
"userEnteredValue":{
"numberValue":3
},
"effectiveValue":{
"numberValue":3
},
"formattedValue":"3",
}
]
}
],
"rowMetadata":[
{
"pixelSize":21
}
],
"columnMetadata":[
{
"pixelSize":100
}
]
}
]
}
# retrieve the sheet title from the `sheet_data`
sheet_title = sheet_data.get('properties', {}).get('title')
sheet_schema, columns = schema.get_sheet_schema_columns(sheet_data)
# check if the logger is called with correct logger message
mocked_logger.assert_called_with('SKIPPING THE SHEET AS HEADERS ROW IS EMPTY. SHEET: {}'.format(sheet_title))