示例#1
0
def delete_activity():
    """
    Deletes an activity from the database
    """
    user_id = request.args.get('userId')
    id = int(request.args.get('id'))
    dbops = DBOps()
    dbops.delete_activity(user_id=user_id, id=id)

    msg = 'Activity %s deleted for user %s' % (id, user_id)
    return jsonify({'action': msg})
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