Пример #1
0
def list_beneficiaries_group(event: HTTPEvent):
    district = event.params["district"]
    group = event.params["group"]
    beneficiaries = BeneficiariesService.query_group(district, group)
    return JSONResponse(QueryResult.from_list([b.to_api_dict(full=False) for b in beneficiaries]).as_dict())
def test_query_group(ddb_stubber: Stubber):
    params = {
        'IndexName': 'ByGroup',
        'KeyConditionExpression': Key('group').eq('district::group'),
        'TableName': 'beneficiaries'
    }
    response = {
        'Items': [{
            'user': {
                'S': 'abcABC123'
            },
            'group': {
                'S': 'district::group'
            },
            'unit-user': {
                'S': 'unit::abcABC123'
            },
            'full-name': {
                'S': 'Name'
            },
            'nickname': {
                'S': 'Name'
            },
            'birthdate': {
                'S': '01-01-2001'
            },
            'score': {
                'M': {}
            },
            'n_tasks': {
                'M': {}
            },
            'bought_items': {
                'M': {}
            },
            'set_base_tasks': {
                'BOOL': False
            },
        }, {
            'user': {
                'S': 'abcABC1234'
            },
            'group': {
                'S': 'district::group'
            },
            'unit-user': {
                'S': 'unit::abcABC1234'
            },
            'full-name': {
                'S': 'Name'
            },
            'nickname': {
                'S': 'Name'
            },
            'birthdate': {
                'S': '01-01-2001'
            },
            'score': {
                'M': {}
            },
            'n_tasks': {
                'M': {}
            },
            'bought_items': {
                'M': {}
            },
            'set_base_tasks': {
                'BOOL': False
            },
        }]
    }
    ddb_stubber.add_response('query', response, params)
    BeneficiariesService.query_group('district', 'group')
    ddb_stubber.assert_no_pending_responses()