Exemplo n.º 1
0
def _push_diary_data_by_action(user_id, action, data):
    """
    Update server diary database based on client changes.

    action: 'create'
    data: {
        'uuid': "2F69DEB5-B631-40DD-A65E-AFE9A0882275",
        'time': 1477139399,
        'title': 'this is a new diary',
        'content': 'today is a good day',
    }
    action:'delete'
    data: {
        'uuid': "04B977C7-6F7F-4D36-BFDA-FE98C5241DB0"
        'time': 1477139399,
    }
    """
    logger.info('_push_diary_data_by_action: user_id:%s; action:%s; data:%s',
                user_id, action, data)
    if action == 'create' or action == 'update':
        db_diary.upsert_diary(user_id, data.get('uuid'), data)
    elif action == 'delete':
        db_diary.delete_diary(user_id, data.get('uuid'), data.get('time'))
    else:
        return
Exemplo n.º 2
0
def test_push():
    base_test.reinit_table()
    # create mock user
    _create_mock_user(1)
    # create a diary
    data = {
        'title': 'first diary',
        'content': 'first diary',
        'time': 11111111,
    }
    _uuid = _get_uuid()
    user_id = 1

    assert db_diary.get_diary_by_uuid(_uuid, user_id) is None
    db_diary.upsert_diary(user_id, _uuid, data)
    diary = db_diary.get_diary_by_uuid(_uuid, user_id)
    assert diary is not None
    assert diary.get('time_created') == 11111111
    assert diary.get('time_modified') == 11111111

    # change this diary
    data = {
        'title': 'changed diary',
        'content': 'changed diary',
        'time': 2222222,
    }
    db_diary.upsert_diary(user_id, _uuid, data)
    diary = db_diary.get_diary_by_uuid(_uuid, user_id)
    assert diary is not None
    assert diary.get('title') == 'changed diary'
    assert diary.get('content') == 'changed diary'
    assert diary.get('time_created') == 11111111
    assert diary.get('time_modified') == 2222222

    # delete this diary
    time_delete = 333333333
    db_diary.delete_diary(user_id, _uuid, time_delete)
    diary = db_diary.get_diary_by_uuid(_uuid, user_id)
    assert diary is None
Exemplo n.º 3
0
def _push_diary_data_by_action(user_id, action, data):
    """
    Update server diary database based on client changes.

    action: 'create'
    data: {
        'uuid': "2F69DEB5-B631-40DD-A65E-AFE9A0882275",
        'time': 1477139399,
        'title': 'this is a new diary',
        'content': 'today is a good day',
    }
    action:'delete'
    data: {
        'uuid': "04B977C7-6F7F-4D36-BFDA-FE98C5241DB0"
        'time': 1477139399,
    }
    """
    logger.info('_push_diary_data_by_action: user_id:%s; action:%s; data:%s', user_id, action, data)
    if action == 'create' or action == 'update':
        db_diary.upsert_diary(user_id, data.get('uuid'), data)
    elif action == 'delete':
        db_diary.delete_diary(user_id, data.get('uuid'), data.get('time'))
    else:
        return
Exemplo n.º 4
0
def upsert_diary(user_id, uuid, data):
    db_diary.upsert_diary(user_id, uuid, data)