summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-03-05 12:46:24 +0100
committerAnton Khirnov <anton@khirnov.net>2020-03-05 13:51:48 +0100
commite2efd81f0dc4f913c73a2494091f67c748001942 (patch)
tree01b13bd2bdc6aa444c86d60c7091f3149266d9eb /tests
parentc5a951d8ed69741c43302a8ed8ca8d1b388cb17f (diff)
Update tests.
Drop some tests for removed functions.
Diffstat (limited to 'tests')
-rw-r--r--tests/db/test_manager.py38
-rw-r--r--tests/db/test_utils.py207
2 files changed, 36 insertions, 209 deletions
diff --git a/tests/db/test_manager.py b/tests/db/test_manager.py
index e675aed4..02df63d9 100644
--- a/tests/db/test_manager.py
+++ b/tests/db/test_manager.py
@@ -9,12 +9,46 @@ import textwrap
import os
import shutil
-from alot.db.manager import DBManager
+import unittest
+from unittest import mock
+
+from alot.db import manager
from alot.settings.const import settings
from notmuch import Database
from .. import utilities
+class TestIsSubdirOf(unittest.TestCase):
+
+ def test_both_paths_absolute_matching(self):
+ superpath = '/a/b'
+ subpath = '/a/b/c/d.rst'
+ result = manager._is_subdir_of(subpath, superpath)
+ self.assertTrue(result)
+
+ def test_both_paths_absolute_not_matching(self):
+ superpath = '/a/z'
+ subpath = '/a/b/c/d.rst'
+ result = manager._is_subdir_of(subpath, superpath)
+ self.assertFalse(result)
+
+ def test_both_paths_relative_matching(self):
+ superpath = 'a/b'
+ subpath = 'a/b/c/d.rst'
+ result = manager._is_subdir_of(subpath, superpath)
+ self.assertTrue(result)
+
+ def test_both_paths_relative_not_matching(self):
+ superpath = 'a/z'
+ subpath = 'a/b/c/d.rst'
+ result = manager._is_subdir_of(subpath, superpath)
+ self.assertFalse(result)
+
+ def test_relative_path_and_absolute_path_matching(self):
+ superpath = 'a/b'
+ subpath = os.path.join(os.getcwd(), 'a/b/c/d.rst')
+ result = manager._is_subdir_of(subpath, superpath)
+ self.assertTrue(result)
class TestDBManager(utilities.TestCaseClassCleanup):
@@ -34,7 +68,7 @@ class TestDBManager(utilities.TestCaseClassCleanup):
cls.dbpath = tempfile.mkdtemp()
cls.db = Database(path=cls.dbpath, create=True)
cls.db.close()
- cls.manager = DBManager(cls.dbpath)
+ cls.manager = manager.DBManager(cls.dbpath)
# clean up temporary database
cls.addClassCleanup(cls.manager.kill_search_processes)
diff --git a/tests/db/test_utils.py b/tests/db/test_utils.py
index ee5f4c25..19ec98cf 100644
--- a/tests/db/test_utils.py
+++ b/tests/db/test_utils.py
@@ -28,213 +28,6 @@ from alot.account import Account
from ..utilities import make_key, make_uid, TestCaseClassCleanup
-class TestIsSubdirOf(unittest.TestCase):
-
- def test_both_paths_absolute_matching(self):
- superpath = '/a/b'
- subpath = '/a/b/c/d.rst'
- result = utils.is_subdir_of(subpath, superpath)
- self.assertTrue(result)
-
- def test_both_paths_absolute_not_matching(self):
- superpath = '/a/z'
- subpath = '/a/b/c/d.rst'
- result = utils.is_subdir_of(subpath, superpath)
- self.assertFalse(result)
-
- def test_both_paths_relative_matching(self):
- superpath = 'a/b'
- subpath = 'a/b/c/d.rst'
- result = utils.is_subdir_of(subpath, superpath)
- self.assertTrue(result)
-
- def test_both_paths_relative_not_matching(self):
- superpath = 'a/z'
- subpath = 'a/b/c/d.rst'
- result = utils.is_subdir_of(subpath, superpath)
- self.assertFalse(result)
-
- def test_relative_path_and_absolute_path_matching(self):
- superpath = 'a/b'
- subpath = os.path.join(os.getcwd(), 'a/b/c/d.rst')
- result = utils.is_subdir_of(subpath, superpath)
- self.assertTrue(result)
-
-
-class TestExtractHeader(unittest.TestCase):
-
- mailstring = '\n'.join([
- 'From: me',
- 'To: you',
- 'Subject: header field capitalisation',
- 'Content-type: text/plain; charset=utf-8',
- 'X-Header: param=one; and=two; or=three',
- "X-Quoted: param=utf-8''%C3%9Cmlaut; second=plain%C3%9C",
- 'X-UPPERCASE: PARAM1=ONE; PARAM2=TWO'
- '\n',
- 'content'
- ])
- mail = email.message_from_string(mailstring)
-
- def test_default_arguments_yield_all_headers(self):
- actual = utils.extract_headers(self.mail)
- # collect all lines until the first empty line, hence all header lines
- expected = []
- for line in self.mailstring.splitlines():
- if not line:
- break
- expected.append(line)
- expected = '\n'.join(expected) + '\n'
- self.assertEqual(actual, expected)
-
- def test_single_headers_can_be_retrieved(self):
- actual = utils.extract_headers(self.mail, ['from'])
- expected = 'from: me\n'
- self.assertEqual(actual, expected)
-
- def test_multible_headers_can_be_retrieved_in_predevined_order(self):
- headers = ['x-header', 'to', 'x-uppercase']
- actual = utils.extract_headers(self.mail, headers)
- expected = 'x-header: param=one; and=two; or=three\nto: you\n' \
- 'x-uppercase: PARAM1=ONE; PARAM2=TWO\n'
- self.assertEqual(actual, expected)
-
- def test_headers_can_be_retrieved_multible_times(self):
- headers = ['from', 'from']
- actual = utils.extract_headers(self.mail, headers)
- expected = 'from: me\nfrom: me\n'
- self.assertEqual(actual, expected)
-
- def test_case_is_prserved_in_header_keys_but_irelevant(self):
- headers = ['FROM', 'from']
- actual = utils.extract_headers(self.mail, headers)
- expected = 'FROM: me\nfrom: me\n'
- self.assertEqual(actual, expected)
-
- @unittest.expectedFailure
- def test_header_values_are_not_decoded(self):
- actual = utils.extract_headers(self.mail, ['x-quoted'])
- expected = "x-quoted: param=utf-8''%C3%9Cmlaut; second=plain%C3%9C\n",
- self.assertEqual(actual, expected)
-
-
-class TestDecodeHeader(unittest.TestCase):
-
- @staticmethod
- def _quote(unicode_string, encoding):
- """Turn a unicode string into a RFC2047 quoted ascii string
-
- :param unicode_string: the string to encode
- :type unicode_string: unicode
- :param encoding: the encoding to use, 'utf-8', 'iso-8859-1', ...
- :type encoding: str
- :returns: the encoded string
- :rtype: str
- """
- string = unicode_string.encode(encoding)
- output = b'=?' + encoding.encode('ascii') + b'?Q?'
- for byte in string:
- output += b'=' + codecs.encode(bytes([byte]), 'hex').upper()
- return (output + b'?=').decode('ascii')
-
- @staticmethod
- def _base64(unicode_string, encoding):
- """Turn a unicode string into a RFC2047 base64 encoded ascii string
-
- :param unicode_string: the string to encode
- :type unicode_string: unicode
- :param encoding: the encoding to use, 'utf-8', 'iso-8859-1', ...
- :type encoding: str
- :returns: the encoded string
- :rtype: str
- """
- string = unicode_string.encode(encoding)
- b64 = base64.encodebytes(string).strip()
- result_bytes = b'=?' + encoding.encode('utf-8') + b'?B?' + b64 + b'?='
- result = result_bytes.decode('ascii')
- return result
-
- def _test(self, teststring, expected):
- actual = utils.decode_header(teststring)
- self.assertEqual(actual, expected)
-
- def test_non_ascii_strings_are_returned_as_unicode_directly(self):
- text = 'Nön ÄSCII string¡'
- self._test(text, text)
-
- def test_basic_utf_8_quoted(self):
- expected = 'ÄÖÜäöü'
- text = self._quote(expected, 'utf-8')
- self._test(text, expected)
-
- def test_basic_iso_8859_1_quoted(self):
- expected = 'ÄÖÜäöü'
- text = self._quote(expected, 'iso-8859-1')
- self._test(text, expected)
-
- def test_basic_windows_1252_quoted(self):
- expected = 'ÄÖÜäöü'
- text = self._quote(expected, 'windows-1252')
- self._test(text, expected)
-
- def test_basic_utf_8_base64(self):
- expected = 'ÄÖÜäöü'
- text = self._base64(expected, 'utf-8')
- self._test(text, expected)
-
- def test_basic_iso_8859_1_base64(self):
- expected = 'ÄÖÜäöü'
- text = self._base64(expected, 'iso-8859-1')
- self._test(text, expected)
-
- def test_basic_iso_1252_base64(self):
- expected = 'ÄÖÜäöü'
- text = self._base64(expected, 'windows-1252')
- self._test(text, expected)
-
- def test_quoted_words_can_be_interrupted(self):
- part = 'ÄÖÜäöü'
- text = self._base64(part, 'utf-8') + ' and ' + \
- self._quote(part, 'utf-8')
- expected = 'ÄÖÜäöü and ÄÖÜäöü'
- self._test(text, expected)
-
- def test_different_encodings_can_be_mixed(self):
- part = 'ÄÖÜäöü'
- text = 'utf-8: ' + self._base64(part, 'utf-8') + \
- ' again: ' + self._quote(part, 'utf-8') + \
- ' latin1: ' + self._base64(part, 'iso-8859-1') + \
- ' and ' + self._quote(part, 'iso-8859-1')
- expected = (
- 'utf-8: ÄÖÜäöü '
- 'again: ÄÖÜäöü '
- 'latin1: ÄÖÜäöü and ÄÖÜäöü'
- )
- self._test(text, expected)
-
- def test_tabs_are_expanded_to_align_with_eigth_spaces(self):
- text = 'tab: \t'
- expected = 'tab: '
- self._test(text, expected)
-
- def test_newlines_are_not_touched_by_default(self):
- text = 'first\nsecond\n third\n fourth'
- expected = 'first\nsecond\n third\n fourth'
- self._test(text, expected)
-
- def test_continuation_newlines_can_be_normalized(self):
- text = 'first\nsecond\n third\n\tfourth\n \t fifth'
- expected = 'first\nsecond third fourth fifth'
- actual = utils.decode_header(text, normalize=True)
- self.assertEqual(actual, expected)
-
- def test_exchange_quotes_remain(self):
- # issue #1347
- expected = '"Mouse, Michaël" <x@y.z>'
- text = self._quote(expected, 'utf-8')
- self._test(text, expected)
-
-
class TestAddSignatureHeaders(unittest.TestCase):
class FakeMail(object):