示例#1
0
def test_copy_except_deleted_and_reply(wa_list):
    # insert a reply
    wa_list.append(make_wa_object(
        age_in_hours=8, reply_to=wa_list[0]['id']))
    # add a deleted
    wa_list[1]['platform']['deleted'] = True
    original_total = len(wa_list)

    # import catcha list
    import_resp = CRUD.import_annos(wa_list)
    assert int(import_resp['original_total']) == original_total
    assert int(import_resp['total_success']) == original_total
    assert int(import_resp['total_failed']) == 0

    anno_list = CRUD.select_annos(
            context_id=wa_list[0]['platform']['context_id'],
            collection_id=wa_list[0]['platform']['collection_id'],
            platform_name=wa_list[0]['platform']['platform_name']
            )

    select_total = len(anno_list)
    for x in anno_list:
        print('search returned ({})'.format(x.anno_id))

    # discount the deleted and reply
    assert select_total == (original_total - 2)

    copy_resp = CRUD.copy_annos(
            anno_list,
            'another_fake_context',
            'collection_x')
    assert int(copy_resp['original_total']) == (original_total - 2)
    assert int(copy_resp['total_success']) == (original_total - 2)
    assert int(copy_resp['total_failed']) == 0
示例#2
0
def test_copy_ok(wa_list):
    original_total = len(wa_list)

    # import catcha list
    import_resp = CRUD.import_annos(wa_list)
    assert int(import_resp['original_total']) == original_total
    assert int(import_resp['total_success']) == original_total
    assert int(import_resp['total_failed']) == 0

    anno_list = CRUD.select_annos(
            context_id=wa_list[0]['platform']['context_id'],
            collection_id=wa_list[0]['platform']['collection_id'],
            platform_name=wa_list[0]['platform']['platform_name'],
            )

    select_total = len(anno_list)
    assert select_total == original_total

    copy_resp = CRUD.copy_annos(
            anno_list,
            'another_fake_context',
            'collection_x')
    assert int(copy_resp['original_total']) == original_total
    assert int(copy_resp['total_success']) == original_total
    assert int(copy_resp['total_failed']) == 0
示例#3
0
    def handle(self, *args, **kwargs):
        filepath = kwargs['filepath']
        source_context_id = kwargs['source_context_id']
        target_context_id = kwargs['target_context_id']
        platform_name = kwargs['platform_name']
        userid_list = None
        username_list = None
        if kwargs['userid_list']:
            userid_list = kwargs['userid_list'].strip().split(',')
        if kwargs['username_list']:
            username_list = kwargs['username_list'].strip().split(',')

        with open(filepath, 'r') as f:
            collection_map = json.load(f)

        results = []
        # TODO: not testing for repeated collection_id in input.
        for collection_row in collection_map:
            selected = CRUD.select_annos(
                context_id=source_context_id,
                collection_id=collection_row[0],
                platform_name=platform_name,
                userid_list=userid_list,
                username_list=username_list,
                is_copy=True)  # do NOT return replies and deleted
            copy_result = CRUD.copy_annos(
                anno_list=selected,
                target_context_id=target_context_id,
                target_collection_id=collection_row[1],
            )
            results.append({
                'source_context_id': source_context_id,
                'target_context_id': target_context_id,
                'source_collection_id': collection_row[0],
                'target_collection_id': collection_row[1],
                'copy_result': copy_result
            })

        print(json.dumps(results, indent=4))