示例#1
0
def test_view_notices_importation(gazette_app):
    client = Client(gazette_app)
    login_publisher(client)

    assert "notices/rejected" in client.get('/notices/drafted')
    assert "notices/imported" not in client.get('/notices/drafted')

    assert "notices/rejected" in client.get('/notices/drafted/statistics')
    assert "notices/imported" not in client.get('/notices/drafted/statistics')

    principal = gazette_app.principal
    principal.sogc_import = {
        'canton': 'GV',
        'endpoint': 'https://localhost',
        'username': '******',
        'password': '******',
        'category': 100,
        'organiaztion': 200
    }
    gazette_app.cache.set('principal', principal)

    assert "notices/imported" in client.get('/notices/drafted')
    assert "notices/rejected" in client.get('/notices/drafted')

    assert "notices/imported" in client.get('/notices/drafted/statistics')
    assert "notices/rejected" in client.get('/notices/drafted/statistics')
示例#2
0
def test_view_notices_update(gazette_app):
    with freeze_time("2017-11-01 11:00"):

        client = Client(gazette_app)
        login_publisher(client)

        # Add a notice
        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = "Erneuerungswahlen"
        manage.form['organization'] = '100'
        manage.form['category'] = '11'
        manage.form['issues'] = ['2017-44', '2017-46']
        manage.form['text'] = "1. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()
        client.get('/notice/erneuerungswahlen/submit').form.submit()
        client.get('/notice/erneuerungswahlen/accept').form.submit()

        manage = client.get('/notice/erneuerungswahlen')
        assert 'State Chancellery' in manage
        assert 'Education' in manage

        # Change the category and organization of the notice
        # (don't change the category or organization because of the observers!)
        transaction.begin()
        session = gazette_app.session()
        notice = session.query(GazetteNotice).one()
        notice.category = 'Edurcatio'
        notice.organization = 'Sate Chancelery'
        transaction.commit()

        manage = client.get('/notice/erneuerungswahlen')
        assert 'Education' not in manage
        assert 'Edurcatio' in manage
        assert 'State Chancellery' not in manage
        assert 'Sate Chancelery' in manage

        # Update all notices
        manage = client.get('/notices/submitted/update')
        manage = manage.form.submit().maybe_follow()
        assert "Meldungen aktualisiert." in manage

        manage = client.get('/notice/erneuerungswahlen')
        assert 'Education' not in manage
        assert 'Edurcatio' in manage
        assert 'State Chancellery' not in manage
        assert 'Sate Chancelery' in manage

        manage = client.get('/notices/accepted/update')
        manage = manage.form.submit().maybe_follow()
        assert "Meldungen aktualisiert." in manage

        manage = client.get('/notice/erneuerungswahlen')
        assert 'Education' in manage
        assert 'Edurcatio' not in manage
        assert 'State Chancellery' in manage
        assert 'Sate Chancelery' not in manage
示例#3
0
def test_view_organizations_order(gazette_app):
    client = Client(gazette_app)
    login_publisher(client)

    manage = client.get('/organizations')
    manage = manage.click('Ordnen')
    organizations = [
        t.text.strip() for t in manage.pyquery('ul[data-sortable] li')
    ]
    assert organizations == [
        'State Chancellery',
        'Civic Community',
        'Municipality',
        'Churches',
        'Evangelical Reformed Parish',
        'Sikh Community',
        'Catholic Parish',
        'Corporation',
    ]
    url = manage.pyquery('ul[data-sortable]')[0].attrib['data-sortable-url']
    expected = (
        '/move/organization/%7Bsubject_id%7D/%7Bdirection%7D/%7Btarget_id%7D'
        '?csrf-token=')
    assert expected in url

    # Move items
    session = gazette_app.session()
    query = session.query(Organization)

    subject = query.filter_by(title='State Chancellery').one().id
    target = query.filter_by(title='Municipality').one().id
    move = url.replace('%7Bsubject_id%7D', str(subject))
    move = move.replace('%7Btarget_id%7D', str(target))
    move = move.replace('%7Bdirection%7D', 'below')
    client.put(move)

    subject = query.filter_by(title='Catholic Parish').one().id
    target = query.filter_by(title='Sikh Community').one().id
    move = url.replace('%7Bsubject_id%7D', str(subject))
    move = move.replace('%7Btarget_id%7D', str(target))
    move = move.replace('%7Bdirection%7D', 'above')
    client.put(move)

    manage = client.get('/organizations')
    manage = manage.click('Ordnen')
    organizations = [
        t.text.strip() for t in manage.pyquery('ul[data-sortable] li')
    ]
    assert organizations == [
        'Civic Community',
        'Municipality',
        'State Chancellery',
        'Churches',
        'Evangelical Reformed Parish',
        'Catholic Parish',
        'Sikh Community',
        'Corporation',
    ]
示例#4
0
def test_view_notices_index(gazette_app):
    with freeze_time("2017-11-01 11:00"):

        client = Client(gazette_app)
        login_publisher(client)

        # new notice
        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = "Erneuerungswahlen"
        manage.form['organization'] = '200'
        manage.form['category'] = '11'
        manage.form['issues'] = ['2017-44', '2017-45']
        manage.form['text'] = "1. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()
        client.get('/notice/erneuerungswahlen/submit').form.submit()
        client.get('/notice/erneuerungswahlen/accept').form.submit()

        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = "Kantonsratswahlen"
        manage.form['organization'] = '300'
        manage.form['category'] = '12'
        manage.form['issues'] = ['2017-45', '2017-46']
        manage.form['text'] = "10. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()
        client.get('/notice/kantonsratswahlen/submit').form.submit()
        client.get('/notice/kantonsratswahlen/accept').form.submit()

        publish_issue(client, '2017-44')
        publish_issue(client, '2017-45')
        publish_issue(client, '2017-46')

        response = client.get('/notices/published/index')
        assert response.headers['Content-Type'] == 'application/pdf'
        assert response.headers['Content-Disposition'] == \
            'inline; filename=amtsblatt-govikon.pdf'

        reader = PdfFileReader(BytesIO(response.body))
        assert [page.extractText() for page in reader.pages
                ] == [('© 2017 Govikon\n1\nAmtsblatt\nStichwortverzeichnis\n'
                       'Organisationen\n'
                       'C\n'
                       'Civic Community  2017-44-1, 2017-45-2\n'
                       'M\n'
                       'Municipality  2017-45-3, 2017-46-4\n'),
                      ('Amtsblatt\n© 2017 Govikon\n2\n'
                       'Rubriken\n'
                       'E\n'
                       'Education  2017-44-1, 2017-45-2\n'
                       'S\n'
                       'Submissions  2017-45-3, 2017-46-4\n')]
示例#5
0
def test_view_issues_export(gazette_app):
    client = Client(gazette_app)

    client.get('/issues/export', status=403)

    login_editor_1(client)
    client.get('/issues/export', status=403)

    login_publisher(client)
    response = client.get('/issues/export')

    book = open_workbook(file_contents=response.body)
    assert book.nsheets == 1

    sheet = book.sheets()[0]
    assert sheet.ncols == 4
    assert sheet.nrows == 15

    def as_date(cell):
        return datetime(
            *xldate_as_tuple(cell.value, book.datemode)
        ).date().isoformat()

    def as_datetime(cell):
        return datetime(
            *xldate_as_tuple(cell.value, book.datemode)
        ).isoformat()

    assert sheet.cell(0, 0).value == 'Jahr'
    assert sheet.cell(0, 1).value == 'Nummer'
    assert sheet.cell(0, 2).value == 'Datum'
    assert sheet.cell(0, 3).value == 'Eingabeschluss'

    assert int(sheet.cell(1, 0).value) == 2017
    assert int(sheet.cell(1, 1).value) == 40
    assert as_date(sheet.cell(1, 2)) == '2017-10-06'
    assert as_datetime(sheet.cell(1, 3)) == '2017-10-04T14:00:00'

    assert int(sheet.cell(5, 0).value) == 2017
    assert int(sheet.cell(5, 1).value) == 44
    assert as_date(sheet.cell(5, 2)) == '2017-11-03'
    assert as_datetime(sheet.cell(5, 3)) == '2017-11-01T13:00:00'

    assert int(sheet.cell(13, 0).value) == 2017
    assert int(sheet.cell(13, 1).value) == 52
    assert as_date(sheet.cell(13, 2)) == '2017-12-29'
    assert as_datetime(sheet.cell(13, 3)) == '2017-12-27T13:00:00'

    assert int(sheet.cell(14, 0).value) == 2018
    assert int(sheet.cell(14, 1).value) == 1
    assert as_date(sheet.cell(14, 2)) == '2018-01-05'
    assert as_datetime(sheet.cell(14, 3)) == '2018-01-03T13:00:00'
示例#6
0
def test_view_organizations_permissions(gazette_app):
    client = Client(gazette_app)

    login_publisher(client)
    manage = client.get('/organizations').click('Neu')
    manage.form['title'] = 'XY'
    manage = manage.form.submit().maybe_follow()
    edit_link = manage.click('Bearbeiten', index=0).request.url
    delete_link = manage.click('Löschen', index=0).request.url

    login_editor_1(client)
    client.get('/organizations', status=403)
    client.get(edit_link, status=403)
    client.get(delete_link, status=403)
示例#7
0
def test_view_principal(gazette_app):
    client = Client(gazette_app)

    assert 'Startseite' in client.get('/').maybe_follow()
    assert '<h2>Anmelden</h2>' in client.get('/').maybe_follow()

    login_admin(client)
    assert '/notices' in client.get('/').maybe_follow().request.url

    login_publisher(client)
    assert '/notices' in client.get('/').maybe_follow().request.url

    login_editor_1(client)
    assert '/dashboard' in client.get('/').maybe_follow().request.url
