mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-06-20 17:47:58 +02:00
Merge pull request #747 from auto-mat/fix-tests
Fix tests and encoding problems
This commit is contained in:
commit
46520e9e5b
@ -471,9 +471,12 @@ def object_from_message(message, queue, logger):
|
|||||||
|
|
||||||
if part.get_content_maintype() == 'text' and name is None:
|
if part.get_content_maintype() == 'text' and name is None:
|
||||||
if part.get_content_subtype() == 'plain':
|
if part.get_content_subtype() == 'plain':
|
||||||
body = EmailReplyParser.parse_reply(
|
body = part.get_payload(decode=True)
|
||||||
decodeUnknown(part.get_content_charset(), part.get_payload(decode=True))
|
# https://github.com/django-helpdesk/django-helpdesk/issues/732
|
||||||
)
|
if part['Content-Transfer-Encoding'] == '8bit' and part.get_content_charset() == 'utf-8':
|
||||||
|
body = body.decode('unicode_escape')
|
||||||
|
body = decodeUnknown(part.get_content_charset(), body)
|
||||||
|
body = EmailReplyParser.parse_reply(body)
|
||||||
# workaround to get unicode text out rather than escaped text
|
# workaround to get unicode text out rather than escaped text
|
||||||
try:
|
try:
|
||||||
body = body.encode('ascii').decode('unicode_escape')
|
body = body.encode('ascii').decode('unicode_escape')
|
||||||
@ -481,9 +484,15 @@ def object_from_message(message, queue, logger):
|
|||||||
body.encode('utf-8')
|
body.encode('utf-8')
|
||||||
logger.debug("Discovered plain text MIME part")
|
logger.debug("Discovered plain text MIME part")
|
||||||
else:
|
else:
|
||||||
payload = encoding.smart_bytes(part.get_payload(decode=True))
|
payload = """
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
</head>
|
||||||
|
%s
|
||||||
|
</html>""" % encoding.smart_text(part.get_payload(decode=True))
|
||||||
files.append(
|
files.append(
|
||||||
SimpleUploadedFile(_("email_html_body.html"), payload, 'text/html')
|
SimpleUploadedFile(_("email_html_body.html"), payload.encode("utf-8"), 'text/html')
|
||||||
)
|
)
|
||||||
logger.debug("Discovered HTML MIME part")
|
logger.debug("Discovered HTML MIME part")
|
||||||
else:
|
else:
|
||||||
|
@ -53,7 +53,7 @@ class GetEmailCommonTests(TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, "test_files/blank-body-with-attachment.eml")) as fd:
|
with open(os.path.join(THIS_DIR, "test_files/blank-body-with-attachment.eml")) as fd:
|
||||||
test_email = fd.read()
|
test_email = fd.read()
|
||||||
ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger)
|
ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger)
|
||||||
self.assertEqual(ticket.title, "FollowUpAttachment without body")
|
self.assertEqual(ticket.title, "Attachment without body")
|
||||||
self.assertEqual(ticket.description, "")
|
self.assertEqual(ticket.description, "")
|
||||||
|
|
||||||
def test_email_with_quoted_printable_body(self):
|
def test_email_with_quoted_printable_body(self):
|
||||||
@ -71,7 +71,7 @@ class GetEmailCommonTests(TestCase):
|
|||||||
attachments = FollowUpAttachment.objects.filter(followup=followup)
|
attachments = FollowUpAttachment.objects.filter(followup=followup)
|
||||||
self.assertEqual(len(attachments), 1)
|
self.assertEqual(len(attachments), 1)
|
||||||
attachment = attachments[0]
|
attachment = attachments[0]
|
||||||
self.assertEqual(attachment.file.read().decode("utf-8"), '<div dir="ltr">Tohle je test českých písmen odeslaných z gmailu.</div>\n')
|
self.assertIn('<div dir="ltr">Tohle je test českých písmen odeslaných z gmailu.</div>\n', attachment.file.read().decode("utf-8"))
|
||||||
|
|
||||||
def test_email_with_8bit_encoding_and_utf_8(self):
|
def test_email_with_8bit_encoding_and_utf_8(self):
|
||||||
"""
|
"""
|
||||||
|
19
quicktest.py
19
quicktest.py
@ -27,7 +27,8 @@ class QuickDjangoTest(object):
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.sites',
|
'django.contrib.sites',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'bootstrap4form'
|
'bootstrap4form',
|
||||||
|
'helpdesk',
|
||||||
)
|
)
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
@ -62,7 +63,7 @@ class QuickDjangoTest(object):
|
|||||||
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.apps = args
|
self.tests = args
|
||||||
self._tests()
|
self._tests()
|
||||||
|
|
||||||
def _tests(self):
|
def _tests(self):
|
||||||
@ -79,7 +80,7 @@ class QuickDjangoTest(object):
|
|||||||
'PORT': '',
|
'PORT': '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
INSTALLED_APPS=self.INSTALLED_APPS + self.apps,
|
INSTALLED_APPS=self.INSTALLED_APPS,
|
||||||
MIDDLEWARE=self.MIDDLEWARE,
|
MIDDLEWARE=self.MIDDLEWARE,
|
||||||
ROOT_URLCONF='helpdesk.tests.urls',
|
ROOT_URLCONF='helpdesk.tests.urls',
|
||||||
STATIC_URL='/static/',
|
STATIC_URL='/static/',
|
||||||
@ -92,7 +93,7 @@ class QuickDjangoTest(object):
|
|||||||
test_runner = DiscoverRunner(verbosity=1)
|
test_runner = DiscoverRunner(verbosity=1)
|
||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
failures = test_runner.run_tests(self.apps)
|
failures = test_runner.run_tests(self.tests)
|
||||||
if failures:
|
if failures:
|
||||||
sys.exit(failures)
|
sys.exit(failures)
|
||||||
|
|
||||||
@ -102,13 +103,15 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
|
|
||||||
$ python quicktest.py app1 app2
|
$ python quicktest.py test1 test2
|
||||||
|
|
||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
usage="[args]",
|
usage="[args]",
|
||||||
description="Run Django tests on the provided applications."
|
description="Run Django tests."
|
||||||
)
|
)
|
||||||
parser.add_argument('apps', nargs='+', type=str)
|
parser.add_argument('tests', nargs="*", type=str)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
QuickDjangoTest(*args.apps)
|
if not args.tests:
|
||||||
|
args.tests = ['helpdesk']
|
||||||
|
QuickDjangoTest(*args.tests)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user