Ejemplo n.º 1
0
 def setUp(self):
     db.execute("DELETE FROM cron WHERE name like 'job%'")
     db.execute('INSERT INTO cron VALUES (1, NULL, %s, %s, NULL, NULL)',
                ('job_name1', 'every 10'))
     db.execute('INSERT INTO cron VALUES (2, "job_id", %s, %s, NULL, NULL)',
                ('job_name2', 'every 10'))
     self.jobthing = JobThing()
     self.job = Job(3, 'job_3', 'job_name3', 'every 5')
Ejemplo n.º 2
0
def thing_setup():
    from leaf.thing.job import JobThing
    from leaf.thing.base import LeaderboardThing, EntryThingTrait, BaseEntryThing
    from leaf.thing.bucket import BucketEntryThing
    from leaf.thing.block import BlockEntryThing
    from leaf.thing.chunk import ChunkEntryThing
    _things['job'] = JobThing()
    _things['leaderboard'] = LeaderboardThing()
    _things['entry'] = EntryThingTrait()

    _entrythings['base'] = BaseEntryThing()
    _entrythings['bucket'] = BucketEntryThing()
    _entrythings['block'] = BlockEntryThing()
    _entrythings['chunk'] = ChunkEntryThing()
Ejemplo n.º 3
0
 def setUp(self):
     db.execute("DELETE FROM cron WHERE name like 'job%'")
     db.execute('INSERT INTO cron VALUES (1, NULL, %s, %s, NULL, NULL)', ('job_name1', 'every 10'))
     db.execute('INSERT INTO cron VALUES (2, "job_id", %s, %s, NULL, NULL)', ('job_name2', 'every 10'))
     self.jobthing = JobThing()
     self.job = Job(3,  'job_3', 'job_name3', 'every 5')
Ejemplo n.º 4
0
class JobThingTest(unittest.TestCase):

    def setUp(self):
        db.execute("DELETE FROM cron WHERE name like 'job%'")
        db.execute('INSERT INTO cron VALUES (1, NULL, %s, %s, NULL, NULL)', ('job_name1', 'every 10'))
        db.execute('INSERT INTO cron VALUES (2, "job_id", %s, %s, NULL, NULL)', ('job_name2', 'every 10'))
        self.jobthing = JobThing()
        self.job = Job(3,  'job_3', 'job_name3', 'every 5')

    def tearDown(self):
        db.execute("DELETE FROM cron WHERE name like 'job%'")

    def test_find(self):
        job = self.jobthing.find('job_name1')
        self.assertEquals((job.name, job.event), ('job_name1', 'every 10'))

        # not exists
        self.assertEqual(self.jobthing.find('job_3'), None)

    def test_find_by_job_id(self):
        jobs = self.jobthing.find_by_job_id('job_id')
        self.assertEqual(len(jobs), 1)
        self.assertEqual(jobs[0].job_id, 'job_id')

        jobs = self.jobthing.find_by_job_id(None)
        self.assertEqual(len(jobs), 1)
        self.assertEqual(jobs[0].name, 'job_name1')

    def test_save(self):
        # new
        self.job.cron_id = None
        self.jobthing.save(self.job)
        job = self.jobthing.find(self.job.name)
        self.assertEqual(job.name, self.job.name)
        self.assertEqual(job.last_run, None)

        # on dup save
        self.job.cron_id = job.cron_id
        self.job.last_run = datetime.now()
        self.jobthing.save(self.job)
        job = self.jobthing.find(self.job.name)
        self.assertEqual(job.name, self.job.name)
        self.assertTrue(job.last_run)


    def test_delete(self):
        self.job.cron_id = 1
        res = self.jobthing.delete(self.job)
        self.assertTrue(res)

        self.job.cron_id = 4
        res = self.jobthing.delete(self.job)
        self.assertFalse(res)
Ejemplo n.º 5
0
class JobThingTest(unittest.TestCase):
    def setUp(self):
        db.execute("DELETE FROM cron WHERE name like 'job%'")
        db.execute('INSERT INTO cron VALUES (1, NULL, %s, %s, NULL, NULL)',
                   ('job_name1', 'every 10'))
        db.execute('INSERT INTO cron VALUES (2, "job_id", %s, %s, NULL, NULL)',
                   ('job_name2', 'every 10'))
        self.jobthing = JobThing()
        self.job = Job(3, 'job_3', 'job_name3', 'every 5')

    def tearDown(self):
        db.execute("DELETE FROM cron WHERE name like 'job%'")

    def test_find(self):
        job = self.jobthing.find('job_name1')
        self.assertEquals((job.name, job.event), ('job_name1', 'every 10'))

        # not exists
        self.assertEqual(self.jobthing.find('job_3'), None)

    def test_find_by_job_id(self):
        jobs = self.jobthing.find_by_job_id('job_id')
        self.assertEqual(len(jobs), 1)
        self.assertEqual(jobs[0].job_id, 'job_id')

        jobs = self.jobthing.find_by_job_id(None)
        self.assertEqual(len(jobs), 1)
        self.assertEqual(jobs[0].name, 'job_name1')

    def test_save(self):
        # new
        self.job.cron_id = None
        self.jobthing.save(self.job)
        job = self.jobthing.find(self.job.name)
        self.assertEqual(job.name, self.job.name)
        self.assertEqual(job.last_run, None)

        # on dup save
        self.job.cron_id = job.cron_id
        self.job.last_run = datetime.now()
        self.jobthing.save(self.job)
        job = self.jobthing.find(self.job.name)
        self.assertEqual(job.name, self.job.name)
        self.assertTrue(job.last_run)

    def test_delete(self):
        self.job.cron_id = 1
        res = self.jobthing.delete(self.job)
        self.assertTrue(res)

        self.job.cron_id = 4
        res = self.jobthing.delete(self.job)
        self.assertFalse(res)