Skip to content

Commit

Permalink
test_mailmover: Split mover-agnostic test setup to separate class
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
  • Loading branch information
kyrias committed Oct 1, 2019
1 parent 52b0f29 commit 7efa7a2
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions afew/tests/test_mailmover.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def create_mail(msg, maildir, notmuch_db, tags, old=False):
return (stripped_msgid, msg)


@freeze_time("2019-01-30 12:00:00")
class TestFolderMailMover(unittest.TestCase):
class MailMoverTestBaseClass:
def setUp(self):
self.test_dir = tempfile.mkdtemp()

Expand All @@ -62,6 +61,25 @@ def setUp(self):
self.archive = self.root.add_folder('archive')
self.spam = self.root.add_folder('spam')


def tearDown(self):
shutil.rmtree(self.test_dir)


@staticmethod
def get_folder_content(db, folder):
return {
(os.path.basename(msg.get_message_id()), msg.get_part(1).decode())
for msg in db.do_query('folder:{}'.format(folder)).search_messages()
}



@freeze_time("2019-01-30 12:00:00")
class TestFolderMailMover(MailMoverTestBaseClass, unittest.TestCase):
def __init__(self, *args, **kwargs):
super(TestFolderMailMover, self).__init__(*args, **kwargs)

# Dict of rules that are passed to FolderMailMover.
#
# The top level key represents a particular mail directory to work on.
Expand All @@ -84,18 +102,6 @@ def setUp(self):
}


def tearDown(self):
shutil.rmtree(self.test_dir)


@staticmethod
def get_folder_content(db, folder):
return {
(os.path.basename(msg.get_message_id()), msg.get_part(1).decode())
for msg in db.do_query('folder:{}'.format(folder)).search_messages()
}


def test_all_rule_cases(self):
from afew import MailMover

Expand Down

0 comments on commit 7efa7a2

Please sign in to comment.