示例#8
0
def test_view_issues_permissions(gazette_app):
    with freeze_time("2017-10-20 12:00"):
        client = Client(gazette_app)

        login_publisher(client)
        manage = client.get('/issues').click('Neu')
        manage.form['number'] = '1'
        manage.form['date_'] = '2017-01-02'
        manage.form['deadline'] = '2017-01-01T12:00'
        manage = manage.form.submit().maybe_follow()
        edit_link = manage.click('Bearbeiten', index=0).request.url
        delete_link = manage.click('Löschen', index=0).request.url

        login_editor_1(client)
        client.get('/issues', status=403)
        client.get(edit_link, status=403)
        client.get(delete_link, status=403)
示例#9
0
def test_view_users_permissions(gazette_app):
    client = Client(gazette_app)

    login_admin(client)
    manage = client.get('/users')
    assert "<h3>Redaktoren</h3>" in manage
    assert "<h3>Herausgeber</h3>" in manage
    edit_editor = manage.click("Bearbeiten", href='editor1').request.url
    delete_editor = manage.click("Löschen", href='editor1').request.url
    edit_publisher = manage.click("Bearbeiten", href='publisher').request.url
    delete_publisher = manage.click("Löschen", href='publisher').request.url

    login_publisher(client)
    manage = client.get('/users')
    assert "<h3>Redaktoren</h3>" in manage
    assert "<h3>Herausgeber</h3>" not in manage
    assert manage.click("Bearbeiten", href='editor1').request.url == \
        edit_editor
    assert manage.click("Löschen", href='editor1').request.url == delete_editor
    client.get(edit_publisher, status=403)
    client.get(delete_publisher, status=403)

    login_editor_1(client)
    client.get('/users', status=403)
    client.get(edit_editor, status=403)
    client.get(edit_publisher, status=403)
    client.get(delete_editor, status=403)
    client.get(delete_publisher, status=403)

    login_editor_2(client)
    client.get('/users', status=403)
    client.get(edit_editor, status=403)
    client.get(edit_publisher, status=403)
    client.get(delete_editor, status=403)
    client.get(delete_publisher, status=403)

    login_editor_3(client)
    client.get('/users', status=403)
    client.get(edit_editor, status=403)
    client.get(edit_publisher, status=403)
    client.get(delete_editor, status=403)
    client.get(delete_publisher, status=403)
示例#10
0
def test_view_notices_pdf_preview(gazette_app):
    with freeze_time("2017-11-01 11:00"):

        client = Client(gazette_app)
        login_publisher(client)

        # new notice
        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = "Erneuerungswahlen"
        manage.form['organization'] = '200'
        manage.form['category'] = '11'
        manage.form['issues'] = ['2017-44']
        manage.form['text'] = "1. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()

        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = "Kantonsratswahlen"
        manage.form['organization'] = '200'
        manage.form['category'] = '11'
        manage.form['issues'] = ['2017-45']
        manage.form['text'] = "10. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()

        response = client.get('/notices/drafted/preview-pdf')
        assert response.headers['Content-Type'] == 'application/pdf'
        assert response.headers['Content-Disposition'] == \
            'inline; filename=amtsblatt-govikon.pdf'

        reader = PdfFileReader(BytesIO(response.body))
        assert [page.extractText() for page in reader.pages] == [
            '© 2017 Govikon\n1\n'
            'xxx\nErneuerungswahlen\n1. Oktober 2017\n'
            'Govikon, 1. Januar 2019\nState Chancellerist\n'
            'xxx\nKantonsratswahlen\n10. Oktober 2017\n'
            'Govikon, 1. Januar 2019\nState Chancellerist\n'
        ]
示例#11
0
def test_view_categories_export(gazette_app):
    client = Client(gazette_app)

    client.get('/categories/export', status=403)

    login_editor_1(client)
    client.get('/categories/export', status=403)

    login_publisher(client)
    response = client.get('/categories/export')

    book = open_workbook(file_contents=response.body)
    assert book.nsheets == 1

    sheet = book.sheets()[0]
    assert sheet.ncols == 4
    assert sheet.nrows == 6

    assert sheet.cell(0, 0).value == 'ID'
    assert sheet.cell(0, 1).value == 'Name'
    assert sheet.cell(0, 2).value == 'Titel'
    assert sheet.cell(0, 3).value == 'Aktiv'

    assert sheet.cell(1, 1).value == '13'
    assert sheet.cell(1, 2).value == 'Commercial Register'
    assert sheet.cell(1, 3).value == 1

    assert sheet.cell(2, 1).value == '10'
    assert sheet.cell(2, 2).value == 'Complaints'
    assert sheet.cell(2, 3).value == 0

    assert sheet.cell(3, 1).value == '11'
    assert sheet.cell(3, 2).value == 'Education'
    assert sheet.cell(3, 3).value == 1

    assert sheet.cell(4, 1).value == '14'
    assert sheet.cell(4, 2).value == 'Elections'
    assert sheet.cell(4, 3).value == 1

    assert sheet.cell(5, 1).value == '12'
    assert sheet.cell(5, 2).value == 'Submissions'
    assert sheet.cell(5, 3).value == 1
示例#12
0
def test_view_groups_permissions(gazette_app):
    client = Client(gazette_app)

    login_admin(client)
    manage = client.get('/groups').click("Neu")
    manage.form['name'] = 'XY'
    manage = manage.form.submit().maybe_follow()
    edit_link = manage.click('Bearbeiten', index=0).request.url
    delete_link = manage.click('Löschen', index=0).request.url

    login_publisher(client)
    manage = client.get('/groups').click("Neu")
    manage.form['name'] = 'YZ'
    manage = manage.form.submit().maybe_follow()
    assert manage.click('Bearbeiten', index=0).request.url == edit_link
    assert manage.click('Löschen', index=0).request.url == delete_link

    login_editor_1(client)
    client.get('/groups', status=403)
    client.get(edit_link, status=403)
    client.get(delete_link, status=403)
示例#13
0
def test_view_notices_publishing_disabled(gazette_app):
    client = Client(gazette_app)
    login_publisher(client)

    assert "notices/published" in client.get('/notices/drafted')
    assert "notices/published" in client.get('/notices/drafted/statistics')

    principal = gazette_app.principal
    principal.publishing = False
    gazette_app.cache.set('principal', principal)

    assert "notices/rejected" in client.get('/notices/drafted')
    assert "notices/published" not in client.get('/notices/drafted')

    assert "notices/rejected" in client.get('/notices/published')
    assert "notices/published" in client.get('/notices/published')

    assert "notices/rejected" in client.get('/notices/drafted/statistics')
    assert "notices/published" not in client.get('/notices/drafted/statistics')

    assert "notices/rejected" in client.get('/notices/published/statistics')
    assert "notices/published" in client.get('/notices/published/statistics')
示例#14
0
def test_view_issues_publish_disabled(gazette_app):
    client = Client(gazette_app)
    login_publisher(client)

    manage = client.get('/issues')
    assert "PDF" in manage
    assert "Veröffentlichen" in manage

    manage = client.get('/issue/2017-40/publish')
    assert "Veröffentlichung ist deaktiviert." not in manage
    assert 'form' in manage

    principal = gazette_app.principal
    principal.publishing = False
    gazette_app.cache.set('principal', principal)

    manage = client.get('/issues')
    assert "PDF" not in manage
    assert "Veröffentlichen" not in manage

    manage = client.get('/issue/2017-40/publish')
    assert "Veröffentlichung ist deaktiviert." in manage
    assert 'form' not in manage
示例#15
0
def test_view_organizations_export(gazette_app):
    client = Client(gazette_app)

    client.get('/organizations/export', status=403)

    login_editor_1(client)
    client.get('/organizations/export', status=403)

    login_publisher(client)
    response = client.get('/organizations/export')

    book = open_workbook(file_contents=response.body)
    assert book.nsheets == 1

    sheet = book.sheets()[0]
    assert sheet.ncols == 6
    assert sheet.nrows == 9

    assert sheet.cell(0, 0).value == 'ID'
    assert sheet.cell(0, 1).value == 'Name'
    assert sheet.cell(0, 2).value == 'Titel'
    assert sheet.cell(0, 3).value == 'Aktiv'
    assert sheet.cell(0, 4).value == 'Externe ID'
    assert sheet.cell(0, 5).value == 'Übergeordnete Organisation'

    assert sheet.cell(1, 1).value == '100'
    assert sheet.cell(1, 2).value == 'State Chancellery'
    assert sheet.cell(1, 3).value == 1
    assert sheet.cell(1, 4).value == ''
    assert sheet.cell(1, 5).value == ''

    assert sheet.cell(2, 1).value == '200'
    assert sheet.cell(2, 2).value == 'Civic Community'
    assert sheet.cell(2, 3).value == 1
    assert sheet.cell(2, 4).value == ''
    assert sheet.cell(2, 5).value == ''

    assert sheet.cell(3, 1).value == '300'
    assert sheet.cell(3, 2).value == 'Municipality'
    assert sheet.cell(3, 3).value == 1
    assert sheet.cell(3, 4).value == ''
    assert sheet.cell(3, 5).value == ''

    assert sheet.cell(4, 1).value == '400'
    assert sheet.cell(4, 2).value == 'Churches'
    assert sheet.cell(4, 3).value == 1
    assert sheet.cell(4, 4).value == ''
    assert sheet.cell(4, 5).value == ''

    assert sheet.cell(5, 1).value == '410'
    assert sheet.cell(5, 2).value == 'Evangelical Reformed Parish'
    assert sheet.cell(5, 3).value == 1
    assert sheet.cell(5, 4).value == ''
    assert int(sheet.cell(5, 5).value) == int(sheet.cell(4, 0).value)

    assert sheet.cell(6, 1).value == '420'
    assert sheet.cell(6, 2).value == 'Sikh Community'
    assert sheet.cell(6, 3).value == 0
    assert sheet.cell(6, 4).value == '4'
    assert int(sheet.cell(6, 5).value) == int(sheet.cell(4, 0).value)

    assert sheet.cell(7, 1).value == '430'
    assert sheet.cell(7, 2).value == 'Catholic Parish'
    assert sheet.cell(7, 3).value == 1
    assert sheet.cell(7, 4).value == ''
    assert int(sheet.cell(7, 5).value) == int(sheet.cell(4, 0).value)

    assert sheet.cell(8, 1).value == '500'
    assert sheet.cell(8, 2).value == 'Corporation'
    assert sheet.cell(8, 3).value == 1
    assert sheet.cell(8, 4).value == ''
    assert sheet.cell(8, 5).value == ''
