summaryrefslogtreecommitdiffstats
path: root/kittystore/test
diff options
context:
space:
mode:
Diffstat (limited to 'kittystore/test')
-rw-r--r--kittystore/test/__init__.py8
-rw-r--r--kittystore/test/test_sa_store.py28
-rw-r--r--kittystore/test/test_utils.py19
-rw-r--r--kittystore/test/testdata/non-ascii-payload.txt8
-rw-r--r--kittystore/test/testdata/strange-in-reply-to-header.txt10
5 files changed, 73 insertions, 0 deletions
diff --git a/kittystore/test/__init__.py b/kittystore/test/__init__.py
new file mode 100644
index 0000000..9a10e1f
--- /dev/null
+++ b/kittystore/test/__init__.py
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+import os
+
+
+def get_test_file(*fileparts):
+ return os.path.join(os.path.dirname(__file__), "testdata", *fileparts)
+get_test_file.__test__ = False
diff --git a/kittystore/test/test_sa_store.py b/kittystore/test/test_sa_store.py
new file mode 100644
index 0000000..01a1a4a
--- /dev/null
+++ b/kittystore/test/test_sa_store.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+
+import unittest
+import email
+from mock import Mock
+
+from kittystore.sa import KittySAStore
+from sqlalchemy.exc import ProgrammingError
+from kittystore.test import get_test_file
+
+class TestSAStore(unittest.TestCase):
+
+ def setUp(self):
+ self.store = KittySAStore("sqlite:///:memory:")
+
+ def tearDown(self):
+ self.store.session.close()
+
+ def test_non_ascii_payload(self):
+ """add_to_list must handle non-ascii messages"""
+ with open(get_test_file("non-ascii-payload.txt")) as email_file:
+ msg = email.message_from_file(email_file)
+ self.store.add_to_list("example-list", msg)
+ try:
+ self.store.session.flush()
+ except ProgrammingError, e:
+ self.fail(e)
+
diff --git a/kittystore/test/test_utils.py b/kittystore/test/test_utils.py
new file mode 100644
index 0000000..c4ceec4
--- /dev/null
+++ b/kittystore/test/test_utils.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+
+import unittest
+import email
+from mock import Mock
+
+import kittystore.utils
+from kittystore.test import get_test_file
+
+class TestUtils(unittest.TestCase):
+
+ def test_ref_parsing(self):
+ with open(get_test_file("strange-in-reply-to-header.txt")) as email_file:
+ msg = email.message_from_file(email_file)
+ store = Mock()
+ store.get_message_by_id_from_list.return_value = None
+ ref_id, thread_id = kittystore.utils.get_ref_and_thread_id(
+ msg, "example-list", store)
+ self.assertEqual(ref_id, "200704070053.46646.other.person@example.com")
diff --git a/kittystore/test/testdata/non-ascii-payload.txt b/kittystore/test/testdata/non-ascii-payload.txt
new file mode 100644
index 0000000..d8106eb
--- /dev/null
+++ b/kittystore/test/testdata/non-ascii-payload.txt
@@ -0,0 +1,8 @@
+From test at example.com Fri Apr 6 22:43:55 2007
+From: test at example.com (Dummy Person)
+Date: Fri, 6 Apr 2007 15:43:55 -0700 (PDT)
+Subject: Dummy subject
+Message-ID: <20070406224355.899B9180064@test.example.com>
+
+This message contains non-ascii characters:
+é è ç à î ï ë €
diff --git a/kittystore/test/testdata/strange-in-reply-to-header.txt b/kittystore/test/testdata/strange-in-reply-to-header.txt
new file mode 100644
index 0000000..ead532b
--- /dev/null
+++ b/kittystore/test/testdata/strange-in-reply-to-header.txt
@@ -0,0 +1,10 @@
+From test at example.com Fri Apr 6 22:43:55 2007
+From: test at example.com (Dummy Person)
+Date: Fri, 6 Apr 2007 15:43:55 -0700 (PDT)
+Subject: Dummy subject
+In-Reply-To: Other person's message of Saturday, 7 April 2007 00:53:46 +0300 <200704070053.46646.other.person@example.com>
+Message-ID: <20070406224355.899B9180064@test.example.com>
+
+> Other person's message
+
+Dummy person's reply