class UpdateIndexTestCase(TestCase): def setUp(self): self.job = Job() self.fnmock = Mock() self.patcher = patch("hyperkitty.jobs.update_index.update_index", self.fnmock) self.patcher.start() def tearDown(self): self.patcher.stop() def test_ok(self): self.job.execute() self.assertTrue(self.fnmock.called) def test_lock(self): lfp = get_lockfile_path() with open(lfp, "w") as lfph: lfph.write("%d\n" % os.getpid()) try: self.job.execute() self.assertTrue(os.path.exists(lfp)) finally: os.remove(lfp) self.assertFalse(self.fnmock.called) def test_lock_break(self): lfp = get_lockfile_path() with open(lfp, "w") as lfph: lfph.write("123456789\n") try: self.job.execute() self.assertFalse(os.path.exists(lfp)) finally: try: os.remove(lfp) except OSError: pass # was removed properly self.assertTrue(self.fnmock.called)
def setUp(self): self.job = Job() self.fnmock = Mock() self.patcher = patch("hyperkitty.jobs.update_index.update_index", self.fnmock) self.patcher.start()