示例#16
0
def test_view_notices_filter(gazette_app):
    with freeze_time("2017-11-01 11:00"):

        client = Client(gazette_app)

        login_editor_1(client)
        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = "Erneuerungswahlen"
        manage.form['organization'] = '100'
        manage.form['category'] = '11'
        manage.form['issues'] = ['2017-44', '2017-45']
        manage.form['text'] = "1. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()
        client.get('/notice/erneuerungswahlen/submit').form.submit()

        login_editor_2(client)
        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = "Kantonsratswahlen"
        manage.form['organization'] = '200'
        manage.form['category'] = '12'
        manage.form['issues'] = ['2017-45', '2017-46']
        manage.form['text'] = "9. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()
        client.get('/notice/kantonsratswahlen/submit').form.submit()

        login_publisher(client)
        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = "Regierungsratswahlen"
        manage.form['organization'] = '300'
        manage.form['category'] = '13'
        manage.form['issues'] = ['2017-47']
        manage.form['text'] = "10. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()
        client.get('/notice/regierungsratswahlen/submit').form.submit()

        manage = client.get('/notice/kantonsratswahlen/edit')
        manage.form['text'] = "10. Oktober 2017"
        manage.form.submit()

        manage = client.get('/notices/submitted')
        assert "Erneuerungswahlen" in manage
        assert "Kantonsratswahlen" in manage
        assert "Regierungsratswahlen" in manage

        assert '<option value="2017-11-03">2017-44</option>' in manage
        assert '<option value="2017-11-10">2017-45</option>' in manage
        assert '<option value="2017-11-17">2017-46</option>' in manage
        assert '<option value="2017-11-24">2017-47</option>' in manage
        assert '<option value="2017-12-01">2017-48</option>' not in manage

        assert '<option value="100">State Chancellery</option>' in manage
        assert '<option value="200">Civic Community</option>' in manage
        assert '<option value="300">Municipality</option>' in manage
        assert '<option value="500">Corporation</option>' not in manage

        assert '<option value="11">Education</option>' in manage
        assert '<option value="12">Submissions</option>' in manage
        assert '<option value="13">Commercial Register</option>' in manage
        assert '<option value="14">Elections</option>' not in manage

        manage.form['term'] = 'neuerun'
        manage = manage.form.submit().maybe_follow()
        assert "Erneuerungswahlen" in manage
        assert "Kantonsratswahlen" not in manage
        assert "Regierungsratswahlen" not in manage

        manage = client.get('/notices/submitted')
        manage.form['term'] = '10. Oktober'
        manage = manage.form.submit().maybe_follow()
        assert "Erneuerungswahlen" not in manage
        assert "Kantonsratswahlen" in manage
        assert "Regierungsratswahlen" in manage

        manage = client.get('/notices/submitted')
        manage.form['term'] = '10. Oktober'
        manage.form['categories'] = '12'
        manage = manage.form.submit().maybe_follow()
        assert "Erneuerungswahlen" not in manage
        assert "Kantonsratswahlen" in manage
        assert "Regierungsratswahlen" not in manage

        manage = client.get('/notices/submitted')
        manage.form['term'] = '10. Oktober'
        manage.form['organizations'] = '200'
        manage = manage.form.submit().maybe_follow()
        assert "Erneuerungswahlen" not in manage
        assert "Kantonsratswahlen" in manage
        assert "Regierungsratswahlen" not in manage

        manage = client.get('/notices/submitted')
        manage.form['term'] = '10. Oktober'
        manage.form['from_date'] = '2017-11-17'
        manage.form['to_date'] = '2017-11-17'
        manage = manage.form.submit().maybe_follow()
        assert "Erneuerungswahlen" not in manage
        assert "Kantonsratswahlen" in manage
        assert "Regierungsratswahlen" not in manage

        manage = client.get('/notices/submitted')
        manage.form['own'] = True
        manage = manage.form.submit().maybe_follow()
        assert "Erneuerungswahlen" not in manage
        assert "Kantonsratswahlen" in manage
        assert "Regierungsratswahlen" in manage
示例#17
0
def test_view_notices(gazette_app):
    with freeze_time("2017-11-01 11:00"):

        publisher = Client(gazette_app)
        login_publisher(publisher)

        editor_1 = Client(gazette_app)
        login_editor_1(editor_1)

        editor_2 = Client(gazette_app)
        login_editor_2(editor_2)

        editor_3 = Client(gazette_app)
        login_editor_3(editor_3)

        for user in (publisher, editor_1, editor_2, editor_3):
            for state in ('drafted', 'submitted', 'rejected', 'accepted',
                          'published'):
                assert "Keine Meldungen" in user.get('/notices/' + state)

        # new notices
        manage = editor_1.get('/notices/drafted/new-notice')
        manage.form['title'] = "Erneuerungswahlen"
        manage.form['organization'] = '200'
        manage.form['category'] = '11'
        manage.form['issues'] = ['2017-44', '2017-45']
        manage.form['text'] = "1. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()

        manage = editor_3.get('/notices/drafted/new-notice')
        manage.form['title'] = "Kantonsratswahlen"
        manage.form['organization'] = '200'
        manage.form['category'] = '11'
        manage.form['issues'] = ['2017-44', '2017-45']
        manage.form['text'] = "1. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()

        for user in (publisher, editor_1, editor_2, editor_3):
            for state in ('submitted', 'rejected', 'accepted', 'published'):
                assert "Keine Meldungen" in user.get('/notices/' + state)

        assert "Erneuerungswahlen" in publisher.get('/notices/drafted')
        assert "Erneuerungswahlen" in editor_1.get('/notices/drafted')
        assert "Erneuerungswahlen" in editor_2.get('/notices/drafted')
        assert "Erneuerungswahlen" not in editor_3.get('/notices/drafted')
        assert "Kantonsratswahlen" in publisher.get('/notices/drafted')
        assert "Kantonsratswahlen" not in editor_1.get('/notices/drafted')
        assert "Kantonsratswahlen" not in editor_1.get('/notices/drafted')
        assert "Kantonsratswahlen" in editor_3.get('/notices/drafted')

        # submit notices
        editor_1.get('/notice/erneuerungswahlen/submit').form.submit()
        editor_3.get('/notice/kantonsratswahlen/submit').form.submit()

        for user in (publisher, editor_1, editor_2, editor_3):
            for state in ('drafted', 'rejected', 'accepted', 'published'):
                assert "Keine Meldungen" in user.get('/notices/' + state)

        assert "Erneuerungswahlen" in publisher.get('/notices/submitted')
        assert "Erneuerungswahlen" in editor_1.get('/notices/submitted')
        assert "Erneuerungswahlen" in editor_2.get('/notices/submitted')
        assert "Erneuerungswahlen" not in editor_3.get('/notices/submitted')
        assert "Kantonsratswahlen" in publisher.get('/notices/submitted')
        assert "Kantonsratswahlen" not in editor_1.get('/notices/submitted')
        assert "Kantonsratswahlen" not in editor_2.get('/notices/submitted')
        assert "Kantonsratswahlen" in editor_3.get('/notices/submitted')

        # reject notices
        manage = publisher.get('/notice/erneuerungswahlen/reject')
        manage.form['comment'] = 'comment'
        manage.form.submit()

        manage = publisher.get('/notice/kantonsratswahlen/reject')
        manage.form['comment'] = 'comment'
        manage.form.submit()

        for user in (publisher, editor_1, editor_2, editor_3):
            for state in ('drafted', 'submitted', 'accepted', 'published'):
                assert "Keine Meldungen" in user.get('/notices/' + state)

        assert "Erneuerungswahlen" in publisher.get('/notices/rejected')
        assert "Erneuerungswahlen" in editor_1.get('/notices/rejected')
        assert "Erneuerungswahlen" in editor_2.get('/notices/rejected')
        assert "Erneuerungswahlen" not in editor_3.get('/notices/rejected')
        assert "Kantonsratswahlen" in publisher.get('/notices/rejected')
        assert "Kantonsratswahlen" not in editor_1.get('/notices/rejected')
        assert "Kantonsratswahlen" not in editor_2.get('/notices/rejected')
        assert "Kantonsratswahlen" in editor_3.get('/notices/rejected')

        # submit & accept notices
        editor_1.get('/notice/erneuerungswahlen/submit').form.submit()
        publisher.get('/notice/erneuerungswahlen/accept').form.submit()
        editor_3.get('/notice/kantonsratswahlen/submit').form.submit()
        publisher.get('/notice/kantonsratswahlen/accept').form.submit()

        for user in (publisher, editor_1, editor_2, editor_3):
            for state in ('drafted', 'submitted', 'rejected', 'published'):
                assert "Keine Meldungen" in user.get('/notices/' + state)

        assert "Erneuerungswahlen" in publisher.get('/notices/accepted')
        assert "Erneuerungswahlen" in editor_1.get('/notices/accepted')
        assert "Erneuerungswahlen" in editor_2.get('/notices/accepted')
        assert "Erneuerungswahlen" not in editor_3.get('/notices/accepted')
        assert "Kantonsratswahlen" in publisher.get('/notices/accepted')
        assert "Kantonsratswahlen" not in editor_1.get('/notices/accepted')
        assert "Kantonsratswahlen" not in editor_2.get('/notices/accepted')
        assert "Kantonsratswahlen" in editor_3.get('/notices/accepted')

        # publish notices
        assert "Erneuerungswahlen" in publisher.get('/notices/accepted')
        assert "Erneuerungswahlen" in editor_1.get('/notices/accepted')
        assert "Erneuerungswahlen" in editor_2.get('/notices/accepted')
        assert "Erneuerungswahlen" not in editor_3.get('/notices/accepted')
        assert "Kantonsratswahlen" in publisher.get('/notices/accepted')
        assert "Kantonsratswahlen" not in editor_1.get('/notices/accepted')
        assert "Kantonsratswahlen" not in editor_2.get('/notices/accepted')
        assert "Kantonsratswahlen" in editor_3.get('/notices/accepted')
