当前位置: 首页>>代码示例>>Python>>正文


Python server.create_backend_app函数代码示例

本文整理汇总了Python中moto.server.create_backend_app函数的典型用法代码示例。如果您正苦于以下问题:Python create_backend_app函数的具体用法?Python create_backend_app怎么用?Python create_backend_app使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_backend_app函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_list_vaults

def test_list_vaults():
    backend = server.create_backend_app("glacier")
    test_client = backend.test_client()

    res = test_client.get('/1234bcd/vaults')

    json.loads(res.data.decode("utf-8")).should.equal({u'Marker': None, u'VaultList': []})
开发者ID:DarthLorenzo,项目名称:moto,代码行数:7,代码来源:test_glacier_server.py

示例2: test_rotate_secret_client_request_token_too_long

def test_rotate_secret_client_request_token_too_long():
    backend = server.create_backend_app('secretsmanager')
    test_client = backend.test_client()

    create_secret = test_client.post('/',
                        data={"Name": "test-secret",
                              "SecretString": "foosecret"},
                        headers={
                            "X-Amz-Target": "secretsmanager.CreateSecret"
                        },
                    )

    client_request_token = (
        'ED9F8B6C-85B7-446A-B7E4-38F2A3BEB13C-'
        'ED9F8B6C-85B7-446A-B7E4-38F2A3BEB13C'
    )
    rotate_secret = test_client.post('/',
                        data={"SecretId": "test-secret",
                              "ClientRequestToken": client_request_token},
                        headers={
                            "X-Amz-Target": "secretsmanager.RotateSecret"
                        },
                    )

    json_data = json.loads(rotate_secret.data.decode("utf-8"))
    assert json_data['message'] == "ClientRequestToken must be 32-64 characters long."
    assert json_data['__type'] == 'InvalidParameterException'
开发者ID:copland,项目名称:moto,代码行数:27,代码来源:test_server.py

示例3: test_messages_polling

def test_messages_polling():
    backend = server.create_backend_app("sqs")
    test_client = backend.test_client()
    messages = []

    test_client.put('/?Action=CreateQueue&QueueName=testqueue')

    def insert_messages():
        messages_count = 5
        while messages_count > 0:
            test_client.put(
                '/123/testqueue?MessageBody=test-message&Action=SendMessage'
                '&Attribute.1.Name=WaitTimeSeconds&Attribute.1.Value=10'
            )
            messages_count -= 1
            time.sleep(.5)

    def get_messages():
        msg_res = test_client.get(
            '/123/testqueue?Action=ReceiveMessage&MaxNumberOfMessages=1&WaitTimeSeconds=5'
        )
        [messages.append(m) for m in re.findall("<Body>(.*?)</Body>", msg_res.data.decode('utf-8'))]

    get_messages_thread = threading.Thread(target=get_messages)
    insert_messages_thread = threading.Thread(target=insert_messages)

    get_messages_thread.start()
    insert_messages_thread.start()

    get_messages_thread.join()
    insert_messages_thread.join()

    assert len(messages) == 5
开发者ID:pitluga,项目名称:moto,代码行数:33,代码来源:test_server.py

示例4: test_create_secret

def test_create_secret():

    backend = server.create_backend_app("secretsmanager")
    test_client = backend.test_client()

    res = test_client.post('/',
                           data={"Name": "test-secret",
                                 "SecretString": "foo-secret"},
                           headers={
                               "X-Amz-Target": "secretsmanager.CreateSecret"},
                           )
    res_2 = test_client.post('/',
                           data={"Name": "test-secret-2",
                                 "SecretString": "bar-secret"},
                           headers={
                               "X-Amz-Target": "secretsmanager.CreateSecret"},
                           )

    json_data = json.loads(res.data.decode("utf-8"))
    assert json_data['ARN'] != ''
    assert json_data['Name'] == 'test-secret'
    
    json_data_2 = json.loads(res_2.data.decode("utf-8"))
    assert json_data_2['ARN'] != ''
    assert json_data_2['Name'] == 'test-secret-2'
开发者ID:copland,项目名称:moto,代码行数:25,代码来源:test_server.py

示例5: test_elbv2_describe_load_balancers

def test_elbv2_describe_load_balancers():
    backend = server.create_backend_app("elbv2")
    test_client = backend.test_client()

    res = test_client.get('/?Action=DescribeLoadBalancers&Version=2015-12-01')

    res.data.should.contain(b'DescribeLoadBalancersResponse')
