Esempio n. 1
0
def test_notice_collection_own_user_id(session):
    users = UserCollection(session)
    user_a = users.add(username='******', password='******', role='admin')
    user_b = users.add(username='******', password='******', role='admin')
    user_c = users.add(username='******', password='******', role='admin')

    collection = GazetteNoticeCollection(session)
    for title, user, annotators in (
        ('A', user_a, []),
        ('B', user_b, [user_a]),
        ('C', user_c, [user_a, user_b]),
    ):
        notice = collection.add(title=title,
                                text='Text',
                                organization_id='100',
                                category_id='11',
                                issues=['2017-46'],
                                user=user)
        for annotator in annotators:
            notice.changes.append(
                GazetteNoticeChange(
                    channel_id=str(notice.id),
                    owner=str(annotator.id),
                ))

    assert collection.query().count() == 3

    collection.own_user_id = str(user_a.id)
    assert collection.query().count() == 3

    collection.own_user_id = str(user_b.id)
    assert collection.query().count() == 2

    collection.own_user_id = str(user_c.id)
    assert collection.query().count() == 1
Esempio n. 2
0
def test_notice_collection_query_deleted_user(session):
    groups = UserGroupCollection(session)
    group_a = groups.add(name="Group A")
    group_b = groups.add(name="Group B")

    users = UserCollection(session)
    user_a = users.add(realname="User A",
                       username='******',
                       password='******',
                       role='admin',
                       group=group_a)
    user_b = users.add(realname="User B",
                       username='******',
                       password='******',
                       role='admin',
                       group=group_b)

    notices = GazetteNoticeCollection(session)
    notice_a = notices.add(title='A',
                           text='Text',
                           organization_id='100',
                           category_id='11',
                           issues=['2017-46'],
                           user=user_a)
    notice_b = notices.add(title='B',
                           text='Text',
                           organization_id='100',
                           category_id='11',
                           issues=['2017-46'],
                           user=user_b)

    assert notices.query().count() == 2

    assert notice_a.user is not None
    assert notice_b.user is not None
    assert notice_a.group is not None
    assert notice_b.group is not None

    assert notices.for_term("User A").query().one() == notice_a
    assert notices.for_term("User B").query().one() == notice_b
    assert notices.for_term("Group A").query().one() == notice_a
    assert notices.for_term("Group B").query().one() == notice_b

    users.delete(user_a.username)
    users.delete(user_b.username)
    groups.delete(group_a)
    groups.delete(group_b)
    commit()

    assert users.query().count() == 0
    assert groups.query().count() == 0

    notice_a = notices.query().filter(GazetteNotice.title == 'A').one()
    notice_b = notices.query().filter(GazetteNotice.title == 'B').one()

    assert notice_a.user is None
    assert notice_b.user is None
    assert notice_a.group is None
    assert notice_b.group is None

    assert notices.query().count() == 2
    assert notices.for_term("User A").query().one() == notice_a
    assert notices.for_term("User B").query().one() == notice_b
    assert notices.for_term("Group A").query().one() == notice_a
    assert notices.for_term("Group B").query().one() == notice_b