示例#18
0
def test_view_dashboard(gazette_app):
    editor_1 = Client(gazette_app)
    login_editor_1(editor_1)

    editor_2 = Client(gazette_app)
    login_editor_2(editor_2)

    editor_3 = Client(gazette_app)
    login_editor_3(editor_3)

    publisher = Client(gazette_app)
    login_publisher(publisher)

    # Group: Testgroup (editor_1 & editor_2)

    with freeze_time("2017-10-20 12:00"):
        deadline = ("<span>Nächster Eingabeschluss</span>: "
                    "<strong>Mittwoch 25.10.2017 14:00</strong>")

        manage = editor_1.get('/').maybe_follow()
        assert "Keine Meldungen." in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage
        assert deadline in manage

        # new notice
        manage = manage.click("Neu")
        assert deadline in manage
        manage.form['title'] = "Erneuerungswahlen"
        manage.form['organization'] = '100'
        manage.form['category'] = '11'
        manage.form['issues'] = ['2017-44', '2017-45']
        manage.form['text'] = "1. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()

        manage = editor_1.get('/').maybe_follow()
        assert "Keine Meldungen." not in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" in manage
        assert "<h3>Eingereicht</h3>" not in manage

        manage = editor_2.get('/').maybe_follow()  # same group
        assert "Keine Meldungen." not in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" in manage
        assert "<h3>Eingereicht</h3>" not in manage

        manage = editor_3.get('/').maybe_follow()  # other group
        assert "Keine Meldungen." in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage

    with freeze_time("2017-11-01 11:00"):
        manage = editor_1.get('/').maybe_follow()
        assert ("Sie haben Meldungen in Arbeit, für welche der "
                "Eingabeschluss bald erreicht ist.") in manage

    with freeze_time("2017-11-02 12:00"):
        deadline = ("<span>Nächster Eingabeschluss</span>: "
                    "<strong>Mittwoch 08.11.2017 13:00</strong>")

        manage = editor_1.get('/').maybe_follow()
        assert ("Sie haben Meldungen in Arbeit mit vergangenen Ausgaben."
                ) in manage
        assert ("Sie haben Meldungenen in Arbeit, für welche der "
                "Eingabeschluss bald erreicht ist.") not in manage

        # edit notice
        manage = editor_1.get('/notice/erneuerungswahlen').click("Bearbeiten")
        assert deadline in manage
        manage.form['issues'] = ['2017-45']
        manage.form.submit()

        # submit notice
        manage = editor_1.get('/').maybe_follow()
        manage.click("Erneuerungswahlen").click("Einreichen").form.submit()

        manage = editor_1.get('/').maybe_follow()
        assert "Keine Meldungen." not in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" in manage

        manage = editor_2.get('/').maybe_follow()  # same group
        assert "Keine Meldungen." not in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" in manage

        manage = editor_3.get('/').maybe_follow()  # other group
        assert "Keine Meldungen." in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage

        # reject notice
        manage = publisher.get('/').maybe_follow().click("Erneuerungswahlen")
        manage = manage.click("Zurückweisen")
        manage.form['comment'] = 'comment'
        manage = manage.form.submit()

        manage = editor_1.get('/').maybe_follow()
        assert "Keine Meldungen." not in manage
        assert "<h3>Zurückgewiesen</h3>" in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage
        assert "Sie haben zurückgewiesene Meldungen." in manage

        manage = editor_2.get('/').maybe_follow()  # same group
        assert "Keine Meldungen." not in manage
        assert "<h3>Zurückgewiesen</h3>" in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage
        assert "Sie haben zurückgewiesene Meldungen." in manage

        manage = editor_3.get('/').maybe_follow()  # other group
        assert "Keine Meldungen." in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage

        # submit & accept notice
        manage = editor_1.get('/').maybe_follow().click("Erneuerungswahlen")
        manage.click("Einreichen").form.submit()

        manage = publisher.get('/').maybe_follow().click("Erneuerungswahlen")
        manage.click("Annehmen").form.submit()

        manage = editor_1.get('/').maybe_follow()
        assert "Keine Meldungen." in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage
        assert "Sie haben zurückgewiesene Meldungen." not in manage

        manage = editor_2.get('/').maybe_follow()  # same group
        assert "Keine Meldungen." in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage
        assert "Sie haben zurückgewiesene Meldungen." not in manage

        manage = editor_3.get('/').maybe_follow()  # other group
        assert "Keine Meldungen." in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage

    # Group: None (editor_3)

    with freeze_time("2017-10-20 12:00"):

        manage = editor_3.get('/').maybe_follow()
        assert "Keine Meldungen." in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage

        # new notice
        manage = manage.click("Neu")
        manage.form['title'] = "Kantonsratswahlen"
        manage.form['organization'] = '100'
        manage.form['category'] = '11'
        manage.form['issues'] = ['2017-44', '2017-45']
        manage.form['text'] = "1. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()

        manage = editor_1.get('/').maybe_follow()  # other group
        assert "Keine Meldungen." in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage

        manage = editor_2.get('/').maybe_follow()  # other group
        assert "Keine Meldungen." in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" not in manage
        assert "<h3>Eingereicht</h3>" not in manage

        manage = editor_3.get('/').maybe_follow()
        assert "Keine Meldungen." not in manage
        assert "<h3>Zurückgewiesen</h3>" not in manage
        assert "<h3>in Arbeit</h3>" in manage
        assert "<h3>Eingereicht</h3>" not in manage
示例#19
0
def test_view_notices_order(gazette_app):
    def get_items(page):
        return [a.text for a in page.pyquery('td strong a')]

    def get_ordering(page):
        return {
            r['order'][0]: r['direction'][0]
            for r in [
                parse_qs(urlparse(a.attrib['href']).query)
                for a in page.pyquery('th a')
            ]
        }

    with freeze_time("2017-11-01 11:00"):

        client = Client(gazette_app)
        login_publisher(client)

        # new notice
        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = "Erneuerungswahlen"
        manage.form['organization'] = '100'
        manage.form['category'] = '11'
        manage.form['issues'] = ['2017-44', '2017-46']
        manage.form['text'] = "1. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()
        client.get('/notice/erneuerungswahlen/submit').form.submit()
        client.get('/notice/erneuerungswahlen/accept').form.submit()

        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = "Kantonsratswahlen"
        manage.form['organization'] = '200'
        manage.form['category'] = '13'
        manage.form['issues'] = ['2017-45', '2017-47']
        manage.form['text'] = "10. Oktober 2017"
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage.form.submit()
        client.get('/notice/kantonsratswahlen/submit').form.submit()
        client.get('/notice/kantonsratswahlen/accept').form.submit()

        # Default sorting
        ordered = client.get('/notices/accepted')
        assert get_items(ordered) == ["Erneuerungswahlen", "Kantonsratswahlen"]
        assert get_ordering(client.get('/notices/accepted')) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'desc'
        }

        # Invalid sorting
        ordered = client.get('/notices/accepted?order=xxx')
        assert get_items(ordered) == ["Erneuerungswahlen", "Kantonsratswahlen"]
        assert get_ordering(client.get('/notices/accepted')) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'desc'
        }

        # Omit direction
        ordered = client.get('/notices/accepted?order=category')
        assert get_items(ordered) == ["Kantonsratswahlen", "Erneuerungswahlen"]
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'desc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }

        # Sort by
        # ... title
        url = '/notices/accepted?order={}&direction={}'
        ordered = client.get(url.format('title', 'asc'))
        assert get_items(ordered) == ["Erneuerungswahlen", "Kantonsratswahlen"]
        assert get_ordering(ordered) == {
            'title': 'desc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }

        ordered = client.get(url.format('title', 'desc'))
        assert get_items(ordered) == ["Kantonsratswahlen", "Erneuerungswahlen"]
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }

        # ... organization
        ordered = client.get(url.format('organization', 'asc'))
        assert get_items(ordered) == ["Kantonsratswahlen", "Erneuerungswahlen"]
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'desc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }

        ordered = client.get(url.format('organization', 'desc'))
        assert get_items(ordered) == ["Erneuerungswahlen", "Kantonsratswahlen"]
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }

        # ... category
        ordered = client.get(url.format('category', 'asc'))
        assert get_items(ordered) == ["Kantonsratswahlen", "Erneuerungswahlen"]
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'desc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }

        ordered = client.get(url.format('category', 'desc'))
        assert get_items(ordered) == ["Erneuerungswahlen", "Kantonsratswahlen"]
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }

        # ... group
        ordered = client.get(url.format('group.name', 'asc'))
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'desc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }

        ordered = client.get(url.format('category', 'desc'))
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }

        # ... user
        ordered = client.get(url.format('user.name', 'asc'))
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'desc',
            'first_issue': 'asc'
        }

        ordered = client.get(url.format('category', 'desc'))
        assert get_items(ordered) == ["Erneuerungswahlen", "Kantonsratswahlen"]
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }

        # ... issues
        ordered = client.get(url.format('first_issue', 'asc'))
        assert get_items(ordered) == ["Erneuerungswahlen", "Kantonsratswahlen"]
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'desc'
        }

        ordered = client.get(url.format('first_issue', 'desc'))
        assert get_items(ordered) == ["Kantonsratswahlen", "Erneuerungswahlen"]
        assert get_ordering(ordered) == {
            'title': 'asc',
            'organization': 'asc',
            'category': 'asc',
            'group.name': 'asc',
            'user.name': 'asc',
            'first_issue': 'asc'
        }
