コード例 #1
0
def tests_execute_reminder_not_pending(dynamodb_stub):
    time_In_Past_By_10_mins = datetime_to_isostr(datetime.now() -
                                                 timedelta(minutes=10))

    print("Scheduling for ", time_In_Past_By_10_mins)

    reminder2send = {
        "user_id": {
            "S": "1"
        },
        "reminder_id": {
            "S": "1"
        },
        "notify_date_time": {
            "S": str(time_In_Past_By_10_mins)
        },
        "remind_msg": {
            "S": "Pay your taxes"
        },
        "state": {
            "S": "Acknowledged"
        },
        "retry_count": {
            "N": "0"
        },
        "notify_by": {
            "M": {
                "type": {
                    "S": "SMS"
                },
                "phone_number": {
                    "S": "+1-123-456-7890"
                }
            }
        }
    }

    expectedParams = {
        'KeyConditionExpression': Key('reminder_id').eq('1'),
        'TableName': 'test-stack-RemindersTable'
    }

    dynamodb_stub.add_response('query', {U'Items': [reminder2send]},
                               expectedParams)

    reminder_id2send = {"reminder_id": "1"}

    response = execute_reminder(reminder_id2send, 'context')
    assert response == {'to_execute': 'false'}
コード例 #2
0
def tests_execute_reminder_rescheduled(dynamodb_stub):
    stubber_ssm = Stubber(ssm)
    stubber_ssm.add_response('get_parameters_by_path', {
        "Parameters": [{
            "Name": "/test-app/test/max_retry_count",
            "Value": "3"
        }]
    }, {
        'Path': '/test-app/test',
        'Recursive': False
    })
    stubber_ssm.activate()

    time_In_Future_By_10_mins = datetime_to_isostr(datetime.utcnow() +
                                                   timedelta(minutes=10))

    print("Scheduling for ", time_In_Future_By_10_mins)

    reminder2send = {
        "user_id": {
            "S": "1"
        },
        "reminder_id": {
            "S": "3"
        },
        "notify_date_time": {
            "S": str(time_In_Future_By_10_mins)
        },
        "remind_msg": {
            "S": "Pay your taxes"
        },
        "state": {
            "S": "Pending"
        },
        "retry_count": {
            "N": "1"
        },
        "notify_by": {
            "M": {
                "type": {
                    "S": "SMS"
                },
                "phone_number": {
                    "S": "+1-123-456-7890"
                }
            }
        }
    }

    expectedParams = {
        'KeyConditionExpression': Key('reminder_id').eq('3'),
        'TableName': 'test-stack-RemindersTable'
    }

    dynamodb_stub.add_response('query', {U'Items': [reminder2send]},
                               expectedParams)

    reminder_id2send = {"reminder_id": "3"}

    with stubber_ssm:
        response = execute_reminder(reminder_id2send, 'context')
        assert response == {
            'to_execute': 'true',
            'notify_date_time': ANY,
            'reminder_id': '3'
        }
