Exemplo n.º 1
0
    def test_do_request_nominal(self, m_validate, m_import):
        from ddbmock.router import router

        m_module = m_import.return_value
        m_route = m_module.create_table
        m_route.return_value = {}
        m_validated = m_validate.return_value

        router(ACTION, POST, USER)

        m_import.assert_called_with("ddbmock.operations.{}".format(ROUTE))
        m_validate.assert_called_with(ROUTE, POST, USER)
        m_route.assert_called_with(m_validated)
Exemplo n.º 2
0
    def test_do_request_nominal(self, m_validate, m_import):
        from ddbmock.router import router

        m_module = m_import.return_value
        m_route = m_module.create_table
        m_route.return_value = {}
        m_validated = m_validate.return_value

        router(ACTION, POST)

        m_import.assert_called_with("ddbmock.operations.{}".format(ROUTE))
        m_validate.assert_called_with(ROUTE, POST)
        m_route.assert_called_with(m_validated)
Exemplo n.º 3
0
def pyramid_router(request):
    # extract action
    target = request.headers.get('x-amz-target')
    action = target.split('.', 2)[1] if target is not None else ""

    post = request.json

    # do the job
    try:
        body = router(action, post)
        status = '200 OK'
    except DDBError as e:
        body = e.to_dict()
        status = '{} {}'.format(e.status, e.status_str)

    # prepare output
    response = Response()
    response.body = json.dumps(body)
    response.status = status
    response.content_type = 'application/x-amz-json-1.0'
    response.headers['x-amzn-RequestId'] = post[
        'request_id']  # added by router

    # done
    return response
Exemplo n.º 4
0
def boto_router(self, action, body='', object_hook=None):
    """Replace boto.layer1.make_request to avoid the network layer. It also
    skips the authentication part. The external behavior is strictly compatible"""
    target = '%s_%s.%s' % (self.ServiceName, self.Version, action)
    start = time.time()

    post = json.loads(body)

    try:
        ret = router(action, post)
    except DDBError as e:
        raise _ddbmock_exception_to_boto_exception(e)
    finally:
        boto.log.debug('RequestId: %s', post['request_id'])
        elapsed = (time.time() - start) * 1000
        boto.perflog.info('dynamodb %s: id=%s time=%sms', target, post['request_id'], int(elapsed))

    # FIXME: dump followed by load... can be better...
    ret = json.dumps(ret)
    return json.loads(ret, object_hook=object_hook)
Exemplo n.º 5
0
def boto_router(self, action, body='', object_hook=None):
    """Replace boto.layer1.make_request to avoid the network layer. It also
    skips the authentication part. The external behavior is strictly compatible"""
    target = '%s_%s.%s' % (self.ServiceName, self.Version, action)
    start = time.time()

    post = json.loads(body)

    try:
        ret = router(action, post)
    except DDBError as e:
        raise _ddbmock_exception_to_boto_exception(e)
    finally:
        boto.log.debug('RequestId: %s', post['request_id'])
        elapsed = (time.time() - start) * 1000
        boto.perflog.info('dynamodb %s: id=%s time=%sms', target,
                          post['request_id'], int(elapsed))

    # FIXME: dump followed by load... can be better...
    ret = json.dumps(ret)
    return json.loads(ret, object_hook=object_hook)
Exemplo n.º 6
0
def pyramid_router(request):
    # extract action
    target = request.headers.get('x-amz-target')
    action = target.split('.', 2)[1] if target is not None else ""

    post = request.json

    # do the job
    try:
        body = router(action, post)
        status = '200 OK'
    except DDBError as e:
        body = e.to_dict()
        status = '{} {}'.format(e.status, e.status_str)

    # prepare output
    response = Response()
    response.body = json.dumps(body)
    response.status = status
    response.content_type = 'application/x-amz-json-1.0'
    response.headers['x-amzn-RequestId'] = post['request_id']  # added by router

    # done
    return response