示例#20
0
def test_view_issues_publish(gazette_app):
    with freeze_time("2017-11-01 12:00"):
        client = Client(gazette_app)
        login_publisher(client)

        for number, issues, print_only, accept in (
            (0, (44, 45), False, True),
            (1, (45, 46), True, True),
            (2, (45,), False, False),
        ):
            slug = 'notice-{}'.format(number)
            manage = client.get('/notices/drafted/new-notice')
            manage.form['title'] = slug
            manage.form['organization'] = '200'
            manage.form['category'] = '13'
            manage.form['issues'] = ['2017-{}'.format(i) for i in issues]
            manage.form['text'] = 'Text'
            manage.form['author_place'] = 'Govikon'
            manage.form['author_name'] = 'State Chancellerist'
            manage.form['author_date'] = '2019-01-01'
            manage.form['print_only'] = print_only
            manage = manage.form.submit()
            client.get('/notice/{}/submit'.format(slug)).form.submit()
            if accept:
                client.get('/notice/{}/accept'.format(slug)).form.submit()

        # publish 44
        manage = client.get('/issues').click('Veröffentlichen', index=0)
        manage = manage.form.submit().maybe_follow()
        assert "Ausgabe veröffentlicht." in manage
        assert "2017-44.pdf" in manage
        assert "2017-44.pdf (Stopp Internet)" in manage

        manage = manage.click(href='2017-44.pdf')
        assert manage.content_type == 'application/pdf'
        reader = PdfFileReader(BytesIO(manage.body))
        text = ''.join([page.extractText() for page in reader.pages])
        assert text == (
            'onegov.ch\n'
            '© 2017 Govikon\n'
            '1\nAmtsblatt Nr. 44, 03.11.2017\n'
            'Das elektronischer Amtsblatt steht unter www.amtsblattzug.ch '
            'zur Verfügung.\n'
            'Civic Community\n'
            'Commercial Register\n'
            '1\nnotice-0\n'
            'Text\n'
            'Govikon, 1. Januar 2019\n'
            'State Chancellerist\n'
        )

        manage = client.get('/issues')
        manage = manage.click('2017-44.pdf', href='print-only-pdf')
        assert manage.content_type == 'application/pdf'
        reader = PdfFileReader(BytesIO(manage.body))
        text = ''.join([page.extractText() for page in reader.pages])
        assert text == (
            'onegov.ch\n'
            '© 2017 Govikon\n'
            '1\nAmtsblatt Nr. 44, 03.11.2017\n'
            'Das elektronischer Amtsblatt steht unter www.amtsblattzug.ch '
            'zur Verfügung.\n'
        )

        notice_0 = client.get('/notice/notice-0')
        notice_1 = client.get('/notice/notice-1')
        notice_2 = client.get('/notice/notice-2')
        assert '<li>Nr. 44, 03.11.2017 / 1</li>' in notice_0
        assert '<li>Nr. 45, 10.11.2017</li>' in notice_0
        assert '<li>Nr. 45, 10.11.2017</li>' in notice_1
        assert '<li>Nr. 46, 17.11.2017</li>' in notice_1
        assert '<li>Nr. 45, 10.11.2017</li>' in notice_2

        # publish 46
        manage = client.get('/issues').click('Veröffentlichen', index=2)
        manage = manage.form.submit().maybe_follow()
        assert "Ausgabe veröffentlicht." in manage
        assert "2017-46.pdf" in manage
        assert "2017-46.pdf (Stopp Internet)" in manage

        manage = manage.click(href='2017-46.pdf')
        assert manage.content_type == 'application/pdf'
        reader = PdfFileReader(BytesIO(manage.body))
        text = ''.join([page.extractText() for page in reader.pages])
        assert text == (
            'onegov.ch\n'
            '© 2017 Govikon\n'
            '1\nAmtsblatt Nr. 46, 17.11.2017\n'
            'Das elektronischer Amtsblatt steht unter www.amtsblattzug.ch '
            'zur Verfügung.\n'
            '1 Publikation(en) mit besonders schützenswerten Daten sind '
            'online nicht verfügbar. Sie stehen\nin Papierform bei der '
            'Staatskanzlei, Seestrasse 2, 6300 Zug, zur Verfügung oder '
            'können unter\[email protected] abonniert werden.\n'
            'Civic Community\n'
            'Commercial Register\n'
            '2\nDiese Meldung ist nur in der Papierversion erhältlich.\n'
        )

        manage = client.get('/issues')
        manage = manage.click('2017-46.pdf', href='print-only-pdf')
        assert manage.content_type == 'application/pdf'
        reader = PdfFileReader(BytesIO(manage.body))
        text = ''.join([page.extractText() for page in reader.pages])
        assert text == (
            'onegov.ch\n'
            '© 2017 Govikon\n'
            '1\nAmtsblatt Nr. 46, 17.11.2017\n'
            '1 Publikation(en) mit besonders schützenswerten Daten gemäss '
            'BGS 152.3 §7 Abs. 2.\n'
            'Das elektronischer Amtsblatt steht unter www.amtsblattzug.ch '
            'zur Verfügung.\n'
            'Civic Community\n'
            'Commercial Register\n'
            '2\nnotice-1\n'
            'Text\n'
            'Govikon, 1. Januar 2019\n'
            'State Chancellerist\n'
        )

        notice_0 = client.get('/notice/notice-0')
        notice_1 = client.get('/notice/notice-1')
        notice_2 = client.get('/notice/notice-2')
        assert '<li>Nr. 44, 03.11.2017 / 1</li>' in notice_0
        assert '<li>Nr. 45, 10.11.2017</li>' in notice_0
        assert '<li>Nr. 45, 10.11.2017</li>' in notice_1
        assert '<li>Nr. 46, 17.11.2017 / 2</li>' in notice_1
        assert '<li>Nr. 45, 10.11.2017</li>' in notice_2

        # publish 45
        manage = client.get('/issues').click('Veröffentlichen', index=1)
        assert "Diese Ausgabe hat eingereichte Meldungen!" in manage
        manage = manage.form.submit().maybe_follow()
        assert "Ausgabe veröffentlicht." in manage
        assert "2017-45.pdf" in manage
        assert "2017-45.pdf (Stopp Internet)" in manage

        manage = manage.click(href='2017-45.pdf')
        assert manage.content_type == 'application/pdf'
        reader = PdfFileReader(BytesIO(manage.body))
        text = ''.join([page.extractText() for page in reader.pages])
        assert text == (
            'onegov.ch\n'
            '© 2017 Govikon\n'
            '1\nAmtsblatt Nr. 45, 10.11.2017\n'
            'Das elektronischer Amtsblatt steht unter www.amtsblattzug.ch '
            'zur Verfügung.\n'
            '1 Publikation(en) mit besonders schützenswerten Daten sind '
            'online nicht verfügbar. Sie stehen\nin Papierform bei der '
            'Staatskanzlei, Seestrasse 2, 6300 Zug, zur Verfügung oder '
            'können unter\[email protected] abonniert werden.\n'
            'Civic Community\n'
            'Commercial Register\n'
            '2\nnotice-0\n'
            'Text\n'
            'Govikon, 1. Januar 2019\n'
            'State Chancellerist\n'
            '3\nDiese Meldung ist nur in der Papierversion erhältlich.\n'
        )

        manage = client.get('/issues')
        manage = manage.click('2017-45.pdf', href='print-only-pdf')
        assert manage.content_type == 'application/pdf'
        reader = PdfFileReader(BytesIO(manage.body))
        text = ''.join([page.extractText() for page in reader.pages])
        assert text == (
            'onegov.ch\n'
            '© 2017 Govikon\n'
            '1\nAmtsblatt Nr. 45, 10.11.2017\n'
            '1 Publikation(en) mit besonders schützenswerten Daten gemäss '
            'BGS 152.3 §7 Abs. 2.\n'
            'Das elektronischer Amtsblatt steht unter www.amtsblattzug.ch '
            'zur Verfügung.\n'
            'Civic Community\n'
            'Commercial Register\n'
            '3\nnotice-1\n'
            'Text\n'
            'Govikon, 1. Januar 2019\n'
            'State Chancellerist\n'
        )

        notice_0 = client.get('/notice/notice-0')
        notice_1 = client.get('/notice/notice-1')
        notice_2 = client.get('/notice/notice-2')
        assert '<li>Nr. 44, 03.11.2017 / 1</li>' in notice_0
        assert '<li>Nr. 45, 10.11.2017 / 2</li>' in notice_0
        assert '<li>Nr. 45, 10.11.2017 / 3</li>' in notice_1
        assert '<li>Nr. 46, 17.11.2017 / 2</li>' in notice_1
        assert '<li>Nr. 45, 10.11.2017</li>' in notice_2  # submitted

        # re-publish 46
        manage = client.get('/issues').click('Veröffentlichen', index=2)
        assert "Diese Ausgabe hat bereits ein PDF!" in manage
        assert "Diese Ausgabe hat bereits Publikationsnummern!" in manage
        manage = manage.form.submit().maybe_follow()
        assert "Ausgabe veröffentlicht." in manage
        assert "2017-46.pdf" in manage
        assert "2017-46.pdf (Stopp Internet)" in manage
        assert "Publikationsnummern haben geändert" in manage

        manage = manage.click(href='2017-46.pdf')
        assert manage.content_type == 'application/pdf'
        reader = PdfFileReader(BytesIO(manage.body))
        text = ''.join([page.extractText() for page in reader.pages])
        assert text == (
            'onegov.ch\n'
            '© 2017 Govikon\n'
            '1\nAmtsblatt Nr. 46, 17.11.2017\n'
            'Das elektronischer Amtsblatt steht unter www.amtsblattzug.ch '
            'zur Verfügung.\n'
            '1 Publikation(en) mit besonders schützenswerten Daten sind '
            'online nicht verfügbar. Sie stehen\nin Papierform bei der '
            'Staatskanzlei, Seestrasse 2, 6300 Zug, zur Verfügung oder '
            'können unter\[email protected] abonniert werden.\n'
            'Civic Community\n'
            'Commercial Register\n'
            '4\nDiese Meldung ist nur in der Papierversion erhältlich.\n'
        )

        manage = client.get('/issues')
        manage = manage.click('2017-46.pdf', href='print-only-pdf')
        assert manage.content_type == 'application/pdf'
        reader = PdfFileReader(BytesIO(manage.body))
        text = ''.join([page.extractText() for page in reader.pages])

        assert text == (
            'onegov.ch\n'
            '© 2017 Govikon\n'
            '1\nAmtsblatt Nr. 46, 17.11.2017\n'
            '1 Publikation(en) mit besonders schützenswerten Daten gemäss '
            'BGS 152.3 §7 Abs. 2.\n'
            'Das elektronischer Amtsblatt steht unter www.amtsblattzug.ch '
            'zur Verfügung.\n'
            'Civic Community\n'
            'Commercial Register\n'
            '4\nnotice-1\n'
            'Text\n'
            'Govikon, 1. Januar 2019\n'
            'State Chancellerist\n'
        )

        notice_0 = client.get('/notice/notice-0')
        notice_1 = client.get('/notice/notice-1')
        notice_2 = client.get('/notice/notice-2')
        assert '<li>Nr. 44, 03.11.2017 / 1</li>' in notice_0
        assert '<li>Nr. 45, 10.11.2017 / 2</li>' in notice_0
        assert '<li>Nr. 45, 10.11.2017 / 3</li>' in notice_1
        assert '<li>Nr. 46, 17.11.2017 / 4</li>' in notice_1
        assert '<li>Nr. 45, 10.11.2017</li>' in notice_2  # submitted
