diff --git a/frappe/integrations/doctype/gcalendar_account/test_gcalendar_account.py b/frappe/integrations/doctype/gcalendar_account/test_gcalendar_account.py index 535c9c5467..6ed4a95b12 100644 --- a/frappe/integrations/doctype/gcalendar_account/test_gcalendar_account.py +++ b/frappe/integrations/doctype/gcalendar_account/test_gcalendar_account.py @@ -13,6 +13,7 @@ class TestGCalendarAccount(unittest.TestCase): doc.enabled = 1 doc.user = users[0].name doc.calendar_name = "Frappe Test" + doc.save() self.assertTrue(frappe.db.exists('GCalendar Account', users[0].name)) connector_name = 'Calendar Connector-' + users[0].name diff --git a/frappe/utils/file_manager.py b/frappe/utils/file_manager.py index 17cdc71dd1..5b3ae220a8 100644 --- a/frappe/utils/file_manager.py +++ b/frappe/utils/file_manager.py @@ -6,12 +6,13 @@ import frappe import os, base64, re import hashlib import mimetypes +import io from frappe.utils import get_hook_method, get_files_path, random_string, encode, cstr, call_hook_method, cint from frappe import _ from frappe import conf from copy import copy from six.moves.urllib.parse import unquote -from six import text_type +from six import text_type, PY2 class MaxFileSizeReachedError(frappe.ValidationError): @@ -297,8 +298,17 @@ def get_file(fname): file_path = get_file_path(fname) # read the file - with open(encode(file_path), 'r') as f: - content = f.read() + if PY2: + with open(encode(file_path)) as f: + content = f.read() + else: + with io.open(encode(file_path), mode='rb') as f: + try: + # for plain text files + content = f.read().decode() + except UnicodeDecodeError: + # for .png, .jpg, etc + content = f.read() return [file_path.rsplit("/", 1)[-1], content]