コード例 #1
0
ファイル: test_crud.py プロジェクト: Harvard-ATG/catchpy
def test_count_deleted_anno_replies_ok(wa_text):
    catcha = wa_text
    x = CRUD.create_anno(catcha)

    # create replies
    x_replies = []
    x_r2r_replies = []
    for i in range(0, 4):
        r = make_wa_object(age_in_hours=i+2, media=ANNO, reply_to=x.anno_id)
        xr = CRUD.create_anno(r)
        # adding reply2reply because it's supported, so just in case
        r2r = make_wa_object(age_in_hours=i+1, media=ANNO, reply_to=xr.anno_id)
        x_r2r = CRUD.create_anno(r2r)

        x_replies.append(xr)
        x_r2r_replies.append(x_r2r)

    assert x.total_replies == 4

    # delete _ONE_ reply
    x_deleted = CRUD.delete_anno(x_replies[0])
    assert x_deleted is not None
    assert x_deleted == x_replies[0]

    x_deleted_fresh = CRUD.get_anno(x_replies[0].anno_id)
    assert x_deleted_fresh is None

    assert x.total_replies == 3
コード例 #2
0
ファイル: test_crud.py プロジェクト: Harvard-ATG/catchpy
def test_create_anno_invalid_target(wa_video):
    catcha = wa_video

    x = CRUD.get_anno(catcha['id'])
    assert x is None

    # mess up target type
    catcha['target']['type'] = 'FLUFFY'

    x = None
    with pytest.raises(InvalidAnnotationTargetTypeError):
        x = CRUD.create_anno(catcha)

    assert x is None
    y = CRUD.get_anno(catcha['id'])
    assert y is None
コード例 #3
0
ファイル: test_crud.py プロジェクト: Harvard-ATG/catchpy
def test_delete_anno_replies_ok(wa_text):
    catcha = wa_text
    x = CRUD.create_anno(catcha)

    # create replies
    x_replies = []
    x_r2r_replies = []
    for i in range(0, 4):
        r = make_wa_object(age_in_hours=i+2, media=ANNO, reply_to=x.anno_id)
        xr = CRUD.create_anno(r)
        # adding reply2reply because it's supported, so just in case
        r2r = make_wa_object(age_in_hours=i+1, media=ANNO, reply_to=xr.anno_id)
        x_r2r = CRUD.create_anno(r2r)

        x_replies.append(xr)
        x_r2r_replies.append(x_r2r)

    assert len(x.replies) == 4

    x_deleted = CRUD.delete_anno(x)
    assert x_deleted is not None
    assert x_deleted == x

    x_deleted_fresh = CRUD.get_anno(x.anno_id)
    assert x_deleted_fresh is None

    for i in range(0, 4):
        xr = CRUD.get_anno(x_replies[i].anno_id)
        assert xr is None

        xr = Anno._default_manager.get(pk=x_replies[i].anno_id)
        assert xr is not None
        assert xr.anno_deleted

        x_r2r = Anno._default_manager.get(pk=x_r2r_replies[i].anno_id)
        assert x_r2r is not None
        assert x_r2r.anno_deleted
コード例 #4
0
ファイル: test_crud.py プロジェクト: Harvard-ATG/catchpy
def test_true_delete_anno_ok(wa_text):
    catcha = wa_text
    x = CRUD.create_anno(catcha)

    assert x.anno_id is not None
    assert x.total_targets > 0
    anno_id = x.anno_id

    x.delete()

    assert anno_id is not None
    assert(CRUD.get_anno(x.anno_id) is None)  # this pulls from db

    with pytest.raises(Anno.DoesNotExist):
        deleted = Anno._default_manager.get(pk=anno_id)

    targets = Target._default_manager.filter(anno__anno_id=anno_id)
    assert targets.count() == 0
コード例 #5
0
ファイル: test_crud.py プロジェクト: Harvard-ATG/catchpy
def test_delete_anno_ok(wa_list):
    annos = []
    for wa in wa_list:
        catcha = wa
        annos.append(CRUD.create_anno(catcha))
    total = Anno._default_manager.count()
    assert len(annos) == total
    assert len(wa_list) == total

    x = annos[2]

    CRUD.delete_anno(x)
    assert x.anno_deleted is True
    with pytest.raises(MissingAnnotationError):
        CRUD.read_anno(x)  # this just checks current anno for deleted

    assert(CRUD.get_anno(x.anno_id) is None)  # this pulls from db

    deleted = Anno._default_manager.get(pk=x.anno_id)
    assert deleted is not None
    assert deleted.anno_deleted is True