开发者ID:Affirm,项目名称:moto,代码行数:7,代码来源:test_server.py

示例6: test_rotate_secret

def test_rotate_secret():
    backend = server.create_backend_app('secretsmanager')
    test_client = backend.test_client()

    create_secret = test_client.post('/',
                        data={"Name": "test-secret",
                              "SecretString": "foosecret"},
                        headers={
                            "X-Amz-Target": "secretsmanager.CreateSecret"
                        },
                    )

    client_request_token = "EXAMPLE2-90ab-cdef-fedc-ba987SECRET2"
    rotate_secret = test_client.post('/',
                        data={"SecretId": "test-secret",
                              "ClientRequestToken": client_request_token},
                        headers={
                            "X-Amz-Target": "secretsmanager.RotateSecret"
                        },
                    )

    json_data = json.loads(rotate_secret.data.decode("utf-8"))
    assert json_data   # Returned dict is not empty
    assert json_data['ARN'] != ''
    assert json_data['Name'] == 'test-secret'
    assert json_data['VersionId'] == client_request_token
开发者ID:copland,项目名称:moto,代码行数:26,代码来源:test_server.py

示例7: test_list_databases

def test_list_databases():
    backend = server.create_backend_app("rds")
    test_client = backend.test_client()

    res = test_client.get('/?Action=DescribeDBInstances')

    res.data.decode("utf-8").should.contain("<DescribeDBInstancesResult>")
开发者ID:2rs2ts,项目名称:moto,代码行数:7,代码来源:test_server.py

示例8: test_iot_list

def test_iot_list():
    backend = server.create_backend_app("iot")
    test_client = backend.test_client()

    # just making sure that server is up
    res = test_client.get('/things')
    res.status_code.should.equal(404)
开发者ID:Affirm,项目名称:moto,代码行数:7,代码来源:test_server.py

示例9: test_s3_server_get

def test_s3_server_get():
    backend = server.create_backend_app("s3bucket_path")
    test_client = backend.test_client()

    res = test_client.get('/')

    res.data.should.contain(b'ListAllMyBucketsResult')
开发者ID:balintzs,项目名称:moto,代码行数:7,代码来源:test_bucket_path_server.py

示例10: test_sqs_list_identities

def test_sqs_list_identities():
    backend = server.create_backend_app("sqs")
    test_client = backend.test_client()

    res = test_client.get('/?Action=ListQueues')
    res.data.should.contain(b"ListQueuesResponse")

    # Make sure that we can receive messages from queues whose name contains dots (".")
    # The AWS API mandates that the names of FIFO queues use the suffix ".fifo"
    # See: https://github.com/spulec/moto/issues/866

    for queue_name in ('testqueue', 'otherqueue.fifo'):

        res = test_client.put('/?Action=CreateQueue&QueueName=%s' % queue_name)


        res = test_client.put(
            '/123/%s?MessageBody=test-message&Action=SendMessage' % queue_name)

        res = test_client.get(
            '/123/%s?Action=ReceiveMessage&MaxNumberOfMessages=1' % queue_name)

        message = re.search("<Body>(.*?)</Body>",
                            res.data.decode('utf-8')).groups()[0]
        message.should.equal('test-message')

    res = test_client.get('/?Action=ListQueues&QueueNamePrefix=other')
    res.data.should.contain(b'otherqueue.fifo')
    res.data.should_not.contain(b'testqueue')
开发者ID:Affirm,项目名称:moto,代码行数:29,代码来源:test_server.py

示例11: test_s3_server_bucket_create

def test_s3_server_bucket_create():
    backend = server.create_backend_app("s3bucket_path")
    test_client = backend.test_client()

    res = test_client.put('/foobar', 'http://localhost:5000')
    res.status_code.should.equal(200)

    res = test_client.get('/')
    res.data.should.contain(b'<Name>foobar</Name>')

    res = test_client.get('/foobar', 'http://localhost:5000')
    res.status_code.should.equal(200)
    res.data.should.contain(b"ListBucketResult")

    res = test_client.put('/foobar2/', 'http://localhost:5000')
    res.status_code.should.equal(200)

    res = test_client.get('/')
    res.data.should.contain(b'<Name>foobar2</Name>')

    res = test_client.get('/foobar2/', 'http://localhost:5000')
    res.status_code.should.equal(200)
    res.data.should.contain(b"ListBucketResult")

    res = test_client.get('/missing-bucket', 'http://localhost:5000')
    res.status_code.should.equal(404)

    res = test_client.put('/foobar/bar', 'http://localhost:5000', data='test value')
    res.status_code.should.equal(200)

    res = test_client.get('/foobar/bar', 'http://localhost:5000')
    res.status_code.should.equal(200)
    res.data.should.equal(b"test value")
