コード例 #1
0
ファイル: app.py プロジェクト: datakind/caseworker-scheduler
def get_activities():
    """
    Retrieves activities from the database for the specified user
    """
    user_id = request.args.get('userId')
    dbops = DBOps()
    activities = dbops.get_activities(user_id)
    for activity in activities:
        activity['completed'] = str(activity['completed'])
        activity['id'] = str(activity['id'])

    return jsonify(activities)
コード例 #2
0
def test_activity_db():
    dbops = DBOps()
    test_activity = {
        'userId': 'testid',
        'id': 1,
        'caseName': 'testcase',
        'activityType': 'testactivity',
        'expectedDuration': 30,
        'address': 'testaddress',
        'city': 'testcity',
        'state': 'teststate',
        'zipCode': 'testzip',
        'coordinates': [1, 2],
        'completed': False
    }

    dbops.upsert_activity(test_activity)
    activity = dbops.get_activity('testid', 1)
    for key in activity:
        if key != 'insert_timestamp':
            assert activity[key] == test_activity[key]

    test_activity2 = {
        'userId': 'testid',
        'id': 2,
        'caseName': 'testcase',
        'activityType': 'testactivity',
        'expectedDuration': 30,
        'address': 'testaddress',
        'city': 'testcity',
        'state': 'teststate',
        'zipCode': 'testzip',
        'coordinates': [1, 2],
        'completed': False
    }
    dbops.upsert_activity(test_activity2)
    activity = dbops.get_activity('testid', 2)
    for key in activity:
        if key != 'insert_timestamp':
            assert activity[key] == test_activity2[key]

    activities = dbops.get_activities('testid')
    assert len(activities) == 2

    dbops.delete_activity('testid', 1)
    activity = dbops.get_activity('testid', 1)
    assert activity == None

    dbops.delete_activity('testid', 2)
    activity = dbops.get_activity('testid', 2)
    assert activity == None