예제 #1
0
 def test_just_args(self):
     body = b64encode(create_request_body('the_counter', 2).encode('ascii'))
     response = self.client.post(self.url,
                                 body,
                                 content_type='application/json')
     self.assertEquals(response.status_code, 200)
     self.assertEquals(json.loads(response.content.decode()), {})
     self.assertEquals(CALL_COUNTER, 2)
예제 #2
0
 def test_no_dispatch(self):
     response = self.client.post(
         self.url, b64encode(
             create_request_body('some_func').encode('ascii')),
         content_type='application/json')
     self.assertEquals(response.status_code, 400)
     self.assertEquals(json.loads(response.content.decode()),
                       {'message': 'No beanstalk dispatch table configured',
                        'error': 400})
예제 #3
0
 def test_just_args(self):
     body = b64encode(create_request_body('the_counter', 2).encode('ascii'))
     response = self.client.post(self.url,
                                 body,
                                 content_type='application/json')
     self.assertEquals(response.status_code, 200)
     self.assertEquals(json.loads(response.content.decode()),
                       {})
     self.assertEquals(CALL_COUNTER, 2)
예제 #4
0
 def test_just_args_task(self):
     body = b64encode(
         create_request_body('the_counter_task', 2).encode('ascii'))
     response = self.client.post(self.url,
                                 body,
                                 content_type='application/json')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(load_encoded_json(response.content), {})
     self.assertEqual(CALL_COUNTER, 2)
예제 #5
0
 def test_missing_function(self):
     response = self.client.post(
         self.url,
         b64encode(create_request_body('nonexistent_func').encode('ascii')),
         content_type='application/json')
     self.assertEquals(response.status_code, 400)
     self.assertEquals(
         json.loads(response.content.decode()),
         {'message': 'Requested function not found: nonexistent_func',
             'error': 400})
예제 #6
0
 def test_no_dispatch(self):
     response = self.client.post(
         self.url,
         b64encode(create_request_body('some_func').encode('ascii')),
         content_type='application/json')
     self.assertEquals(response.status_code, 400)
     self.assertEquals(json.loads(response.content.decode()), {
         'message': 'No beanstalk dispatch table configured',
         'error': 400
     })
예제 #7
0
 def test_missing_function(self):
     response = self.client.post(
         self.url,
         b64encode(create_request_body('nonexistent_func').encode('ascii')),
         content_type='application/json')
     self.assertEquals(response.status_code, 400)
     self.assertEquals(
         json.loads(response.content.decode()), {
             'message': 'Requested function not found: nonexistent_func',
             'error': 400
         })
예제 #8
0
 def test_invalid_function_pointer(self):
     response = self.client.post(
         self.url,
         b64encode(create_request_body(
             'bad_function_pointer', 'test-queue', {}).encode('ascii')),
         content_type='application/json')
     self.assertEquals(response.status_code, 400)
     self.assertEquals(
         json.loads(response.content.decode()),
         {
             'message': 'Unable to locate function: nothing-to-see-here',
             'error': 400
         })
예제 #9
0
 def test_invalid_function_pointer(self):
     response = self.client.post(self.url,
                                 b64encode(
                                     create_request_body(
                                         'bad_function_pointer',
                                         'test-queue', {}).encode('ascii')),
                                 content_type='application/json')
     self.assertEqual(response.status_code, 400)
     self.assertEqual(
         load_encoded_json(response.content), {
             'message': 'Unable to locate function: nothing-to-see-here',
             'error': 400
         })
예제 #10
0
 def test_invalid_task_class(self):
     response = self.client.post(
         self.url,
         b64encode(create_request_body(
             'bad_task_class', 'test-queue', {}).encode('ascii')),
         content_type='application/json')
     self.assertEquals(response.status_code, 400)
     self.assertEquals(
         json.loads(response.content.decode()),
         {
             'message': ('Requested task is not a SafeTask'
                         ' subclass: bad_task_class'),
             'error': 400
         })
예제 #11
0
def schedule_function(queue_name, function_name, *args, **kwargs):
    """
    Schedule a function named `function_name` to be run by workers on
    the queue `queue_name` with *args and **kwargs as specified by that
    function.
    """
    body = create_request_body(function_name, *args, **kwargs)
    connection = boto.connect_sqs(settings.BEANSTALK_DISPATCH_SQS_KEY,
                                  settings.BEANSTALK_DISPATCH_SQS_SECRET)
    queue = connection.get_queue(queue_name)
    if not queue:
        queue = connection.create_queue(queue_name)
    message = boto.sqs.message.Message()
    message.set_body(body)
    queue.write(message)
예제 #12
0
 def test_invalid_task_class(self):
     response = self.client.post(self.url,
                                 b64encode(
                                     create_request_body(
                                         'bad_task_class', 'test-queue',
                                         {}).encode('ascii')),
                                 content_type='application/json')
     self.assertEqual(response.status_code, 400)
     self.assertEqual(
         load_encoded_json(response.content), {
             'message': ('Requested task is not a SafeTask'
                         ' subclass: bad_task_class'),
             'error':
             400
         })
예제 #13
0
def schedule_function(queue_name, function_name, *args, **kwargs):
    """
    Schedule a function named `function_name` to be run by workers on
    the queue `queue_name` with *args and **kwargs as specified by that
    function.
    """
    body = create_request_body(function_name, *args, **kwargs)
    connection = boto.connect_sqs(
        settings.BEANSTALK_DISPATCH_SQS_KEY,
        settings.BEANSTALK_DISPATCH_SQS_SECRET)
    queue = connection.get_queue(queue_name)
    if not queue:
        queue = connection.create_queue(queue_name)
    message = boto.sqs.message.Message()
    message.set_body(body)
    queue.write(message)
예제 #14
0
def schedule_function(queue_name, function_name, *args, **kwargs):
    """
    Schedule a function named `function_name` to be run by workers on
    the queue `queue_name` with *args and **kwargs as specified by that
    function.
    """
    body = create_request_body(function_name, *args, **kwargs)
    if getattr(settings, 'BEANSTALK_DISPATCH_EXECUTE_SYNCHRONOUSLY', False):
        execute_function(json.loads(body))
    else:
        connection = boto.connect_sqs(settings.BEANSTALK_DISPATCH_SQS_KEY,
                                      settings.BEANSTALK_DISPATCH_SQS_SECRET)
        queue = connection.get_queue(queue_name)
        if not queue:
            queue = connection.create_queue(queue_name)
        message = boto.sqs.message.Message()
        message.set_body(body)
        queue.write(message)
예제 #15
0
def schedule_function(queue_name, function_name, *args, **kwargs):
    """
    Schedule a function named `function_name` to be run by workers on
    the queue `queue_name` with *args and **kwargs as specified by that
    function.
    """
    body = create_request_body(function_name, *args, **kwargs)
    if getattr(settings, 'BEANSTALK_DISPATCH_EXECUTE_SYNCHRONOUSLY', False):
        execute_function(json.loads(body))
    else:
        connection = boto.connect_sqs(
            settings.BEANSTALK_DISPATCH_SQS_KEY,
            settings.BEANSTALK_DISPATCH_SQS_SECRET)
        queue = connection.get_queue(queue_name)
        if not queue:
            queue = connection.create_queue(queue_name)
        message = boto.sqs.message.Message()
        message.set_body(body)
        queue.write(message)