diff --git a/tests/filemon/test_util.py b/tests/filemon/test_util.py index f9ed406539265459e2e0232a6e0a6894efe0357a..c0b9e211c3f0c12998b48663686403b247ac2f6d 100644 --- a/tests/filemon/test_util.py +++ b/tests/filemon/test_util.py @@ -1,15 +1,45 @@ +# -*- coding: utf-8 -*- +import Queue from unittest import TestCase +from fixture import TempIO + +from edbob.configuration import AppConfigParser + from rattail.filemon import util +from rattail.filemon.config import Profile + + +class TestQueueExisting(TestCase): + + def setUp(self): + self.tmp = TempIO() + self.config = AppConfigParser(u'rattail') + self.config.set(u'rattail.filemon', u'monitor', u'foo') + self.config.set(u'rattail.filemon', u'foo.dirs', self.tmp) + self.config.set(u'rattail.filemon', u'foo.actions', u'noop') + self.config.set(u'rattail.filemon', u'foo.action.noop.func', u'rattail.filemon.actions:noop') + self.profile = Profile(self.config, u'foo') + self.profile.queue = Queue.Queue() + def test_nothing_queued_if_no_files_exist(self): + util.queue_existing(self.profile, self.tmp) + self.assertTrue(self.profile.queue.empty()) -class TestRaiseException(TestCase): + def test_normal_files_are_queued_but_not_folders(self): + self.tmp.putfile(u'file', u'') + self.tmp.mkdir(u'folder') + util.queue_existing(self.profile, self.tmp) + self.assertEqual(self.profile.queue.qsize(), 1) + self.assertEqual(self.profile.queue.get_nowait(), self.tmp.join(u'file')) + self.assertTrue(self.profile.queue.empty()) - def test_exception_is_raised_and_has_correct_message(self): - path = u'fake_path' - self.assertRaises(Exception, util.raise_exception, path) - try: - util.raise_exception(path, message=u"This is my custom message") - except Exception as error: - self.assertEqual(unicode(error), u"This is my custom message: fake_path") + def test_if_profile_watches_locks_then_normal_files_are_queued_but_not_lock_files(self): + self.profile.watch_locks = True + self.tmp.putfile(u'file1.lock', u'') + self.tmp.putfile(u'file2', u'') + util.queue_existing(self.profile, self.tmp) + self.assertEqual(self.profile.queue.qsize(), 1) + self.assertEqual(self.profile.queue.get_nowait(), self.tmp.join(u'file2')) + self.assertTrue(self.profile.queue.empty())