コード例 #3
0
def tests_execute_reminder_exceeded_max_retry_counts(dynamodb_stub):
    stubber_ssm = Stubber(ssm)
    stubber_ssm.add_response('get_parameters_by_path', {
        "Parameters": [{
            "Name": "/test-app/test/max_retry_count",
            "Value": "3"
        }]
    }, {
        'Path': '/test-app/test',
        'Recursive': False
    })
    stubber_ssm.activate()

    time_In_Past_By_10_mins = datetime_to_isostr(datetime.utcnow() -
                                                 timedelta(minutes=10))

    print("Scheduling for ", time_In_Past_By_10_mins)

    reminder2send = {
        "user_id": {
            "S": "1"
        },
        "reminder_id": {
            "S": "1"
        },
        "notify_date_time": {
            "S": str(time_In_Past_By_10_mins)
        },
        "remind_msg": {
            "S": "Pay your taxes"
        },
        "state": {
            "S": "Pending"
        },
        "retry_count": {
            "N": "4"
        },
        "notify_by": {
            "M": {
                "type": {
                    "S": "SMS"
                },
                "phone_number": {
                    "S": "+1-123-456-7890"
                }
            }
        }
    }

    expectedParams = {
        'KeyConditionExpression': Key('reminder_id').eq('3'),
        'TableName': 'test-stack-RemindersTable'
    }

    dynamodb_stub.add_response('query', {U'Items': [reminder2send]},
                               expectedParams)

    reminder_id2send = {"reminder_id": "3"}

    expectedUpdateParams = {
        u'Key': {
            u'reminder_id': u'3'
        },
        u'TableName': u'test-stack-RemindersTable',
        u'UpdateExpression': u'SET state= :state, updated_at= :updated_at',
        u'ExpressionAttributeValues': {
            u':state': 'Unacknowledged',
            U':updated_at': ANY
        }
    }

    stubbed_response = {U'Attributes': {u'string': {"S": "string"}}}

    dynamodb_stub.add_response('update_item', stubbed_response,
                               expectedUpdateParams)

    with stubber_ssm:
        response = execute_reminder(reminder_id2send, 'context')
        assert response == {'to_execute': 'false'}
コード例 #4
0
def tests_execute_reminder_send_email(dynamodb_stub):
    stubber_ssm = Stubber(ssm)
    stubber_ssm.add_response('get_parameters_by_path', {
        "Parameters": [{
            "Name": "/test-app/test/max_retry_count",
            "Value": "3"
        }]
    }, {
        'Path': '/test-app/test',
        'Recursive': False
    })
    stubber_ssm.activate()

    stubber_ses = Stubber(ses)

    expectedParams = {
        'Destination': {
            'ToAddresses': ['*****@*****.**']
        },
        'Message': {
            'Body': {
                'Text': {
                    'Charset': 'UTF-8',
                    'Data': 'Pay your taxes'
                }
            },
            'Subject': {
                'Charset': 'UTF-8',
                'Data': 'Pay your taxes'
            }
        },
        'Source': '*****@*****.**'
    }

    stubber_ses.add_response('send_email', {"MessageId": "SomeID"},
                             expectedParams)
    stubber_ses.activate()

    time_In_Past_By_10_mins = datetime_to_isostr(datetime.utcnow() -
                                                 timedelta(minutes=10))

    print("Scheduling for ", time_In_Past_By_10_mins)

    reminder2send = {
        "user_id": {
            "S": "1"
        },
        "reminder_id": {
            "S": "1"
        },
        "notify_date_time": {
            "S": str(time_In_Past_By_10_mins)
        },
        "remind_msg": {
            "S": "Pay your taxes"
        },
        "state": {
            "S": "Pending"
        },
        "retry_count": {
            "N": "0"
        },
        "notify_by": {
            "M": {
                "type": {
                    "S": "Email"
                },
                "to_address": {
                    "S": "*****@*****.**"
                },
                "from_address": {
                    "S": "*****@*****.**"
                }
            }
        }
    }

    expectedParams = {
        'KeyConditionExpression': Key('reminder_id').eq('1'),
        'TableName': 'test-stack-RemindersTable'
    }

    dynamodb_stub.add_response('query', {U'Items': [reminder2send]},
                               expectedParams)

    reminder_id2send = {"reminder_id": "1"}

    expectedResponse = {
        'Destination': {
            'ToAddresses': ['*****@*****.**']
        },
        'Message': {
            'Body': {
                'Text': {
                    'Charset': 'UTF-8',
                    'Data': 'Pay your taxes'
                }
            },
            'Subject': {
                'Charset': 'UTF-8',
                'Data': 'Pay your taxes'
            }
        },
        'Source': '*****@*****.**'
    }

    with stubber_ssm:
        with stubber_ses:
            response = execute_reminder(reminder_id2send, 'context')
            assert response == {
                'to_execute': 'true',
                'notify_date_time': ANY,
                'reminder_id': '1'
            }