如何模拟dynamoDB create_backup表,我无法成功运行测试

时间:2019-02-12 00:41:46

标签: unit-testing amazon-dynamodb moto

嗨,我无法模拟dynamoDB的api调用,尤其是create_backup(tableName='', BackupTableName='')

不幸的是,moto尚不支持这种特殊的测试响应 https://github.com/spulec/moto/blob/master/moto/dynamodb2/responses.py

class Handler:

    dynamo = boto3.client('dynamodb')


    def create_backup(self,table):

        response = self.dynamo.create_backup(
            TableName = table,
            BackupName = table + '_Backup'
        )
        return response

测试:

@mock_dynamodb2
def should_test_create_backup(self):
    handler =  Handler()
    response = handler.create_backup(table)

此测试通常不会给我AttributeError: 'DynamoHandler' object has no attribute 'create_backup'

第二次测试:

@patch("boto3.client", response = {})
def should_test_create_backup(self,mock_dynamo):
    handler =  BkupHandler()
    response = handler.create_backup(table)


=========================== 1 passed in 0.04 seconds ===========================.<MagicMock name='client().create_backup()' id='4507057008'>

此测试通过是因为我正在打补丁,但它不是有效的测试,只是魔术模拟,一个人如何通过打补丁使它成为有效的测试?

0 个答案:

没有答案