# Path: mail/models.py
# def id2uri(id):
# def uri2id(uri):
# def save_email(subject, text_body, html_body, sequence, audience, tags):
# def update_email(uri, subject, text_body, html_body, sequence, audience, tags):
# def mark_sent(uri):
# def delete_email(uri):
# def _2json(email_db):
# def get_email(uri):
# def get_emails():
# def schedule_email(uri, scheduled_datetime):


from django.test import TestCase
from mail import models as mail_model
import datetime
    def test_update_email(self):
        email = mail_model.save_email(*self.EMAIL_PARAMS)
        mail_model.update_email(email['uri'], 'New sub', 'New Text', '', 2, 'individuals', 'tag1')
        email2 = mail_model.get_email(email['uri'])
        self.assertNotEqual(email, email2)
        self.assertEqual(email2['subject'], 'New sub')
        self.assertEqual(email2['text_body'], 'New Text')
        self.assertEqual(email2['html_body'], '')
        self.assertEqual(email2['sequence'], 2)
        self.assertEqual(email2['audience'], 'individuals')
        self.assertEqual(email2['tags'], 'tag1')


    def test_mark_sent(self):
        email = mail_model.save_email(*self.EMAIL_PARAMS)
        mail_model.mark_sent(email['uri'])
        email2 = mail_model.get_email(email['uri'])
        self.assertIn('date_sent', email2.keys())


    def test_delete_email(self):
        email = mail_model.save_email(*self.EMAIL_PARAMS)
        email = mail_model.save_email(*self.EMAIL_PARAMS)
        mail_model.delete_email(email['uri'])
        with self.assertRaises(Exception):
            email2 = mail_model.get_email(email['uri'])


    def test_schedule_email(self):
        email = mail_model.save_email(*self.EMAIL_PARAMS)

# Path: mail/models.py
# def id2uri(id):
# def uri2id(uri):
# def save_email(subject, text_body, html_body, sequence, audience, tags):
# def update_email(uri, subject, text_body, html_body, sequence, audience, tags):
# def mark_sent(uri):
# def delete_email(uri):
# def _2json(email_db):
# def get_email(uri):
# def get_emails():
# def schedule_email(uri, scheduled_datetime):


# Path: mail/tests/test_model.py
from django.test import TestCase
from mail import models as mail_model
import datetime

    def test_update_email(self):
        email = mail_model.save_email(*self.EMAIL_PARAMS)
        mail_model.update_email(email['uri'], 'New sub', 'New Text', '', 2, 'individuals', 'tag1')
        email2 = mail_model.get_email(email['uri'])
        self.assertNotEqual(email, email2)
        self.assertEqual(email2['subject'], 'New sub')
        self.assertEqual(email2['text_body'], 'New Text')
        self.assertEqual(email2['html_body'], '')
        self.assertEqual(email2['sequence'], 2)
        self.assertEqual(email2['audience'], 'individuals')
        self.assertEqual(email2['tags'], 'tag1')


    def test_mark_sent(self):
        email = mail_model.save_email(*self.EMAIL_PARAMS)
        mail_model.mark_sent(email['uri'])
        email2 = mail_model.get_email(email['uri'])
        self.assertIn('date_sent', email2.keys())


    def test_delete_email(self):
        email = mail_model.save_email(*self.EMAIL_PARAMS)
        email = mail_model.save_email(*self.EMAIL_PARAMS)
        mail_model.delete_email(email['uri'])
        with self.assertRaises(Exception):
            email2 = mail_model.get_email(email['uri'])


    def test_schedule_email(self):
        email = mail_model.save_email(*self.EMAIL_PARAMS)

        mail_model.schedule_email(email['uri'], datetime.datetime.utcnow())