Beispiel #1
0
class TestScheduleJob(TestCase):
    def setUp(self):
        self.task = Task(ModelStub())
        
    def test_schedule_job_with_scheduled_time(self):
        # Arrange
        scheduled_time = datetime.now()
        # Ack
        self.task.schedule(scheduled_time) 
        # Assert
        self.assertEqual(scheduled_time, self.task.scheduled)
Beispiel #2
0
 def __init__(self, time_to_execute, job, function, args = [], kwargs = {}):
     # pre conditions here
     self.function = function
     self.args = args
     self.kwargs = kwargs
     self.time_to_execute = time_to_execute
     # assign roles
     self.job = Task(job)
Beispiel #3
0
class ScheduleJob(object):
    def __init__(self, time_to_execute, job, function, args = [], kwargs = {}):
        # pre conditions here
        self.function = function
        self.args = args
        self.kwargs = kwargs
        self.time_to_execute = time_to_execute
        # assign roles
        self.job = Task(job)

    def __enter__(self):
        self.job.set_call(self.function, *self.args, **self.kwargs)
        if self.time_to_execute:
            self.job.schedule(self.time_to_execute)
        return self

    def __exit__(self, type, value, traceback):
        Task.revoke(self.job)
        self.job.save()
Beispiel #4
0
class TestSetFunction(TestCase):
    def setUp(self):
        self.task = Task(ModelStub())

    def test_set_call(self):
        #Ack
        self.task.set_call(hello_world)
        # Assert
        function_name = 'async_exec.tests.function_for_test.hello_world'
        self.assertEqual(function_name, self.task.name)
        
    def test_set_call_with_args(self):
        #Ack
        self.task.set_call(hello_world, 1, 2, 3)
        # Assert
        self.assertEqual("[1, 2, 3]", self.task.args)
        
    def test_set_call_with_args(self):
        #Ack
        self.task.set_call(hello_world, subject = 'Python rocks', tags = ['python', 'cool'])
        # Assert
        kwargs = '{"tags": ["python", "cool"], "subject": "Python rocks"}'
        self.assertEqual(kwargs, self.task.kwargs)
Beispiel #5
0
 def __exit__(self, type, value, traceback):
     Task.revoke(self.job)
     self.job.save()
Beispiel #6
0
 def setUp(self):
     self.task = Task(ModelStub())