diff --git a/helpdesk/email.py b/helpdesk/email.py index c753aea5..85dd07d4 100644 --- a/helpdesk/email.py +++ b/helpdesk/email.py @@ -7,6 +7,7 @@ See LICENSE for details. # import base64 + from bs4 import BeautifulSoup from datetime import timedelta from django.conf import settings as django_settings @@ -17,10 +18,11 @@ from django.db.models import Q from django.utils import encoding, timezone from django.utils.translation import gettext as _ import email +from email.message import Message from email.utils import getaddresses from email_reply_parser import EmailReplyParser from helpdesk import settings -from helpdesk.exceptions import IgnoreTicketException, DeleteIgnoredTicketException +from helpdesk.exceptions import DeleteIgnoredTicketException, IgnoreTicketException from helpdesk.lib import process_attachments, safe_template_context from helpdesk.models import FollowUp, IgnoreEmail, Queue, Ticket import imaplib @@ -35,8 +37,7 @@ import ssl import sys from time import ctime import typing -from email.message import Message -from typing import Tuple, List +from typing import List, Tuple # import User model, which may be a custom model diff --git a/helpdesk/tests/test_get_email.py b/helpdesk/tests/test_get_email.py index 14f8398e..a3ae7aee 100644 --- a/helpdesk/tests/test_get_email.py +++ b/helpdesk/tests/test_get_email.py @@ -1,14 +1,18 @@ # -*- coding: utf-8 -*- + from django.contrib.auth.hashers import make_password from django.contrib.auth.models import User +from django.core.files.uploadedfile import SimpleUploadedFile from django.core.management import call_command from django.shortcuts import get_object_or_404 from django.test import override_settings, TestCase import helpdesk.email +from helpdesk.email import extract_part_data, object_from_message +from helpdesk.exceptions import DeleteIgnoredTicketException, IgnoreTicketException from helpdesk.management.commands.get_email import Command -from helpdesk.models import FollowUp, FollowUpAttachment, Queue, Ticket, TicketCC,\ - IgnoreEmail +from helpdesk.models import FollowUp, FollowUpAttachment, IgnoreEmail, Queue, Ticket, TicketCC +from helpdesk.tests import utils import itertools import logging import os @@ -16,12 +20,8 @@ from shutil import rmtree import six import sys from tempfile import mkdtemp -from unittest import mock -from helpdesk.tests import utils -from helpdesk.exceptions import DeleteIgnoredTicketException, IgnoreTicketException -from helpdesk.email import object_from_message, extract_part_data -from django.core.files.uploadedfile import SimpleUploadedFile import typing +from unittest import mock THIS_DIR = os.path.dirname(os.path.abspath(__file__)) diff --git a/helpdesk/tests/utils.py b/helpdesk/tests/utils.py index 38ddcd53..00b7e6a5 100644 --- a/helpdesk/tests/utils.py +++ b/helpdesk/tests/utils.py @@ -1,23 +1,24 @@ """UItility functions facilitate making unit testing easier and less brittle.""" + +from PIL import Image import email -import factory -import faker -import random -import re -import string -import typing -import unicodedata from email import encoders from email.message import Message from email.mime.base import MIMEBase from email.mime.image import MIMEImage +from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText +import factory +import faker from io import BytesIO from numpy.random import randint -from PIL import Image -from typing import Tuple, Any, Optional -from email.mime.multipart import MIMEMultipart +import random +import re +import string +import typing +from typing import Any, Optional, Tuple +import unicodedata def strip_accents(text):