Skip to content

Commit

Permalink
fix urlib opener bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Hossein Torabi committed Dec 7, 2019
1 parent ed3944e commit 4c4b4d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 3 additions & 2 deletions superset/tasks/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ def _get_slice_data(schedule):
raise URLError(response.getcode())

# TODO: Move to the csv module
rows = [r.split(b",") for r in response.content.splitlines()]
content = response.read()
rows = [r.split(b",") for r in content.splitlines()]

if schedule.delivery_type == EmailDeliveryType.inline:
data = None
Expand All @@ -281,7 +282,7 @@ def _get_slice_data(schedule):
)

elif schedule.delivery_type == EmailDeliveryType.attachment:
data = {__("%(name)s.csv", name=slc.slice_name): response.content}
data = {__("%(name)s.csv", name=slc.slice_name): content}
body = __(
'<b><a href="%(url)s">Explore in Superset</a></b><p></p>',
name=slc.slice_name,
Expand Down
5 changes: 2 additions & 3 deletions tests/schedules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def test_deliver_slice_csv_attachment(
mock_open.return_value = response
mock_urlopen.return_value = response
mock_urlopen.return_value.getcode.return_value = 200
response.content = self.CSV
response.read.return_value = self.CSV

schedule = (
db.session.query(SliceEmailSchedule)
Expand All @@ -404,8 +404,7 @@ def test_deliver_slice_csv_inline(self, send_email_smtp, mock_open, mock_urlopen
mock_open.return_value = response
mock_urlopen.return_value = response
mock_urlopen.return_value.getcode.return_value = 200
response.content = self.CSV

response.read.return_value = self.CSV
schedule = (
db.session.query(SliceEmailSchedule)
.filter_by(id=self.slice_schedule)
Expand Down

0 comments on commit 4c4b4d3

Please sign in to comment.