def test_db_to_email(self): # Empty/Invalid content self.assertEqual(db_to_email(""), None) self.assertEqual(db_to_email(None), None) # Other objects which should be returned as-is data = "Hello Email" self.assertEqual(db_to_email(email_to_db(data)), data) data = [ "Test subject", "Test body", "*****@*****.**", ["*****@*****.**"] ] self.assertEqual(db_to_email(email_to_db(data)), data) email = mail.EmailMessage(*data) converted_email = db_to_email(email_to_db(email)) self.assertEqual(converted_email.body, email.body) self.assertEqual(converted_email.subject, email.subject) self.assertEqual(converted_email.from_email, email.from_email) self.assertEqual(converted_email.to, email.to) # Test old pickle in DB format db_email = pickle.dumps(email) converted_email = db_to_email(db_email) self.assertEqual(converted_email.body, email.body) self.assertEqual(converted_email.subject, email.subject) self.assertEqual(converted_email.from_email, email.from_email) self.assertEqual(converted_email.to, email.to)
def test_db_to_email(self): # Empty/Invalid content self.assertEqual(db_to_email(""), None) self.assertEqual(db_to_email(None), None) # Other objects which should be returned as-is data = "Hello Email" self.assertEqual(db_to_email(email_to_db(data)), data) data = ["Test subject", "Test body", "*****@*****.**", ["*****@*****.**"]] self.assertEqual(db_to_email(email_to_db(data)), data) email = mail.EmailMessage(*data) converted_email = db_to_email(email_to_db(email)) self.assertEqual(converted_email.body, email.body) self.assertEqual(converted_email.subject, email.subject) self.assertEqual(converted_email.from_email, email.from_email) self.assertEqual(converted_email.to, email.to) # Test old pickle in DB format db_email = pickle.dumps(email) converted_email = db_to_email(db_email) self.assertEqual(converted_email.body, email.body) self.assertEqual(converted_email.subject, email.subject) self.assertEqual(converted_email.from_email, email.from_email) self.assertEqual(converted_email.to, email.to)