This repository has been archived by the owner on Dec 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmail_test.py
81 lines (68 loc) · 2.98 KB
/
mail_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""Unit tests for testing mail receiving, parsing, etc."""
import unittest
from google.appengine.api import mail as google_mail_api
import mail
# Mapping of test email filenames to the expected google doc ids that should
# be pulled out of 'em.
#
# These sequences of email threads are taken from real KA project submissions
# so we can test situations like somebody submitting a project, then people
# replying about it, then somebody resubmitting it in the same thread, etc etc.
TEST_EMAILS = {
"thread_1.1.txt": [
"1JYZ9EGMspPV1bcjgTaG2PH_m8Imzh8eKyAUzD6eq62g"
],
"thread_2.1.txt": [
"1ZKcH46_jHP47RnVXl_YLUSqS9pL7JdnQCxqfscUN9vI"
],
"thread_2.2.txt": [],
"thread_2.3.txt": [],
"thread_3.1.txt": [
"1ZLB3xnP_Pz6UKgc9D8eHGFPJacmQeK-546FR6kghMPc"],
"thread_3.2.txt": [],
"thread_4.1.txt": [
"1RN4UvHSHk5k2EC_YgZq6ceWH3iL9Xqyv5vBKfjDMdjI"],
"thread_5.1.txt": [
"1uTXNmnCxQjVp-6_YcqeSNMg388vvWvZNqyrhPzdLnQE",
"1KyteGUXXJ8LSuDL1yql6olxxWaAvnQTaenMlLW6PndE",
"1udt0iKNhL9USgJHyisCTANKazZ1k7JvtYY-TGttPdyw"
],
"thread_6.1.txt": [
"1aQfqmuXP6z2Hj3cYwAoCetXledZQRAfTlAJqjA0hl7A",
"1o-LhqDSfkC-LQwHlBl-p3bDqM-tpfLkLmJnqhX2adW8"
],
"thread_6.2.txt": [],
"thread_6.3.txt": [
"1vx9ceBL9MlUJP6aRFW81wdpiqlGewR-kLHVbXhJgu3s"
],
"thread_7.1.txt": [
"1YqKBNjWt70uSwD8DO1peWN-qsmuLyacQfPle-XS4edo",
"1YqKBNjWt70uSwD8DO1peWN-qsmuLyacQfPle-XS4ed1"
],
}
class MailHandlerTest(unittest.TestCase):
def _assertGoogleDocIdExtraction(self, filename, expected_google_doc_ids):
email_raw = None
f = open("test_emails/%s" % filename, "r")
with f:
email_raw = f.read()
inbound_msg = google_mail_api.InboundEmailMessage(email_raw)
google_doc_ids = (
mail.NewProjectsMailHandler.google_doc_ids_from_message(
inbound_msg))
self.assertEquals(sorted(expected_google_doc_ids),
sorted(google_doc_ids))
def test_extracting_all_google_doc_ids(self):
"""Test extracting google ids from all example email threads.
These threads (found in test_emails/*.txt) are taken from example
conversations sent to [email protected], w/ all sorts of
replies and quoted text and links to google docs at various positions
and the like.
"""
for filename, expected_google_doc_ids in TEST_EMAILS.iteritems():
self._assertGoogleDocIdExtraction(filename,
expected_google_doc_ids)
def test_extracting_single_google_doc(self):
"""Test extracting google ids from a single example email thread."""
filename = "thread_6.1.txt"
self._assertGoogleDocIdExtraction(filename, TEST_EMAILS[filename])