[fix] GCalendar Account test (#5400)
* [fix] GCalendar Account test * [py3] fix email account test * Decode plain text files
This commit is contained in:
parent
ef536e055b
commit
da3e726fde
2 changed files with 14 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue