Ejemplo n.º 1
0
def test_notice_collection(session, organizations, categories, issues):
    user = UserCollection(session).add(username='******',
                                       password='******',
                                       role='admin')

    collection = GazetteNoticeCollection(session)
    collection.add(title='Notice A',
                   text='An <strong>important</strong> Notice!',
                   organization_id='100',
                   category_id='11',
                   issues=['2017-46', '2017-47'],
                   user=user)
    collection.add(title='Notice B',
                   text='Another Notice',
                   organization_id='200',
                   category_id='13',
                   issues={'2017-47', '2017-48'},
                   user=user)

    notice = collection.for_term('Notice A').query().one()
    assert notice.title == 'Notice A'
    assert notice.text == 'An <strong>important</strong> Notice!'
    assert notice.organization_id == '100'
    assert notice.organization == 'State Chancellery'
    assert notice.category_id == '11'
    assert notice.category == 'Education'
    assert notice.issues == {'2017-46': None, '2017-47': None}
    assert notice.first_issue == standardize_date(datetime(2017, 11, 17),
                                                  'UTC')
    assert notice.user == user
    assert notice.changes.one().event == 'created'
    assert notice.changes.one().user == user

    notice = collection.for_term('Notice B').query().one()
    assert notice.title == 'Notice B'
    assert notice.text == 'Another Notice'
    assert notice.organization_id == '200'
    assert notice.organization == 'Civic Community'
    assert notice.category_id == '13'
    assert notice.category == 'Commercial Register'
    assert notice.issues == {'2017-47': None, '2017-48': None}
    assert notice.first_issue == standardize_date(datetime(2017, 11, 24),
                                                  'UTC')
    assert notice.user == user
    assert notice.changes.one().event == 'created'
    assert notice.changes.one().user == user
Ejemplo 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