示例#21
0
def test_view_notices_statistics(gazette_app):

    editor = Client(gazette_app)
    login_editor_3(editor)  # this has no group

    publisher = Client(gazette_app)
    login_publisher(publisher)

    def statistic(state, sheet_name, qs=None):
        result = publisher.get('/notices/{}/statistics-xlsx?{}'.format(
            state, qs or ''))
        book = open_workbook(file_contents=result.body)
        for sheet in book.sheets():
            if sheet.name == sheet_name:
                return [[
                    sheet.cell(row, col).value for col in range(sheet.ncols)
                ] for row in range(sheet.nrows)]

    # No notices yet
    states = ('drafted', 'submitted', 'accepted', 'rejected')
    for s in states:
        editor.get('/notices/{}/statistics'.format(s), status=403)
        editor.get('/notices/{}/statistics-xlsx'.format(s), status=403)

        publisher.get('/notices/{}/statistics'.format(s))

        assert statistic(s, 'Organisationen') == [['Organisation', 'Anzahl']]
        assert statistic(s, 'Rubriken') == [['Rubrik', 'Anzahl']]
        assert statistic(s, 'Gruppen') == [['Gruppe', 'Anzahl']]

    # Add users and groups
    admin = Client(gazette_app)
    login_admin(admin)
    manage = admin.get('/groups').click("Neu")
    for group in ('A', 'B', 'C'):
        manage.form['name'] = group
        manage.form.submit()

    manage = admin.get('/users').click("Neu")
    for user, group in (
        ('*****@*****.**', 'B'),
        ('*****@*****.**', 'B'),
        ('*****@*****.**', 'C'),
    ):
        manage.form['role'] = 'member'
        manage.form['name'] = user
        manage.form['username'] = user
        manage.form['group'] = dict(
            (x[2], x[0]) for x in manage.form['group'].options)[group]
        with patch('onegov.gazette.views.users.random_password') as password:
            password.return_value = 'hunter2'
            manage.form.submit().maybe_follow()

    user_1 = Client(gazette_app)
    user_2 = Client(gazette_app)
    user_3 = Client(gazette_app)
    for user, client in (
        ('*****@*****.**', user_1),
        ('*****@*****.**', user_2),
        ('*****@*****.**', user_3),
    ):
        login = client.get('/auth/login')
        login.form['username'] = user
        login.form['password'] = '******'
        login.form.submit()

    # Add notices
    with freeze_time("2017-11-01 11:00"):
        for (organization, category, submit, user, issues) in (
            ('100', '13', False, editor, ['2017-44']),
            ('100', '13', False, user_1, ['2017-45']),
            ('100', '11', False, user_1, ['2017-46']),
            ('200', '11', False, user_1, ['2017-47']),
            ('100', '12', True, user_1, ['2017-47', '2017-45']),
            ('100', '14', True, user_1, ['2017-45', '2017-46']),
            ('300', '14', True, user_1, ['2017-46']),
            ('100', '11', False, user_2, ['2017-47']),
            ('100', '12', True, user_2, ['2017-47']),
            ('200', '14', False, user_2, ['2017-45', '2017-47']),
            ('100', '14', True, user_3, ['2017-46']),
            ('100', '12', True, user_3, ['2017-47']),
            ('100', '14', False, user_3, ['2017-47']),
            ('100', '14', True, user_3, ['2017-45', '2017-46', '2017-47']),
        ):
            manage = user.get('/notices/drafted/new-notice')
            manage.form['title'] = "Titel"
            manage.form['organization'] = organization
            manage.form['category'] = category
            manage.form['text'] = "Text"
            manage.form['author_place'] = 'Govikon'
            manage.form['author_name'] = 'State Chancellerist'
            manage.form['author_date'] = '2019-01-01'
            manage.form['issues'] = issues
            manage = manage.form.submit().maybe_follow()
            if submit:
                manage.click("Einreichen").form.submit()

    for s in ('rejected', 'accepted'):
        assert statistic(s, 'Organisationen') == [['Organisation', 'Anzahl']]
        assert statistic(s, 'Rubriken') == [['Rubrik', 'Anzahl']]
        assert statistic(s, 'Gruppen') == [['Gruppe', 'Anzahl']]

    assert publisher.get('/notices/drafted/statistics')
    assert publisher.get('/notices/submitted/statistics')
    assert publisher.get('/notices/published/statistics')

    # organizations/drafted: 5 x 100, 3 x 200
    assert statistic('drafted',
                     'Organisationen') == [['Organisation', 'Anzahl'],
                                           ['Civic Community', 3],
                                           ['State Chancellery', 5]]

    # organizations/submitted: 10 x 100, 1 x 300
    assert statistic('submitted', 'Organisationen') == [
        ['Organisation', 'Anzahl'],
        ['Municipality', 1],
        ['State Chancellery', 10],
    ]

    # organizations/submitted/2017-45/46: 6 x 100, 1 x 300
    assert statistic('submitted', 'Organisationen',
                     'from_date=2017-11-10&to_date=2017-11-17') == [
                         ['Organisation', 'Anzahl'],
                         ['Municipality', 1],
                         ['State Chancellery', 6],
                     ]

    # categories/drafted: 3 x 11, 2 x 13, 3 x 14
    assert statistic('drafted', 'Rubriken') == [
        ['Rubrik', 'Anzahl'],
        ['Commercial Register', 2],
        ['Education', 3],
        ['Elections', 3],
    ]

    # categories/submitted: 4 x 12, 7 x 14
    assert statistic('submitted', 'Rubriken') == [
        ['Rubrik', 'Anzahl'],
        ['Elections', 7],
        ['Submissions', 4],
    ]

    # categories/submitted/2017-45/46: 1 x 12, 6 x 14
    assert statistic('submitted', 'Rubriken',
                     'from_date=2017-11-10&to_date=2017-11-17') == [
                         ['Rubrik', 'Anzahl'],
                         ['Elections', 6],
                         ['Submissions', 1],
                     ]

    # groups/drafted: 1 x w/o, 6 x B, 1 x C
    assert '>5</td>' in publisher.get('/notices/drafted/statistics')
    assert statistic('drafted', 'Gruppen') == [
        ['Gruppe', 'Anzahl'],
        ['B', 6],
        ['C', 1],
    ]

    # groups/submitted: 6 x B, 5 x C
    assert '>4</td>' in publisher.get('/notices/submitted/statistics')
    assert statistic('submitted', 'Gruppen') == [
        ['Gruppe', 'Anzahl'],
        ['B', 6],
        ['C', 5],
    ]

    # groups/submitted/2017-45/46: 4 x B, 3 x C
    assert statistic('submitted', 'Gruppen',
                     'from_date=2017-11-10&to_date=2017-11-17') == [
                         ['Gruppe', 'Anzahl'],
                         ['B', 4],
                         ['C', 3],
                     ]
