Files
@ cf4902b6480a
Branch filter:
Location: rattail-project/rattail/tests/filemon/test_util.py - annotation
cf4902b6480a
2.0 KiB
text/x-python
Do not allow executing custorder batch if no customer set
cdbb6d29d98e 00cfe2afce43 ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 ebd442ef9c7a 00cfe2afce43 00cfe2afce43 85ab706736d2 00cfe2afce43 ebd442ef9c7a 2c7d6c16e14f 2c7d6c16e14f 2c7d6c16e14f 2c7d6c16e14f 2c7d6c16e14f ebd65a8ef921 ff46d4d1e702 2c7d6c16e14f ebd65a8ef921 2c7d6c16e14f 2c7d6c16e14f 2c7d6c16e14f cdbb6d29d98e 00cfe2afce43 ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 2c7d6c16e14f ebd65a8ef921 2c7d6c16e14f 00cfe2afce43 2c7d6c16e14f ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 2c7d6c16e14f ebd65a8ef921 2c7d6c16e14f 00cfe2afce43 2c7d6c16e14f 2c7d6c16e14f ebd65a8ef921 ebd65a8ef921 ebd65a8ef921 2c7d6c16e14f ebd65a8ef921 2c7d6c16e14f | # -*- coding: utf-8; -*-
import os
import shutil
import tempfile
import queue
from unittest import TestCase
from rattail.config import make_config
from rattail.filemon import util
from rattail.filemon.config_ import Profile
class TestQueueExisting(TestCase):
def setUp(self):
self.tempdir = tempfile.mkdtemp()
self.config = make_config([], extend=False)
self.config.set(u'rattail.filemon', u'monitor', u'foo')
self.config.set('rattail.filemon', 'foo.dirs', self.tempdir)
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 tearDown(self):
shutil.rmtree(self.tempdir)
def write_file(self, fname, content):
path = os.path.join(self.tempdir, fname)
with open(path, 'wt') as f:
f.write(content)
return path
def test_nothing_queued_if_no_files_exist(self):
util.queue_existing(self.profile, self.tempdir)
self.assertTrue(self.profile.queue.empty())
def test_normal_files_are_queued_but_not_folders(self):
self.write_file('file', '')
os.makedirs(os.path.join(self.tempdir, 'folder'))
util.queue_existing(self.profile, self.tempdir)
self.assertEqual(self.profile.queue.qsize(), 1)
self.assertEqual(self.profile.queue.get_nowait(), os.path.join(self.tempdir, 'file'))
self.assertTrue(self.profile.queue.empty())
def test_if_profile_watches_locks_then_normal_files_are_queued_but_not_lock_files(self):
self.profile.watch_locks = True
self.write_file('file1.lock', '')
self.write_file('file2', '')
util.queue_existing(self.profile, self.tempdir)
self.assertEqual(self.profile.queue.qsize(), 1)
self.assertEqual(self.profile.queue.get_nowait(), os.path.join(self.tempdir, 'file2'))
self.assertTrue(self.profile.queue.empty())
|