def test_basic_processing(self): # make sure UserCommand got registered self.assertTrue('djutils.tests.queue.UserCommand' in registry) self.assertEqual(registry._registry['djutils.tests.queue.UserCommand'], UserCommand) # create a command command = UserCommand((self.dummy, self.dummy.email, '*****@*****.**')) # enqueueing the command won't execute it - it just hangs out invoker.enqueue(command) # did the message get enqueued? self.assertEqual(len(invoker.queue), 1) # dequeueing loads from the queue, creates a command and executes it invoker.dequeue() # make sure the command's execute() method got called dummy = User.objects.get(username='******') self.assertEqual(dummy.email, '*****@*****.**')
def test_periodic_command_registration(self): # make sure TestPeriodicCommand got registered self.assertTrue('djutils.tests.queue.TestPeriodicCommand' in registry) self.assertEqual(registry._registry['djutils.tests.queue.TestPeriodicCommand'], TestPeriodicCommand) # create a command command = TestPeriodicCommand() # enqueueing the command won't execute it - it just hangs out invoker.enqueue(command) # check that there are no users in the db self.assertEqual(User.objects.all().count(), 1) # did the message get enqueued? self.assertEqual(len(invoker.queue), 1) # dequeueing loads from the queue, creates a command and executes it invoker.dequeue() # a new user should have been added self.assertEqual(User.objects.all().count(), 2)
def inner_run(*args, **kwargs): invoker.enqueue(klass((args, kwargs)))