示例#1
0
def test__extract_and_map():
    """
    Check that the transform works as expected.
    """
    # this is the kind of list that will be returned from SF:
    test_list = [{
        u'Text_For_Donor_Wall__c': u'Mark Zlinger',
        u'Name': u'Zlinger Account',
        u'attributes': {
            u'type': u'Account',
            u'url': u'/services/data/v33.0/sobjects/Account/0011700000C46BMAAZ'
            },
        u'npo02__LastMembershipLevel__c': u"Editor's Circle"},
        {
        u'Text_For_Donor_Wall__c': u'Mark Olinger',
        u'Name': u'Olinger Account',
        u'attributes': {
            u'type': u'Account',
            u'url': u'/services/data/v33.0/sobjects/Account/0011700000C46BMAAZ'
             },
        u'npo02__LastMembershipLevel__c': u"Editor's Circle"
        }]
    key = 'Text_For_Donor_Wall__c'
    value = 'npo02__LastMembershipLevel__c'
    # this is what we want:
    expected = {
            u'Olinger Account:Mark Olinger': u"Editor's Circle",
            u'Zlinger Account:Mark Zlinger': u"Editor's Circle"
            }
    sort = 'Name'
    actual = _extract_and_map(test_list, key, value, sort)
    assert expected == actual
示例#2
0
def generate_circle_data():
    """
    Create a JSON file based on current circle members that
    identifies the level of circle membership. Save this
    file to S3.
    """

    # circle wall
    sf = SalesforceConnection()
    response = sf.query(circle_query)
    new_dict = _extract_and_map(argument=response,
            key='Text_For_Donor_Wall__c',
            value='Membership_Level_TT__c',
            sort_key='Name')
    intermediate = _invert_and_aggregate(new_dict)
    now_sorted = _sort_circle(intermediate)
    final = _strip_sort_key(now_sorted)
    json_output = json.dumps(final)

    push_to_s3(filename='circle-members.json', contents=json_output)