Ejemplo n.º 1
0
def test_notice_collection_count_by_organization(session):
    collection = GazetteNoticeCollection(session)
    assert collection.count_by_organization() == []

    organizations = OrganizationCollection(session)
    organizations.add_root(name='1', title='A')
    organizations.add_root(name='2', title='B')
    organizations.add_root(name='3', title='C')
    for organization, count in (('1', 2), ('2', 4), ('3', 10)):
        for x in range(count):
            collection.add(title='',
                           text='',
                           organization_id=organization,
                           category_id='',
                           issues=['2017-{}'.format(y) for y in range(x)],
                           user=None)
    assert collection.count_by_organization() == [
        ('A', 1),
        ('B', 6),
        ('C', 45),
    ]

    assert collection.count_by_organization() == \
        collection.for_state('drafted').count_by_organization()

    collection.issues = ['2017-1', '2017-4']
    assert collection.count_by_organization() == [('B', 2), ('C', 13)]
Ejemplo n.º 2
0
def test_notice_collection_count_by_group(session):
    collection = GazetteNoticeCollection(session)
    assert collection.count_by_group() == []

    groups = UserGroupCollection(session)
    group_a = groups.add(name='A')
    group_b = groups.add(name='B')
    groups.add(name='C')

    users = UserCollection(session)
    user_a = users.add('*****@*****.**', 'pw', 'editor', group=group_a)
    user_b = users.add('*****@*****.**', 'pw', 'editor', group=group_a)
    user_c = users.add('*****@*****.**', 'pw', 'admin')
    user_d = users.add('*****@*****.**', 'pw', 'publisher')
    user_e = users.add('*****@*****.**', 'pw', 'publisher', group=group_b)
    user_f = users.add('*****@*****.**', 'pw', 'publisher')
    user_g = users.add('*****@*****.**', 'pw', 'publisher')
    user_h = users.add('*****@*****.**', 'pw', 'publisher')

    for user, count in (
        (user_a, 2),
        (user_b, 4),
        (user_c, 1),
        (user_d, 7),
        (user_e, 2),
        (user_f, 3),
        (user_g, 6),
        (user_h, 2),
    ):
        for x in range(count):
            collection.add(title='',
                           text='',
                           organization_id='',
                           category_id='',
                           issues=['2017-{}'.format(y) for y in range(x)],
                           user=user)
    assert collection.count_by_group() == [('A', 7), ('B', 1)]

    assert collection.count_by_group() == \
        collection.for_state('drafted').count_by_group()

    collection.issues = ['2017-2', '2017-4']
    assert collection.count_by_group() == [('A', 1)]
Ejemplo n.º 3
0
def test_notice_collection_count_by_category(session):
    collection = GazetteNoticeCollection(session)
    assert collection.count_by_category() == []

    categories = CategoryCollection(session)
    categories.add_root(name='1', title='A')
    categories.add_root(name='2', title='B')
    categories.add_root(name='3', title='C')
    for category, count in (('1', 2), ('2', 4), ('3', 1)):
        for x in range(count):
            collection.add(title='',
                           text='',
                           organization_id=None,
                           category_id=category,
                           issues=['2017-{}'.format(y) for y in range(x)],
                           user=None)
    assert collection.count_by_category() == [('A', 1), ('B', 6)]

    assert collection.count_by_category() == \
        collection.for_state('drafted').count_by_category()

    collection.issues = ['2017-0', '2017-2']
    assert collection.count_by_category() == [('A', 1), ('B', 4)]