示例#22
0
def test_view_issues(gazette_app):
    with freeze_time("2017-11-01 12:00"):
        client = Client(gazette_app)
        login_publisher(client)

        # Test data:
        # 2017:
        #     40: 2017-10-06 / 2017-10-04T12:00:00
        #     41: 2017-10-13 / 2017-10-11T12:00:00
        #     42: 2017-10-20 / 2017-10-18T12:00:00
        #     43: 2017-10-27 / 2017-10-25T12:00:00
        # >>>>>
        #     44: 2017-11-03 / 2017-11-01T12:00:00
        #     45: 2017-11-10 / 2017-11-08T12:00:00
        #     46: 2017-11-17 / 2017-11-15T12:00:00
        #     47: 2017-11-24 / 2017-11-22T12:00:00
        #     48: 2017-12-01 / 2017-11-29T12:00:00
        #     49: 2017-12-08 / 2017-12-06T12:00:00
        #     50: 2017-12-15 / 2017-12-13T12:00:00
        #     51: 2017-12-22 / 2017-12-20T12:00:00
        #     52: 2017-12-29 / 2017-12-27T12:00:00
        # 2018:
        #     1: 2018-01-05 / 2018-01-03T12:00:00

        # add a issue
        manage = client.get('/issues')
        manage = manage.click('Neu')
        manage.form['number'] = '1'
        manage.form['date_'] = '2019-01-02'
        manage.form['deadline'] = '2019-01-01T12:00'
        manage = manage.form.submit().maybe_follow()
        assert 'Ausgabe hinzugefügt.' in manage
        assert '2019-1' in manage
        upcoming_issues = [
            [td.text.strip() for td in pq(tr)('td')]
            for tr in manage.pyquery('#panel_upcoming table.issues tbody tr')
        ]
        past_issues = [
            [td.text.strip() for td in pq(tr)('td')]
            for tr in manage.pyquery('#panel_past table.issues tbody tr')
        ]
        assert upcoming_issues == [
            ['2017-44', '03.11.2017', 'Mittwoch 01.11.2017 13:00', '', ''],
            ['2017-45', '10.11.2017', 'Mittwoch 08.11.2017 13:00', '', ''],
            ['2017-46', '17.11.2017', 'Mittwoch 15.11.2017 13:00', '', ''],
            ['2017-47', '24.11.2017', 'Mittwoch 22.11.2017 13:00', '', ''],
            ['2017-48', '01.12.2017', 'Mittwoch 29.11.2017 13:00', '', ''],
            ['2017-49', '08.12.2017', 'Mittwoch 06.12.2017 13:00', '', ''],
            ['2017-50', '15.12.2017', 'Mittwoch 13.12.2017 13:00', '', ''],
            ['2017-51', '22.12.2017', 'Mittwoch 20.12.2017 13:00', '', ''],
            ['2017-52', '29.12.2017', 'Mittwoch 27.12.2017 13:00', '', ''],
            ['2018-1', '05.01.2018', 'Mittwoch 03.01.2018 13:00', '', ''],
            ['2019-1', '02.01.2019', 'Dienstag 01.01.2019 12:00', '', '']
        ]
        assert past_issues == [
            ['2017-43', '27.10.2017', 'Mittwoch 25.10.2017 14:00', '', ''],
            ['2017-42', '20.10.2017', 'Mittwoch 18.10.2017 14:00', '', ''],
            ['2017-41', '13.10.2017', 'Mittwoch 11.10.2017 14:00', '', ''],
            ['2017-40', '06.10.2017', 'Mittwoch 04.10.2017 14:00', '', ''],
        ]

        # use the first available issue in a notice
        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = 'Titel'
        manage.form['organization'] = '200'
        manage.form['category'] = '13'
        manage.form['issues'] = ['2017-44']
        manage.form['text'] = 'Text'
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage = manage.form.submit().maybe_follow()
        assert '<h2>Titel</h2>' in manage
        assert 'Nr. 44, 03.11.2017' in manage

        # edit the issue
        manage = client.get('/issues')
        manage = manage.click('Bearbeiten', index=0)
        manage.form['date_'] = '2017-11-02'
        manage.form['deadline'] = '2017-11-01T12:00'
        manage = manage.form.submit().maybe_follow()
        assert 'Ausgabe geändert.' in manage

        upcoming_issues = [
            [td.text.strip() for td in pq(tr)('td')]
            for tr in manage.pyquery('#panel_upcoming table.issues tbody tr')
        ]
        past_issues = [
            [td.text.strip() for td in pq(tr)('td')]
            for tr in manage.pyquery('#panel_past table.issues tbody tr')
        ]
        assert upcoming_issues == [
            ['2017-44', '02.11.2017', 'Mittwoch 01.11.2017 12:00', '', ''],
            ['2017-45', '10.11.2017', 'Mittwoch 08.11.2017 13:00', '', ''],
            ['2017-46', '17.11.2017', 'Mittwoch 15.11.2017 13:00', '', ''],
            ['2017-47', '24.11.2017', 'Mittwoch 22.11.2017 13:00', '', ''],
            ['2017-48', '01.12.2017', 'Mittwoch 29.11.2017 13:00', '', ''],
            ['2017-49', '08.12.2017', 'Mittwoch 06.12.2017 13:00', '', ''],
            ['2017-50', '15.12.2017', 'Mittwoch 13.12.2017 13:00', '', ''],
            ['2017-51', '22.12.2017', 'Mittwoch 20.12.2017 13:00', '', ''],
            ['2017-52', '29.12.2017', 'Mittwoch 27.12.2017 13:00', '', ''],
            ['2018-1', '05.01.2018', 'Mittwoch 03.01.2018 13:00', '', ''],
            ['2019-1', '02.01.2019', 'Dienstag 01.01.2019 12:00', '', '']
        ]
        assert past_issues == [
            ['2017-43', '27.10.2017', 'Mittwoch 25.10.2017 14:00', '', ''],
            ['2017-42', '20.10.2017', 'Mittwoch 18.10.2017 14:00', '', ''],
            ['2017-41', '13.10.2017', 'Mittwoch 11.10.2017 14:00', '', ''],
            ['2017-40', '06.10.2017', 'Mittwoch 04.10.2017 14:00', '', ''],
        ]

        # check if the notice has been updated
        manage = client.get('/notice/titel')
        assert 'Nr. 44, 03.11.2017' not in manage
        assert 'Nr. 44, 02.11.2017' in manage

        # delete all but one (unused) issues
        manage = client.get('/issues')
        manage.click('Löschen', index=1).form.submit()
        manage.click('Löschen', index=2).form.submit()
        manage.click('Löschen', index=3).form.submit()
        manage.click('Löschen', index=4).form.submit()
        manage.click('Löschen', index=5).form.submit()
        manage.click('Löschen', index=6).form.submit()
        manage.click('Löschen', index=7).form.submit()
        manage.click('Löschen', index=8).form.submit()
        manage.click('Löschen', index=9).form.submit()
        manage.click('Löschen', index=10).form.submit()
        manage.click('Löschen', index=11).form.submit()
        manage.click('Löschen', index=12).form.submit()
        manage.click('Löschen', index=13).form.submit()
        manage.click('Löschen', index=14).form.submit()

        manage = client.get('/issues')
        issues = [
            [td.text.strip() for td in pq(tr)('td')]
            for tr in manage.pyquery('table.issues tbody tr')
        ]
        assert issues == [
            ['2017-44', '02.11.2017', 'Mittwoch 01.11.2017 12:00', '', '']
        ]

        # Try to delete the used issue
        manage = client.get('/issues')
        manage = manage.click('Löschen')
        assert 'Es können nur unbenutzte Ausgaben gelöscht werden.' in manage
        assert not manage.forms
