Пример #1
0
    def setUp(self):
        super(CloudTasksEmulatorUnitTests, self).setUp()
        self.url = 'dummy_url'
        self.queue_name1 = 'queue_name1'
        self.queue_name2 = 'queue_name2'
        self.payload1 = {'param1': 'param1', 'param2': 2, 'param3': None}

        self.payload2 = {
            'param1': 'param2',
            'param2': {
                'arg': 'arg1'
            },
            'param3': [1, 2, 3]
        }
        self.output = []
        self.unit_test_emulator = cloud_tasks_emulator.Emulator(
            task_handler=self.mock_task_handler, automatic_task_handling=False)
        self.dev_mode_emulator = cloud_tasks_emulator.Emulator(
            task_handler=self.mock_task_handler)
Пример #2
0
    headers['X-Appengine-TaskRetryCount'] = '0'
    headers['X-Appengine-TaskExecutionCount'] = '0'
    headers['X-Appengine-TaskETA'] = '0'
    # Special header to fake the admin role when making requests to the task
    # handlers in DEV_MODE.
    headers['X-AppEngine-Fake-Is-Admin'] = '1'
    headers['method'] = 'POST'
    complete_url = 'http://localhost:%s%s' % (GOOGLE_APP_ENGINE_PORT, url)
    requests.post(
        complete_url,
        json=payload,
        headers=headers,
        timeout=feconf.DEFAULT_TASKQUEUE_TIMEOUT_SECONDS)


CLIENT = cloud_tasks_emulator.Emulator(task_handler=_task_handler)


# In the type annotation below, payload is of type Dict[str, Any] because
# the payload here has no constraints.
def create_http_task(
        queue_name: str,
        url: str,
        payload: Optional[Dict[str, Any]] = None,
        scheduled_for: Optional[datetime.datetime] = None,
        task_name: Optional[str] = None
) -> None:
    """Creates a Task in the corresponding queue that will be executed when
    the 'scheduled_for' countdown expires using the cloud tasks emulator.

    Args: