Files
edx-platform/lms/djangoapps/instructor/tests/utils.py
njdup 5791fd1087 Instructors can view previously sent email content
Previously on the send email page of the instructor dashboard, instructors could only view
task information about emails they've sent for their course in the past.
In addition to this, I've now added the ability to see the content of all previously sent emails.

A "Sent Email History" button has been added to the page. When clicked, a table displaying the
subject line, number of emails sent, and date/time of submission for each previously sent email
is created. An instructor can then click on any subject line to see the content of that email,
displayed in a modal window that appears on the page.

The window is also equipped with a "copy email to editor" button, which copies the emails contents
to the tinyMCE editor, so that an instructor can easily resend an email that they've sent
in the past.
2014-08-04 10:08:32 -07:00

85 lines
2.4 KiB
Python

"""
Utilities for instructor unit tests
"""
import datetime
import json
import random
from django.utils.timezone import utc
from util.date_utils import get_default_time_display
class FakeInfo(object):
"""Parent class for faking objects used in tests"""
FEATURES = []
def __init__(self):
for feature in self.FEATURES:
setattr(self, feature, u'expected')
def to_dict(self):
""" Returns a dict representation of the object """
return {key: getattr(self, key) for key in self.FEATURES}
class FakeContentTask(FakeInfo):
""" Fake task info needed for email content list """
FEATURES = [
'task_input',
'task_output',
]
def __init__(self, email_id, num_sent, sent_to):
super(FakeContentTask, self).__init__()
self.task_input = {'email_id': email_id, 'to_option': sent_to}
self.task_input = json.dumps(self.task_input)
self.task_output = {'total': num_sent}
self.task_output = json.dumps(self.task_output)
def make_invalid_input(self):
"""Corrupt the task input field to test errors"""
self.task_input = "THIS IS INVALID JSON"
class FakeEmail(FakeInfo):
""" Corresponding fake email for a fake task """
FEATURES = [
'subject',
'html_message',
'id',
'created',
]
def __init__(self, email_id):
super(FakeEmail, self).__init__()
self.id = unicode(email_id)
# Select a random data for create field
year = random.choice(range(1950, 2000))
month = random.choice(range(1, 12))
day = random.choice(range(1, 28))
hour = random.choice(range(0, 23))
minute = random.choice(range(0, 59))
self.created = datetime.datetime(year, month, day, hour, minute, tzinfo=utc)
class FakeEmailInfo(FakeInfo):
""" Fake email information object """
FEATURES = [
u'created',
u'sent_to',
u'email',
u'number_sent'
]
EMAIL_FEATURES = [
u'subject',
u'html_message',
u'id'
]
def __init__(self, fake_email, num_sent):
super(FakeEmailInfo, self).__init__()
self.created = get_default_time_display(fake_email.created)
self.number_sent = num_sent
fake_email_dict = fake_email.to_dict()
self.email = {feature: fake_email_dict[feature] for feature in self.EMAIL_FEATURES}