示例#23
0
def test_view_organizations(gazette_app):
    with freeze_time("2017-10-20 12:00"):
        client = Client(gazette_app)
        login_publisher(client)

        # Test data:
        # 100 / State Chancellery / active
        # 200 / Civic Community / active
        # 300 / Municipality / active
        # 400 / Evangelical Reformed Parish / active
        # 510 / Sikh Community / inactive
        # 500 / Catholic Parish / active
        # 600 / Corporation / active

        # add a organization
        manage = client.get('/organizations')
        manage = manage.click('Neu')
        manage.form['title'] = 'Organisation XY'
        manage.form['active'] = True
        manage = manage.form.submit().maybe_follow()
        assert 'Organisation hinzugefügt.' in manage
        assert 'Organisation XY' in manage
        organizations = [[
            ''.join((td.text_content(), td.attrib['class']))
            for td in pq(tr)('td')[:1]
        ][0] for tr in manage.pyquery('table.organizations tbody tr')]
        assert organizations == [
            'State Chancellery (100)', 'Civic Community (200)',
            'Municipality (300)', 'Churches (400)',
            'Evangelical Reformed Parish (410)child ',
            'Sikh Community (420)child inactive',
            'Catholic Parish (430)child ', 'Corporation (500)',
            'Organisation XY (501)'
        ]

        # use the first organization in a notice
        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = 'Titel'
        manage.form['organization'] = '100'
        manage.form['category'] = '13'
        manage.form['issues'] = ['2017-44']
        manage.form['text'] = 'Text'
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage = manage.form.submit().maybe_follow()
        assert '<h2>Titel</h2>' in manage
        assert 'State Chancellery' in manage

        # edit the first organization
        manage = client.get('/organizations')
        manage = manage.click('Bearbeiten', index=0)
        manage.form['title'] = 'Organisation Z'
        manage.form['active'] = False
        manage = manage.form.submit().maybe_follow()
        assert 'Organisation geändert.' in manage
        assert 'State Chancellery' not in manage
        assert 'Organisation Z' in manage

        organizations = [[
            ''.join((td.text_content(), td.attrib['class']))
            for td in pq(tr)('td')[:1]
        ][0] for tr in manage.pyquery('table.organizations tbody tr')]
        assert organizations == [
            'Organisation Z (100)inactive', 'Civic Community (200)',
            'Municipality (300)', 'Churches (400)',
            'Evangelical Reformed Parish (410)child ',
            'Sikh Community (420)child inactive',
            'Catholic Parish (430)child ', 'Corporation (500)',
            'Organisation XY (501)'
        ]

        # check if the notice has been updated
        manage = client.get('/notice/titel')
        assert 'State Chancellery' not in manage
        assert 'Organisation Z' in manage

        # try to delete the organization with suborganizations
        manage = client.get('/organizations')
        manage = manage.click('Löschen', index=3)
        assert (
            'Nur unbenutzte Organisationen ohne Unterorganisationen können '
            'gelöscht werden.') in manage
        assert not manage.forms

        # try to delete the used organization
        manage = client.get('/organizations')
        manage = manage.click('Löschen', index=3)
        assert (
            'Nur unbenutzte Organisationen ohne Unterorganisationen können '
            'gelöscht werden.') in manage
        assert not manage.forms

        # delete all but one (unused) organizations
        manage = client.get('/organizations')
        manage.click('Löschen', index=8).form.submit()
        manage.click('Löschen', index=7).form.submit()
        manage.click('Löschen', index=6).form.submit()
        manage.click('Löschen', index=5).form.submit()
        manage.click('Löschen', index=4).form.submit()
        manage.click('Löschen', index=3).form.submit()
        manage.click('Löschen', index=2).form.submit()
        manage.click('Löschen', index=1).form.submit()

        manage = client.get('/organizations')
        assert 'Organisation Z' in manage
        assert 'Civic Community' not in manage
        assert 'Municipality' not in manage
        assert 'Evangelical Reformed Parish' not in manage
        assert 'Sikh Community' not in manage
        assert 'Catholic Parish' not in manage
        assert 'Corporation' not in manage
        assert 'Organisation XY' not in manage
示例#24
0
def test_view_categories(gazette_app):
    with freeze_time("2017-10-20 12:00"):
        client = Client(gazette_app)
        login_publisher(client)

        # Test data:
        # 10 / Complaints / inactive
        # 11 / Education / active
        # 12 / Submissions / active
        # 13 / Commercial Register / active
        # 14 / Elections / active

        # add a category
        manage = client.get('/categories')
        manage = manage.click('Neu')
        manage.form['title'] = 'Rubrik XY'
        manage.form['active'] = True
        manage = manage.form.submit().maybe_follow()
        assert 'Rubrik hinzugefügt.' in manage
        assert 'Rubrik XY' in manage
        categories = [
            [
                ''.join((td.text_content(), td.attrib['class']))
                for td in pq(tr)('td')[:1]
            ][0]
            for tr in manage.pyquery('table.categories tbody tr')
        ]
        assert categories == [
            'Commercial Register (13)',
            'Complaints (10)inactive',
            'Education (11)',
            'Elections (14)',
            'Rubrik XY (15)',
            'Submissions (12)'
        ]

        # use the first category in a notice
        manage = client.get('/notices/drafted/new-notice')
        manage.form['title'] = 'Titel'
        manage.form['organization'] = '200'
        manage.form['category'] = '13'
        manage.form['issues'] = ['2017-44']
        manage.form['text'] = 'Text'
        manage.form['author_place'] = 'Govikon'
        manage.form['author_name'] = 'State Chancellerist'
        manage.form['author_date'] = '2019-01-01'
        manage = manage.form.submit().maybe_follow()
        assert '<h2>Titel</h2>' in manage
        assert 'Commercial Register' in manage

        # edit the first category
        manage = client.get('/categories')
        manage = manage.click('Bearbeiten', index=0)
        manage.form['title'] = 'Rubrik Z'
        manage.form['active'] = False
        manage = manage.form.submit().maybe_follow()
        assert 'Rubrik geändert.' in manage
        assert 'Commercial Register' not in manage

        categories = [
            [
                ''.join((td.text_content(), td.attrib['class']))
                for td in pq(tr)('td')[:1]
            ][0]
            for tr in manage.pyquery('table.categories tbody tr')
        ]
        assert categories == [
            'Complaints (10)inactive',
            'Education (11)',
            'Elections (14)',
            'Rubrik XY (15)',
            'Rubrik Z (13)inactive',
            'Submissions (12)'
        ]

        # check if the notice has been updated
        manage = client.get('/notice/titel')
        assert 'Commercial Register' not in manage
        assert 'Rubrik Z' in manage

        # delete all but one (unused) categories
        manage = client.get('/categories')
        manage.click('Löschen', index=0).form.submit()
        manage.click('Löschen', index=1).form.submit()
        manage.click('Löschen', index=2).form.submit()
        manage.click('Löschen', index=3).form.submit()
        manage.click('Löschen', index=5).form.submit()

        manage = client.get('/categories')
        assert 'Complaints' not in manage
        assert 'Education' not in manage
        assert 'Elections' not in manage
        assert 'Rubrik XY' not in manage
        assert 'Rubrik Z' in manage
        assert 'Submissions' not in manage

        # Try to delete the used category
        manage = client.get('/categories')
        manage = manage.click('Löschen')
        assert 'Es können nur unbenutzte Rubriken gelöscht werden.' in manage
        assert not manage.forms
示例#25
0
def test_view_archive(gazette_app):
    principal = gazette_app.principal
    principal.frontend = True
    gazette_app.cache.set('principal', principal)

    with freeze_time("2017-11-01 12:00"):
        client = Client(gazette_app)

        publisher = Client(gazette_app)
        login_publisher(publisher)

        # generate past issues
        for index in range(13, 9, -1):
            manage = publisher.get('/issues')
            manage = manage.click('Veröffentlichen', index=index)
            manage = manage.form.submit().maybe_follow()
            assert "Ausgabe veröffentlicht." in manage

        archive = client.get('/').maybe_follow()
        assert "<h3>2017</h3>" in archive
        assert "<h3>2018</h3>" not in archive

        issues = pq(archive.body)('li a')
        assert [a.text for a in issues] == [
            'Nr. 43, 27.10.2017 (PDF)', 'Nr. 42, 20.10.2017 (PDF)',
            'Nr. 41, 13.10.2017 (PDF)', 'Nr. 40, 06.10.2017 (PDF)'
        ]
        assert [a.attrib['href'] for a in issues] == [
            'http://localhost/pdf/2017-43.pdf',
            'http://localhost/pdf/2017-42.pdf',
            'http://localhost/pdf/2017-41.pdf',
            'http://localhost/pdf/2017-40.pdf'
        ]

        # publish the generate
        for index in range(0, 10):
            manage = publisher.get('/issues')
            manage = manage.click('Veröffentlichen', index=index)
            manage = manage.form.submit().maybe_follow()
            assert "Ausgabe veröffentlicht." in manage

        archive = client.get('/').maybe_follow()
        assert "<h3>2017</h3>" in archive
        assert "<h3>2018</h3>" in archive

        issues = pq(archive.body)('li a')
        assert [a.text for a in issues] == [
            'Nr. 1, 05.01.2018 (PDF)', 'Nr. 52, 29.12.2017 (PDF)',
            'Nr. 51, 22.12.2017 (PDF)', 'Nr. 50, 15.12.2017 (PDF)',
            'Nr. 49, 08.12.2017 (PDF)', 'Nr. 48, 01.12.2017 (PDF)',
            'Nr. 47, 24.11.2017 (PDF)', 'Nr. 46, 17.11.2017 (PDF)',
            'Nr. 45, 10.11.2017 (PDF)', 'Nr. 44, 03.11.2017 (PDF)',
            'Nr. 43, 27.10.2017 (PDF)', 'Nr. 42, 20.10.2017 (PDF)',
            'Nr. 41, 13.10.2017 (PDF)', 'Nr. 40, 06.10.2017 (PDF)'
        ]
        assert [a.attrib['href'] for a in issues] == [
            'http://localhost/pdf/2018-1.pdf',
            'http://localhost/pdf/2017-52.pdf',
            'http://localhost/pdf/2017-51.pdf',
            'http://localhost/pdf/2017-50.pdf',
            'http://localhost/pdf/2017-49.pdf',
            'http://localhost/pdf/2017-48.pdf',
            'http://localhost/pdf/2017-47.pdf',
            'http://localhost/pdf/2017-46.pdf',
            'http://localhost/pdf/2017-45.pdf',
            'http://localhost/pdf/2017-44.pdf',
            'http://localhost/pdf/2017-43.pdf',
            'http://localhost/pdf/2017-42.pdf',
            'http://localhost/pdf/2017-41.pdf',
            'http://localhost/pdf/2017-40.pdf'
        ]