开发者ID:balintzs,项目名称:moto,代码行数:33,代码来源:test_bucket_path_server.py

示例12: test_usage_plans_keys

def test_usage_plans_keys():
    backend = server.create_backend_app('apigateway')
    test_client = backend.test_client()
    usage_plan_id = 'test_plan_id'

    # Create API key to be used in tests
    res = test_client.post('/apikeys', data=json.dumps({'name': 'test'}))
    created_api_key = json.loads(res.data)

    # List usage plans keys (expect empty)
    res = test_client.get('/usageplans/{0}/keys'.format(usage_plan_id))
    json.loads(res.data)["item"].should.have.length_of(0)

    # Create usage plan key
    res = test_client.post('/usageplans/{0}/keys'.format(usage_plan_id), data=json.dumps({'keyId': created_api_key["id"], 'keyType': 'API_KEY'}))
    created_usage_plan_key = json.loads(res.data)

    # List usage plans keys (expect 1 key)
    res = test_client.get('/usageplans/{0}/keys'.format(usage_plan_id))
    json.loads(res.data)["item"].should.have.length_of(1)

    # Get single usage plan key
    res = test_client.get('/usageplans/{0}/keys/{1}'.format(usage_plan_id, created_api_key["id"]))
    fetched_plan_key = json.loads(res.data)
    fetched_plan_key.should.equal(created_usage_plan_key)

    # Delete usage plan key
    res = test_client.delete('/usageplans/{0}/keys/{1}'.format(usage_plan_id, created_api_key["id"]))
    res.data.should.equal(b'{}')

    # List usage plans keys (expect to be empty again)
    res = test_client.get('/usageplans/{0}/keys'.format(usage_plan_id))
    json.loads(res.data)["item"].should.have.length_of(0)
开发者ID:botify-labs,项目名称:moto,代码行数:33,代码来源:test_server.py

示例13: test_usage_plans_apis

def test_usage_plans_apis():
    backend = server.create_backend_app('apigateway')
    test_client = backend.test_client()

    # List usage plans (expect empty)
    res = test_client.get('/usageplans')
    json.loads(res.data)["item"].should.have.length_of(0)

    # Create usage plan
    res = test_client.post('/usageplans', data=json.dumps({'name': 'test'}))
    created_plan = json.loads(res.data)
    created_plan['name'].should.equal('test')

    # List usage plans (expect 1 plan)
    res = test_client.get('/usageplans')
    json.loads(res.data)["item"].should.have.length_of(1)

    # Get single usage plan
    res = test_client.get('/usageplans/{0}'.format(created_plan["id"]))
    fetched_plan = json.loads(res.data)
    fetched_plan.should.equal(created_plan)

    # Delete usage plan
    res = test_client.delete('/usageplans/{0}'.format(created_plan["id"]))
    res.data.should.equal(b'{}')

    # List usage plans (expect empty again)
    res = test_client.get('/usageplans')
    json.loads(res.data)["item"].should.have.length_of(0)
开发者ID:botify-labs,项目名称:moto,代码行数:29,代码来源:test_server.py

示例14: test_elb_describe_instances

def test_elb_describe_instances():
    backend = server.create_backend_app("elb")
    test_client = backend.test_client()

    res = test_client.get('/?Action=DescribeLoadBalancers')

    res.data.should.contain('DescribeLoadBalancersResponse')
开发者ID:elastic-coders,项目名称:moto,代码行数:7,代码来源:test_server.py

示例15: test_sts_get_session_token

def test_sts_get_session_token():
    backend = server.create_backend_app("sts")
    test_client = backend.test_client()

    res = test_client.get('/?Action=GetSessionToken')
    res.status_code.should.equal(200)
    res.data.should.contain("SessionToken")
    res.data.should.contain("AccessKeyId")
开发者ID:Zulunko,项目名称:moto,代码行数:8,代码来源:test_server.py


注:本文中的moto.server.create_backend_app函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。