Ejemplo n.º 1
0
    def test_decorated_function(self):
        user_command(self.dummy, '*****@*****.**')
        self.assertEqual(len(invoker.queue), 1)

        # the user's email address hasn't changed yet
        dummy = User.objects.get(username='******')
        self.assertEqual(dummy.email, '*****@*****.**')

        # dequeue
        invoker.dequeue()

        # make sure that the command was executed
        dummy = User.objects.get(username='******')
        self.assertEqual(dummy.email, '*****@*****.**')
        self.assertEqual(len(invoker.queue), 0)
Ejemplo n.º 2
0
    def test_decorated_function(self):
        user_command(self.dummy, '*****@*****.**')
        self.assertEqual(len(invoker.queue), 1)

        # the user's email address hasn't changed yet
        dummy = User.objects.get(username='******')
        self.assertEqual(dummy.email, '*****@*****.**')

        # dequeue
        invoker.dequeue()

        # make sure that the command was executed
        dummy = User.objects.get(username='******')
        self.assertEqual(dummy.email, '*****@*****.**')
        self.assertEqual(len(invoker.queue), 0)
Ejemplo n.º 3
0
    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, '*****@*****.**')
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    def test_periodic_command_enqueueing(self):
        on_time = datetime.datetime(2011, 1, 1, 1, 15)  # matches */15
        off_time = datetime.datetime(2011, 1, 1, 1, 16)  # doesn't match */15
        both_time = datetime.datetime(2011, 1, 1, 1, 30)

        # there should be nothing in the queue
        self.assertEqual(len(invoker.queue), 0)

        # no commands should be enqueued
        invoker.enqueue_periodic_commands(off_time)

        self.assertEqual(len(invoker.queue), 0)

        # running it at 1:15 will pick up the */15 command
        invoker.enqueue_periodic_commands(on_time)

        self.assertEqual(len(invoker.queue), 1)

        # dequeue and execute, should get a new user named 'fifteen'
        invoker.dequeue()

        # verify user created, then delete the user
        self.assertEqual(User.objects.filter(username='******').count(), 1)
        User.objects.all().delete()

        # make sure the queue is empty
        self.assertEqual(len(invoker.queue), 0)

        # running it at :30 will pick up both the */15 and the */30 commands
        invoker.enqueue_periodic_commands(both_time)

        self.assertEqual(len(invoker.queue), 2)

        # execute both commands
        invoker.dequeue()
        invoker.dequeue()

        # check that the users were created
        self.assertEqual(User.objects.all().count(), 2)
        self.assertEqual(User.objects.filter(username='******').count(), 1)
        self.assertEqual(User.objects.filter(username='******').count(), 1)
Ejemplo n.º 6
0
 def test_periodic_command_enqueueing(self):
     on_time = datetime.datetime(2011, 1, 1, 1, 15) # matches */15
     off_time = datetime.datetime(2011, 1, 1, 1, 16) # doesn't match */15
     both_time = datetime.datetime(2011, 1, 1, 1, 30)
     
     # there should be nothing in the queue
     self.assertEqual(len(invoker.queue), 0)
     
     # no commands should be enqueued
     invoker.enqueue_periodic_commands(off_time)
     
     self.assertEqual(len(invoker.queue), 0)
     
     # running it at 1:15 will pick up the */15 command
     invoker.enqueue_periodic_commands(on_time)
     
     self.assertEqual(len(invoker.queue), 1)
     
     # dequeue and execute, should get a new user named 'fifteen'
     invoker.dequeue()
     
     # verify user created, then delete the user
     self.assertEqual(User.objects.filter(username='******').count(), 1)
     User.objects.all().delete()
     
     # make sure the queue is empty
     self.assertEqual(len(invoker.queue), 0)
     
     # running it at :30 will pick up both the */15 and the */30 commands
     invoker.enqueue_periodic_commands(both_time)
     
     self.assertEqual(len(invoker.queue), 2)
     
     # execute both commands
     invoker.dequeue()
     invoker.dequeue()
     
     # check that the users were created
     self.assertEqual(User.objects.all().count(), 2)
     self.assertEqual(User.objects.filter(username='******').count(), 1)
     self.assertEqual(User.objects.filter(username='******').count(), 1)