def test_layout_delete_vote(swissvotes_app): request = DummyRequest() request.app = swissvotes_app model = SwissVote( title_de="Vote", title_fr="Vote", short_title_de="Vote", short_title_fr="Vote", ) layout = DeleteVoteLayout(model, request) assert layout.title == _("Delete vote") assert layout.editbar_links == [] assert path( layout.breadcrumbs) == ('Principal/SwissVoteCollection/SwissVote/#') # Log in as editor request.roles = ['editor'] layout = DeleteVoteLayout(model, request) assert layout.editbar_links == [] # Log in as admin request.roles = ['admin'] layout = DeleteVoteLayout(model, request) assert layout.editbar_links == []
def test_layout_upload_vote_attachemts(swissvotes_app): request = DummyRequest() request.app = swissvotes_app model = SwissVote( title_de="Vote", title_fr="Vote", short_title_de="Vote", short_title_fr="Vote", ) layout = UploadVoteAttachemtsLayout(model, request) assert layout.title == _("Manage attachments") assert layout.editbar_links == [] assert path( layout.breadcrumbs) == ('Principal/SwissVoteCollection/SwissVote/#') # Log in as editor request.roles = ['editor'] layout = UploadVoteAttachemtsLayout(model, request) assert layout.editbar_links == [] # Log in as admin request.roles = ['admin'] layout = UploadVoteAttachemtsLayout(model, request) assert layout.editbar_links == []
def test_vote_pagination(swissvotes_app): for day, number in ((1, '100'), (2, '101.1'), (2, '101.2'), (3, '102')): swissvotes_app.session().add( SwissVote( bfs_number=Decimal(number), date=date(1990, 6, day), legislation_number=4, legislation_decade=NumericRange(1990, 1994), title_de="Vote DE", title_fr="Vote FR", short_title_de="V D", short_title_fr="V F", keyword="Keyword", votes_on_same_day=2, _legal_form=3, initiator="Initiator", )) commit() client = Client(swissvotes_app) client.get('/locale/de_CH').follow() # 102 page = client.get('/').maybe_follow().click("Abstimmungen") page = page.click("Details", index=0) assert "<td>102</td>" in page assert "Vorherige Abstimmung" in page assert "Nächste Abstimmung" not in page # 101.2 page = page.click("Vorherige Abstimmung") assert "<td>101.2</td>" in page assert "Vorherige Abstimmung" in page assert "Nächste Abstimmung" in page # 101.1 page = page.click("Vorherige Abstimmung") assert "<td>101.1</td>" in page assert "Vorherige Abstimmung" in page assert "Nächste Abstimmung" in page # 100 page = page.click("Vorherige Abstimmung") assert "<td>100</td>" in page assert "Vorherige Abstimmung" not in page assert "Nächste Abstimmung" in page # 101.1 page = page.click("Nächste Abstimmung") assert "<td>101.1</td>" in page # 101.2 page = page.click("Nächste Abstimmung") assert "<td>101.2</td>" in page # 102 page = page.click("Nächste Abstimmung") assert "<td>102</td>" in page
def test_recommendations_parties(sample_vote): grouped = sample_vote.recommendations_parties codes = SwissVote.codes('recommendation') # Remove entries in codes for unknown and actor no longer exists del codes[9999] del codes[None] # print(grouped.keys()) # print(codes.values()) assert list(grouped.keys()) == list(codes.values())
def test_layout_vote(swissvotes_app): session = swissvotes_app.session() request = DummyRequest() request.app = swissvotes_app session.add( SwissVote(title_de="Vote DE", title_fr="Vote FR", short_title_de="Vote D", short_title_fr="Vote F", bfs_number=Decimal('100'), date=date(1990, 6, 2), legislation_number=10, legislation_decade=NumericRange(1990, 1994), votes_on_same_day=2, _legal_form=1)) session.flush() model = session.query(SwissVote).one() layout = VoteLayout(model, request) assert layout.title == "Vote D" assert layout.editbar_links == [] assert path(layout.breadcrumbs) == 'Principal/SwissVoteCollection/#' swissvotes_app.session_manager.current_locale = 'fr_CH' model = swissvotes_app.session().query(SwissVote).one() layout = VoteLayout(model, request) assert layout.title == "Vote F" swissvotes_app.session_manager.current_locale = 'en_US' model = swissvotes_app.session().query(SwissVote).one() layout = VoteLayout(model, request) assert layout.title == "Vote D" # Log in as editor request.roles = ['editor'] layout = VoteLayout(model, request) assert list(hrefs(layout.editbar_links)) == [ 'SwissVote/upload', 'SwissVote/delete', ] # Log in as admin request.roles = ['admin'] layout = VoteLayout(model, request) assert list(hrefs(layout.editbar_links)) == [ 'SwissVote/upload', 'SwissVote/delete', ]
def test_vote_attachments(swissvotes_app, attachments): session = swissvotes_app.session() session.add( SwissVote( bfs_number=Decimal('100.1'), date=date(1990, 6, 2), legislation_number=4, legislation_decade=NumericRange(1990, 1994), title_de="Vote DE", title_fr="Vote FR", short_title_de="V D", short_title_fr="V F", keyword="Keyword", votes_on_same_day=2, _legal_form=1, )) session.flush() vote = session.query(SwissVote).one() assert vote.voting_text is None assert vote.federal_council_message is None assert vote.parliamentary_debate is None assert vote.voting_booklet is None assert vote.resolution is None assert vote.realization is None assert vote.results_by_domain is None assert vote.files == [] assert vote.searchable_text_de_CH is None assert vote.searchable_text_fr_CH is None assert vote.indexed_files == { 'brief_description', 'federal_council_message', 'parliamentary_debate', 'realization', 'voting_text', } vote.ad_analysis = attachments['ad_analysis'] vote.brief_description = attachments['brief_description'] vote.parliamentary_debate = attachments['parliamentary_debate'] vote.voting_text = attachments['voting_text'] session.flush() assert len(vote.files) == 4 assert vote.ad_analysis.name == 'ad_analysis-de_CH' assert vote.brief_description.name == 'brief_description-de_CH' assert vote.parliamentary_debate.name == 'parliamentary_debate-de_CH' assert vote.voting_text.name == 'voting_text-de_CH' assert "abstimmungstex" in vote.searchable_text_de_CH assert "kurschbeschreib" in vote.searchable_text_de_CH assert "parlamentdebatt" in vote.searchable_text_de_CH assert vote.searchable_text_fr_CH == '' swissvotes_app.session_manager.current_locale = 'fr_CH' vote.realization = attachments['realization'] session.flush() assert len(vote.files) == 5 assert vote.voting_text is None assert vote.realization.name == 'realization-fr_CH' assert "abstimmungstex" in vote.searchable_text_de_CH assert "kurschbeschreib" in vote.searchable_text_de_CH assert "parlamentdebatt" in vote.searchable_text_de_CH assert "réalis" in vote.searchable_text_fr_CH del vote.realization vote.federal_council_message = attachments['federal_council_message'] vote.resolution = attachments['resolution'] vote.voting_booklet = attachments['voting_booklet'] session.flush() assert len(vote.files) == 7 assert vote.voting_text is None assert vote.federal_council_message.name == 'federal_council_message-fr_CH' assert vote.resolution.name == 'resolution-fr_CH' assert vote.voting_booklet.name == 'voting_booklet-fr_CH' assert "abstimmungstex" in vote.searchable_text_de_CH assert "kurschbeschreib" in vote.searchable_text_de_CH assert "parlamentdebatt" in vote.searchable_text_de_CH assert "réalis" not in vote.searchable_text_fr_CH assert "conseil" in vote.searchable_text_fr_CH assert "fédéral" in vote.searchable_text_fr_CH
def test_vote_codes(): assert SwissVote.codes('legal_form')[2] == "Optional referendum" assert SwissVote.codes('result')[0] == "Rejected" assert SwissVote.codes('result_people_accepted')[0] == "Rejected" assert SwissVote.codes('result_cantons_accepted')[0] == "Rejected" assert SwissVote.codes('result_ai_accepted')[1] == "Accepted" assert SwissVote.codes('department_in_charge')[8] == \ "Federal Chancellery (FCh)" assert SwissVote.codes('position_federal_council')[3] == "None" assert SwissVote.codes('position_parliament')[2] == "Rejecting" assert SwissVote.codes('position_national_council')[2] == "Rejecting" assert SwissVote.codes('position_council_of_states')[2] == "Rejecting" assert SwissVote.codes('recommendation')[5] == "Free vote"
def post_validate(self, form, validation_stopped): """ Make sure the given XLSX is valid (all expected columns are present all cells contain reasonable values). Converts the XLSX to a list of SwissVote objects, available as ``data``. """ super(SwissvoteDatasetField, self).post_validate(form, validation_stopped) if validation_stopped: return errors = [] data = [] mapper = ColumnMapper() try: workbook = open_workbook( file_contents=self.raw_data[0].file.read()) except Exception: raise ValueError(_("Not a valid XLSX file.")) if workbook.nsheets < 1: raise ValueError(_("No data.")) data_sheet_name = 'DATA' citation_sheet_name = 'CITATION' if data_sheet_name not in workbook.sheet_names(): raise ValueError(_('Sheet DATA is missing.')) if citation_sheet_name not in workbook.sheet_names(): raise ValueError(_('Sheet CITATION is missing.')) sheet = workbook.sheet_by_name(data_sheet_name) if sheet.nrows <= 1: raise ValueError(_("No data.")) headers = [column.value for column in sheet.row(0)] missing = set(mapper.columns.values()) - set(headers) if missing: raise ValueError( _("Some columns are missing: ${columns}.", mapping={'columns': ', '.join(missing)})) for index in range(1, sheet.nrows): row = sheet.row(index) vote = SwissVote() for (attribute, column, type_, nullable, precision, scale) in mapper.items(): cell = row[headers.index(column)] try: if cell.ctype == XL_CELL_EMPTY: value = None elif type_ == 'TEXT': value = str(cell.value) value = '' if value == '.' else value elif type_ == 'DATE': if isinstance(cell.value, str): value = parse(cell.value, dayfirst=True).date() else: value = xldate.xldate_as_datetime( cell.value, workbook.datemode).date() elif type_ == 'INTEGER': if isinstance(cell.value, str): value = cell.value value = '' if value == '.' else value value = int(value) if value else None else: value = int(cell.value) elif type_ == 'INT4RANGE': value = NumericRange( *[int(bound) for bound in cell.value.split('-')]) elif type_.startswith('NUMERIC'): if isinstance(cell.value, str): value = cell.value value = '' if value == '.' else value value = Decimal(str(value)) if value else None else: value = Decimal(str(cell.value)) if value is not None: value = Decimal( format(value, f'{precision}.{scale}f')) except Exception: errors.append( (index, column, f"'{value}' ≠ {type_.lower()}")) else: if not nullable and value is None: errors.append((index, column, "∅")) mapper.set_value(vote, attribute, value) data.append(vote) if errors: raise ValueError( _("Some cells contain invalid values: ${errors}.", mapping={ 'errors': '; '.join( ['{}:{} {}'.format(*error) for error in errors]) })) self.data = data
def test_vote_chart(session): class Request(object): def translate(self, text): if isinstance(text, TranslationString): return text.interpolate() return text empty = { 'empty': True, 'text': '', 'text_label': '', 'nay': 0.0, 'nay_label': '', 'none': 0.0, 'none_label': '', 'yea': 0.0, 'yea_label': '' } model = SwissVote() request = Request() assert view_vote_percentages(model, request) == { 'results': [empty], 'title': None } model.title_de = "Vote DE" model.title_fr = "Vote FR" model.short_title_de = "V D" model.short_title_fr = "V F" model._result_people_accepted = 0 model._result_cantons_accepted = 3 model._position_federal_council = 33 model._position_national_council = 1 model._position_council_of_states = 2 assert view_vote_percentages(model, request) == { 'results': [{ 'empty': False, 'text': 'People', 'text_label': '', 'yea': 0.0, 'yea_label': '', 'none': 0.0, 'none_label': '', 'nay': True, 'nay_label': 'Rejected', }, { 'empty': False, 'text': 'Cantons', 'text_label': '', 'yea': 0.0, 'yea_label': '', 'none': True, 'none_label': 'Majority of the cantons not necessary', 'nay': 0.0, 'nay_label': '', }, empty, { 'empty': False, 'text': 'National Council', 'text_label': '', 'yea': True, 'yea_label': 'Accepting', 'none': 0.0, 'none_label': '', 'nay': 0.0, 'nay_label': '', }, { 'empty': False, 'text': 'Council of States', 'text_label': '', 'yea': 0.0, 'yea_label': '', 'none': 0.0, 'none_label': '', 'nay': True, 'nay_label': 'Rejecting', }], 'title': 'Vote DE' } model.result_people_yeas_p = Decimal('10.2') model.result_cantons_yeas = Decimal('23.5') model.result_cantons_nays = Decimal('2.5') model.position_national_council_yeas = Decimal('149') model.position_national_council_nays = Decimal('51') model.position_council_of_states_yeas = Decimal('43') model.position_council_of_states_nays = Decimal('3') model.national_council_share_yeas = Decimal('1.0') model.national_council_share_nays = Decimal('3.4') assert view_vote_percentages(model, request) == { 'results': [{ 'empty': False, 'text': 'People', 'text_label': '', 'yea': 10.2, 'yea_label': '10.2% yea', 'none': 0.0, 'none_label': '', 'nay': 89.8, 'nay_label': '89.8% nay', }, { 'empty': False, 'text': 'Cantons', 'text_label': '', 'yea': 90.4, 'yea_label': '23.5 yea', 'none': 0.0, 'none_label': '', 'nay': 9.6, 'nay_label': '2.5 nay', }, empty, { 'empty': False, 'text': 'National Council', 'text_label': '', 'yea': 74.5, 'yea_label': '149 yea', 'none': 0.0, 'none_label': '', 'nay': 25.5, 'nay_label': '51 nay', }, { 'empty': False, 'text': 'Council of States', 'text_label': '', 'yea': 93.5, 'yea_label': '43 yea', 'none': 0.0, 'none_label': '', 'nay': 6.5, 'nay_label': '3 nay', }, { 'empty': False, 'text': 'Party slogans', 'text_label': 'Recommendations by political parties', 'yea': 1.0, 'yea_label': ('Electoral shares of parties: ' 'Parties recommending Yes 1.0%'), 'none': 95.6, 'none_label': ('Electoral shares of parties: neutral/unknown 95.6%'), 'nay': 3.4, 'nay_label': ('Electoral shares of parties: Parties recommending No 3.4%'), }], 'title': 'Vote DE' }
def test_import_attachments(session_manager, temporary_directory, redis_url): def create_file(path, content='content'): path.parent.mkdir(parents=True, exist_ok=True) with open(path, 'wb') as file: pdf = Pdf(file) pdf.init_report() pdf.p(content) pdf.generate() cfg_path = os.path.join(temporary_directory, 'onegov.yml') write_config(cfg_path, session_manager.dsn, temporary_directory, redis_url) result = run_command(cfg_path, 'govikon', ['add']) assert result.exit_code == 0 assert "Instance was created successfully" in result.output # Test parsing folder = Path(temporary_directory) / 'data-1' create_file(folder / 'voting_text' / 'de_CH' / '001.pdf') create_file(folder / 'voting_text' / 'de_CH' / '01.pdf') create_file(folder / 'voting_text' / 'de_CH' / '1.pdf') create_file(folder / 'voting_text' / 'de_CH' / '1.1.pdf') create_file(folder / 'voting_text' / 'de_CH' / '01.1.pdf') create_file(folder / 'voting_text' / 'de_CH' / '01.10.pdf') create_file(folder / 'voting_text' / 'de_CH' / '001.100.pdf') create_file(folder / 'voting_text' / 'de_CH' / 'a.pdf') create_file(folder / 'voting_text' / 'de_CH' / '100.pdx') create_file(folder / 'voting_text' / 'rm_CH' / '100.pdf') create_file(folder / 'voting_text' / '100.pdf') create_file(folder / 'another_text' / 'de_CH' / '100.pdf') create_file(folder / 'another_text' / '100.pdf') create_file(folder / '100.pdf') result = run_command(cfg_path, 'govikon', ['import', str(folder)]) assert result.exit_code == 0 assert "1 for voting_text/de_CH/001.pdf" in result.output assert "1 for voting_text/de_CH/01.pdf" in result.output assert "1 for voting_text/de_CH/1.pdf" in result.output assert "1.1 for voting_text/de_CH/1.1.pdf" in result.output assert "1.1 for voting_text/de_CH/01.1.pdf" in result.output assert "1.10 for voting_text/de_CH/01.10.pdf" in result.output assert "1.100 for voting_text/de_CH/001.100.pdf" in result.output assert "Invalid name voting_text/de_CH/a.pdf" in result.output assert "Ignoring voting_text/de_CH/100.pdx" in result.output assert "Ignoring /another_text" in result.output assert "Ignoring /voting_text/rm_CH" in result.output assert "Ignoring /voting_text/100.pdf" in result.output assert "Ignoring /another_text" in result.output assert "Ignoring /100.pdf" in result.output # Test importing folder = Path(temporary_directory) / 'data-2' for name in ( 'federal_council_message', 'parliamentary_debate', 'realization', 'resolution', 'voting_booklet', 'voting_text', ): create_file(folder / name / 'de_CH' / '1.0.pdf', f"A 1{name}de end") create_file(folder / name / 'fr_CH' / '1.0.pdf', f"B 1{name}fr end") create_file(folder / name / 'de_CH' / '2.0.pdf', f"C 2{name}de end") create_file(folder / name / 'fr_CH' / '2.0.pdf', f"D 2{name}fr end") session_manager.ensure_schema_exists('onegov_swissvotes-govikon') session_manager.set_current_schema('onegov_swissvotes-govikon') session = session_manager.session() for number in (1, 2, 3): session.add( SwissVote( id=number, bfs_number=Decimal(str(number)), date=date(1990, 6, 2), legislation_number=4, legislation_decade=NumericRange(1990, 1994), title_de=f"Vote {number}", title_fr=f"Vote {number}", short_title_de=f"Vote {number}", short_title_fr=f"Vote {number}", votes_on_same_day=3, _legal_form=1, ) ) session.flush() commit() result = run_command(cfg_path, 'govikon', ['import', str(folder)]) assert result.exit_code == 0 assert "Added federal_council_message/de_CH/1.0.pdf" in result.output assert "Added federal_council_message/de_CH/2.0.pdf" in result.output assert "Added federal_council_message/fr_CH/1.0.pdf" in result.output assert "Added federal_council_message/fr_CH/2.0.pdf" in result.output assert "Added parliamentary_debate/de_CH/1.0.pdf" in result.output assert "Added parliamentary_debate/de_CH/2.0.pdf" in result.output assert "Added parliamentary_debate/fr_CH/1.0.pdf" in result.output assert "Added parliamentary_debate/fr_CH/2.0.pdf" in result.output assert "Added realization/de_CH/1.0.pdf" in result.output assert "Added realization/de_CH/2.0.pdf" in result.output assert "Added realization/fr_CH/1.0.pdf" in result.output assert "Added realization/fr_CH/2.0.pdf" in result.output assert "Added resolution/de_CH/1.0.pdf" in result.output assert "Added resolution/de_CH/2.0.pdf" in result.output assert "Added resolution/fr_CH/1.0.pdf" in result.output assert "Added resolution/fr_CH/2.0.pdf" in result.output assert "Added voting_booklet/de_CH/1.0.pdf" in result.output assert "Added voting_booklet/de_CH/2.0.pdf" in result.output assert "Added voting_booklet/fr_CH/1.0.pdf" in result.output assert "Added voting_booklet/fr_CH/2.0.pdf" in result.output assert "Added voting_text/de_CH/1.0.pdf" in result.output assert "Added voting_text/de_CH/2.0.pdf" in result.output assert "Added voting_text/fr_CH/1.0.pdf" in result.output assert "Added voting_text/fr_CH/2.0.pdf" in result.output for number in (1, 2): vote = session.query(SwissVote).filter_by(id=number).one() for lang in ('de', 'fr'): vote.session_manager.current_locale = f'{lang}_CH' for name in ( 'federal_council_message', 'parliamentary_debate', 'realization', 'resolution', 'voting_booklet', 'voting_text', ): assert f'{number}{name}{lang}' in getattr(vote, name).extract
def test_view_vote(swissvotes_app): swissvotes_app.session().add( SwissVote( bfs_number=Decimal('100.1'), date=date(1990, 6, 2), legislation_number=4, legislation_decade=NumericRange(1990, 1994), title_de="Vote DE", title_fr="Vote FR", short_title_de="V D", short_title_fr="V F", keyword="Keyword", votes_on_same_day=2, _legal_form=1, initiator="Initiator", anneepolitique="anneepolitique", descriptor_1_level_1=Decimal('4'), descriptor_1_level_2=Decimal('4.2'), descriptor_1_level_3=Decimal('4.21'), descriptor_2_level_1=Decimal('10'), descriptor_2_level_2=Decimal('10.3'), descriptor_2_level_3=Decimal('10.35'), descriptor_3_level_1=Decimal('10'), descriptor_3_level_2=Decimal('10.3'), descriptor_3_level_3=Decimal('10.33'), _result=1, result_eligible_voters=2, result_votes_empty=3, result_votes_invalid=4, result_votes_valid=5, result_votes_total=6, result_turnout=Decimal('20.01'), _result_people_accepted=1, result_people_yeas=8, result_people_nays=9, result_people_yeas_p=Decimal('40.01'), _result_cantons_accepted=1, result_cantons_yeas=Decimal('1.5'), result_cantons_nays=Decimal('24.5'), result_cantons_yeas_p=Decimal('60.01'), _department_in_charge=1, procedure_number=Decimal('24.557'), _position_federal_council=1, _position_parliament=1, _position_national_council=1, position_national_council_yeas=10, position_national_council_nays=20, _position_council_of_states=1, position_council_of_states_yeas=30, position_council_of_states_nays=40, duration_federal_assembly=30, duration_post_federal_assembly=31, duration_initative_collection=32, duration_initative_federal_council=33, duration_initative_total=34, duration_referendum_collection=35, duration_referendum_total=36, signatures_valid=40, signatures_invalid=41, recommendations={ 'fdp': 1, 'cvp': 1, 'sps': 1, 'svp': 1, 'lps': 2, 'ldu': 2, 'evp': 2, 'csp': 3, 'pda': 3, 'poch': 3, 'gps': 4, 'sd': 4, 'rep': 4, 'edu': 5, 'fps': 5, 'lega': 5, 'kvp': 66, 'glp': 66, 'bdp': None, 'mcg': 9999, 'sav': 1, 'eco': 2, 'sgv': 3, 'sbv-usp': 3, 'sgb': 3, 'travs': 3, 'vsa': 9999, }, recommendations_other_yes="Pro Velo", recommendations_other_no=None, recommendations_other_free="Pro Natura, Greenpeace", recommendations_divergent={ 'fdp-fr_ch': 2, 'jcvp_ch': 2, }, national_council_election_year=1990, national_council_share_fdp=Decimal('01.10'), national_council_share_cvp=Decimal('02.10'), national_council_share_sp=Decimal('03.10'), national_council_share_svp=Decimal('04.10'), national_council_share_lps=Decimal('05.10'), national_council_share_ldu=Decimal('06.10'), national_council_share_evp=Decimal('07.10'), national_council_share_csp=Decimal('08.10'), national_council_share_pda=Decimal('09.10'), national_council_share_poch=Decimal('10.10'), national_council_share_gps=Decimal('11.10'), national_council_share_sd=Decimal('12.10'), national_council_share_rep=Decimal('13.10'), national_council_share_edu=Decimal('14.10'), national_council_share_fps=Decimal('15.10'), national_council_share_lega=Decimal('16.10'), national_council_share_kvp=Decimal('17.10'), national_council_share_glp=Decimal('18.10'), national_council_share_bdp=Decimal('19.10'), national_council_share_mcg=Decimal('20.20'), national_council_share_ubrige=Decimal('21.20'), national_council_share_yeas=Decimal('22.20'), national_council_share_nays=Decimal('23.20'), national_council_share_neutral=Decimal('24.20'), national_council_share_none=Decimal('25.20'), national_council_share_empty=Decimal('26.20'), national_council_share_free_vote=Decimal('27.20'), national_council_share_unknown=Decimal('28.20'), )) commit() client = Client(swissvotes_app) client.get('/locale/de_CH').follow() page = client.get('/').maybe_follow().click("Abstimmungen") page = page.click("Details") assert "100.1" in page assert "Vote DE" in page assert "V D" in page assert "Keyword" in page assert "02.06.1990" in page assert "Obligatorisches Referendum" in page assert ("Wirtschaft > Arbeit und Beschäftigung > Arbeitsbedingungen" ) in page assert ("Soziale Fragen – Sozialpolitik > Soziale Gruppen > " "Kinder und Jugendliche") in page assert ("Soziale Fragen – Sozialpolitik > Soziale Gruppen > " "Stellung der Frau") in page assert "anneepolitique" in page assert "Befürwortend" in page assert "24.557" in page assert "30 Tage" in page assert "(10 Ja, 20 Nein)" in page assert "(30 Ja, 40 Nein)" in page assert "CVP" in page assert "FDP" in page assert "SPS" in page assert "SVP" in page assert "EVP" in page assert "LdU" in page assert "LPS" in page assert "CSP" in page assert "PdA" in page assert "POCH" in page assert "GPS" in page assert "REP" in page assert "SD" in page assert "EDU" in page assert "FPS" in page assert "Lega" in page assert "GLP" in page assert "KVP" in page assert "SAV" in page assert "eco" in page assert "SBV" in page assert "SGB" in page assert "SGV" in page assert "TravS" in page assert "Pro Velo" in page assert "Pro Natura" in page assert "Greenpeace" in page assert "FDP.Die Liberalen Frauen" in page assert "Junge CVP" in page assert "22.2%" in page assert "Details" in page assert "Angenommen" in page assert "(40.01% Ja-Stimmen)" in page assert "(1.5 Ja, 24.5 Nein)" in page assert "20.01%" in page swissvotes_app.session().query(SwissVote).one()._legal_form = 3 commit() page = client.get('/').maybe_follow().click("Abstimmungen") page = page.click("Details") assert "Volksinitiative" in page assert "Initiator" in page assert "32 Tage" in page # Party strengths # Note: the lower table gets all actors whose paroles is not unknown # To get a sum of 100%, not ubrige is displayed but the percentage of # unknown paroles. Hence the percentage for Unknown paroles will be # displayed twice. page = page.click("Details") assert "Nationalratswahl 1990" assert "21.2%" not in page, 'Ubrige are included in unknown' assert "22.2%" in page assert "23.2%" in page assert "24.2%" in page assert "25.2%" in page assert "26.2%" in page assert "27.2%" in page assert len(re.findall(r'28\.2\%', str(page))) == 2 assert "1.1%" in page assert "2.1%" in page assert "3.1%" in page assert "4.1%" in page assert "5.1%" in page assert "6.1%" in page assert "7.1%" in page assert "8.1%" in page assert "9.1%" in page assert "10.1%" in page assert "11.1%" in page assert "12.1%" in page assert "13.1%" in page assert "14.1%" in page assert "15.1%" in page assert "16.1%" in page assert "17.1%" in page assert "18.1%" in page assert "19.1%" not in page, "Recommendation:None => not displayed" assert "20.2%" not in page, "has code 9999, so not displayed" # Percentages page = client.get(page.request.url.replace('/strengths', '/percentages')) assert page.json == { 'results': [{ 'text': 'Volk', 'text_label': '', 'empty': False, 'yea': 40.0, 'yea_label': '40.0% Ja', 'none': 0.0, 'none_label': '', 'nay': 60.0, 'nay_label': '60.0% Nein', }, { 'text': 'Stände', 'text_label': '', 'empty': False, 'yea': 5.8, 'yea_label': '1.5 Ja', 'none': 0.0, 'none_label': '', 'nay': 94.2, 'nay_label': '24.5 Nein', }, { 'text': '', 'text_label': '', 'empty': True, 'yea': 0.0, 'yea_label': '', 'none': 0.0, 'none_label': '', 'nay': 0.0, 'nay_label': '', }, { 'text': 'Bundesrat', 'text_label': 'Position des Bundesrats', 'empty': False, 'yea': True, 'yea_label': 'Befürwortend', 'none': 0.0, 'none_label': '', 'nay': 0.0, 'nay_label': '', }, { 'text': 'Nationalrat', 'text_label': '', 'empty': False, 'yea': 33.3, 'yea_label': '10 Ja', 'none': 0.0, 'none_label': '', 'nay': 66.7, 'nay_label': '20 Nein', }, { 'text': 'Ständerat', 'text_label': '', 'empty': False, 'yea': 42.9, 'yea_label': '30 Ja', 'none': 0.0, 'none_label': '', 'nay': 57.1, 'nay_label': '40 Nein', }, { 'text': 'Parteiparolen', 'text_label': 'Empfehlungen der politischen Parteien', 'empty': False, 'yea': 22.2, 'yea_label': ('Wähleranteile der Parteien: Befürwortende Parteien 22.2%'), 'none': 54.6, 'none_label': ('Wähleranteile der Parteien: Neutral/unbekannt 54.6%'), 'nay': 23.2, 'nay_label': ('Wähleranteile der Parteien: Ablehnende Parteien 23.2%'), }], 'title': 'Vote DE' } # Delete vote login = client.get('/auth/login') login.form['username'] = '******' login.form['password'] = '******' login.form.submit() manage = client.get('/').maybe_follow().click("Abstimmungen") manage = manage.click("Details").click("Abstimmung löschen") manage = manage.form.submit().follow() assert swissvotes_app.session().query(SwissVote).count() == 0
def add(self, **kwargs): vote = SwissVote(**kwargs) self.session.add(vote) self.session.flush() return vote
def test_layout_default(swissvotes_app): session = swissvotes_app.session() request = DummyRequest() request.app = swissvotes_app request.session = session model = None layout = DefaultLayout(model, request) assert layout.title == "" assert layout.editbar_links == [] assert path(layout.breadcrumbs) == 'Principal' assert layout.static_path == 'Principal/static' assert layout.app_version assert layout.locales == [('de_CH', 'de', 'Deutsch', 'SiteLocale/'), ('fr_CH', 'fr', 'Français', 'SiteLocale/'), ('en_US', 'en', 'English', 'SiteLocale/')] assert layout.request.includes == ['frameworks', 'chosen', 'common'] assert list(hrefs(layout.top_navigation)) == ['SwissVoteCollection/'] assert layout.homepage_url == 'Principal/' assert layout.votes_url == 'SwissVoteCollection/' assert layout.login_url == 'Auth/login' assert layout.logout_url is None assert layout.move_page_url_template == ( 'TranslatablePageMove/?csrf-token=x') assert path([layout.disclaimer_link]) == 'TranslatablePage' layout.disclaimer_link.text == 'disclaimer' assert path([layout.imprint_link]) == 'TranslatablePage' layout.imprint_link.text == 'imprint' assert path([layout.data_protection_link]) == 'TranslatablePage' layout.data_protection_link.text == 'data-protection' # Login request.is_logged_in = True layout = DefaultLayout(model, request) assert layout.login_url is None assert layout.logout_url == 'Auth/logout' # Add some pages pages = TranslatablePageCollection(session) pages.add(id='dataset', title_translations={ 'de_CH': 'Datensatz', 'en_US': 'Dataset' }, content_translations={ 'de_CH': 'Datensatz', 'en_US': 'Dataset' }) pages.add(id='about', title_translations={ 'de_CH': 'Über uns', 'en_US': 'About' }, content_translations={ 'de_CH': 'Über uns', 'en_US': 'About' }) pages.add(id='contact', title_translations={ 'de_CH': 'Kontakt', 'en_US': 'Contact' }, content_translations={ 'de_CH': 'Kontakt', 'en_US': 'Contact' }) assert [item.text for item in layout.top_navigation ] == ['Votes', 'Datensatz', 'Über uns', 'Kontakt'] assert layout.format_bfs_number(Decimal('100')) == '100' assert layout.format_bfs_number(Decimal('100.1')) == '100.1' assert layout.format_bfs_number(Decimal('100.12')) == '100.1' assert layout.format_procedure_number(None) == '' assert layout.format_procedure_number(Decimal('0')) == '0' assert layout.format_procedure_number(Decimal('00.087')) == '00.087' assert layout.format_procedure_number(Decimal('0.087')) == '00.087' assert layout.format_procedure_number(Decimal('02.060')) == '02.060' assert layout.format_procedure_number(Decimal('2.06')) == '02.060' assert layout.format_procedure_number(Decimal('16.479')) == '16.479' assert layout.format_procedure_number(Decimal('1859')) == '1859' assert layout.format_procedure_number(Decimal('1859.000')) == '1859' assert layout.format_procedure_number(Decimal('9309')) == '9309' assert layout.format_procedure_number(Decimal('9309.0')) == '9309' assert layout.format_procedure_number(Decimal('12239')) == '12239' assert layout.format_procedure_number(Decimal('12239.0')) == '12239' assert layout.format_policy_areas(SwissVote()) == '' vote = SwissVote( descriptor_1_level_1=Decimal('4'), descriptor_2_level_1=Decimal('8'), descriptor_2_level_2=Decimal('8.3'), descriptor_3_level_1=Decimal('10'), descriptor_3_level_2=Decimal('10.3'), descriptor_3_level_3=Decimal('10.33'), ) assert layout.format_policy_areas(vote) == ( '<span title="d-1-10 > d-2-103 > d-3-1033">d-1-10</span>,<br>' '<span title="d-1-4">d-1-4</span>,<br>' '<span title="d-1-8 > d-2-83">d-1-8</span>') vote = SwissVote( descriptor_2_level_1=Decimal('10'), descriptor_2_level_2=Decimal('10.3'), descriptor_3_level_1=Decimal('10'), descriptor_3_level_2=Decimal('10.3'), descriptor_3_level_3=Decimal('10.33'), ) assert layout.format_policy_areas(vote) == ( '<span title="d-1-10 > d-2-103 ' 'd-1-10 > d-2-103 > d-3-1033">d-1-10</span>')
def sample_vote(): vote = SwissVote() vote.bfs_number = Decimal('100.1') vote.date = date(1990, 6, 2) vote.legislation_number = 4 vote.legislation_decade = NumericRange(1990, 1994) vote.title_de = "Vote DE" vote.title_fr = "Vote FR" vote.short_title_de = "V D" vote.short_title_fr = "V F" vote.keyword = "Keyword" vote.votes_on_same_day = 2 vote._legal_form = 1 vote.initiator = "Initiator" vote.anneepolitique = "anneepolitique" vote.bfs_map_de = ( "https://www.atlas.bfs.admin.ch/maps/12/map/mapIdOnly/1815_de.html") vote.bfs_map_fr = "htt(ps://www.ap/mapIdOnly/1815[e.html}" vote.descriptor_1_level_1 = Decimal('4') vote.descriptor_1_level_2 = Decimal('4.2') vote.descriptor_1_level_3 = Decimal('4.21') vote.descriptor_2_level_1 = Decimal('10') vote.descriptor_2_level_2 = Decimal('10.3') vote.descriptor_2_level_3 = Decimal('10.35') vote.descriptor_3_level_1 = Decimal('10') vote.descriptor_3_level_2 = Decimal('10.3') vote.descriptor_3_level_3 = Decimal('10.33') vote._result = 1 vote.result_eligible_voters = 2 vote.result_votes_empty = 3 vote.result_votes_invalid = 4 vote.result_votes_valid = 5 vote.result_votes_total = 6 vote.result_turnout = Decimal('20.01') vote._result_people_accepted = 1 vote.result_people_yeas = 8 vote.result_people_nays = 9 vote.result_people_yeas_p = Decimal('40.01') vote._result_cantons_accepted = 1 vote.result_cantons_yeas = Decimal('1.5') vote.result_cantons_nays = Decimal('24.5') vote.result_cantons_yeas_p = Decimal('60.01') vote.result_ag_eligible_voters = 101 vote.result_ag_votes_valid = 102 vote.result_ag_votes_total = 103 vote.result_ag_turnout = Decimal('10.40') vote.result_ag_yeas = 105 vote.result_ag_nays = 107 vote.result_ag_yeas_p = Decimal('10.80') vote._result_ag_accepted = 0 vote.result_ai_eligible_voters = 101 vote.result_ai_votes_valid = 102 vote.result_ai_votes_total = 103 vote.result_ai_turnout = Decimal('10.40') vote.result_ai_yeas = 105 vote.result_ai_nays = 107 vote.result_ai_yeas_p = Decimal('10.80') vote._result_ai_accepted = 0 vote.result_ar_eligible_voters = 101 vote.result_ar_votes_valid = 102 vote.result_ar_votes_total = 103 vote.result_ar_turnout = Decimal('10.40') vote.result_ar_yeas = 105 vote.result_ar_nays = 107 vote.result_ar_yeas_p = Decimal('10.80') vote._result_ar_accepted = 0 vote.result_be_eligible_voters = 101 vote.result_be_votes_valid = 102 vote.result_be_votes_total = 103 vote.result_be_turnout = Decimal('10.40') vote.result_be_yeas = 105 vote.result_be_nays = 107 vote.result_be_yeas_p = Decimal('10.80') vote._result_be_accepted = 0 vote.result_bl_eligible_voters = 101 vote.result_bl_votes_valid = 102 vote.result_bl_votes_total = 103 vote.result_bl_turnout = Decimal('10.40') vote.result_bl_yeas = 105 vote.result_bl_nays = 107 vote.result_bl_yeas_p = Decimal('10.80') vote._result_bl_accepted = 0 vote.result_bs_eligible_voters = 101 vote.result_bs_votes_valid = 102 vote.result_bs_votes_total = 103 vote.result_bs_turnout = Decimal('10.40') vote.result_bs_yeas = 105 vote.result_bs_nays = 107 vote.result_bs_yeas_p = Decimal('10.80') vote._result_bs_accepted = 0 vote.result_fr_eligible_voters = 101 vote.result_fr_votes_valid = 102 vote.result_fr_votes_total = 103 vote.result_fr_turnout = Decimal('10.40') vote.result_fr_yeas = 105 vote.result_fr_nays = 107 vote.result_fr_yeas_p = Decimal('10.80') vote._result_fr_accepted = 0 vote.result_ge_eligible_voters = 101 vote.result_ge_votes_valid = 102 vote.result_ge_votes_total = 103 vote.result_ge_turnout = Decimal('10.40') vote.result_ge_yeas = 105 vote.result_ge_nays = 107 vote.result_ge_yeas_p = Decimal('10.80') vote._result_ge_accepted = 0 vote.result_gl_eligible_voters = 101 vote.result_gl_votes_valid = 102 vote.result_gl_votes_total = 103 vote.result_gl_turnout = Decimal('10.40') vote.result_gl_yeas = 105 vote.result_gl_nays = 107 vote.result_gl_yeas_p = Decimal('10.80') vote._result_gl_accepted = 0 vote.result_gr_eligible_voters = 101 vote.result_gr_votes_valid = 102 vote.result_gr_votes_total = 103 vote.result_gr_turnout = Decimal('10.40') vote.result_gr_yeas = 105 vote.result_gr_nays = 107 vote.result_gr_yeas_p = Decimal('10.80') vote._result_gr_accepted = 0 vote.result_ju_eligible_voters = 101 vote.result_ju_votes_valid = 102 vote.result_ju_votes_total = 103 vote.result_ju_turnout = Decimal('10.40') vote.result_ju_yeas = 105 vote.result_ju_nays = 107 vote.result_ju_yeas_p = Decimal('10.80') vote._result_ju_accepted = 0 vote.result_lu_eligible_voters = 101 vote.result_lu_votes_valid = 102 vote.result_lu_votes_total = 103 vote.result_lu_turnout = Decimal('10.40') vote.result_lu_yeas = 105 vote.result_lu_nays = 107 vote.result_lu_yeas_p = Decimal('10.80') vote._result_lu_accepted = 0 vote.result_ne_eligible_voters = 101 vote.result_ne_votes_valid = 102 vote.result_ne_votes_total = 103 vote.result_ne_turnout = Decimal('10.40') vote.result_ne_yeas = 105 vote.result_ne_nays = 107 vote.result_ne_yeas_p = Decimal('10.80') vote._result_ne_accepted = 0 vote.result_nw_eligible_voters = 101 vote.result_nw_votes_valid = 102 vote.result_nw_votes_total = 103 vote.result_nw_turnout = Decimal('10.40') vote.result_nw_yeas = 105 vote.result_nw_nays = 107 vote.result_nw_yeas_p = Decimal('10.80') vote._result_nw_accepted = 0 vote.result_ow_eligible_voters = 101 vote.result_ow_votes_valid = 102 vote.result_ow_votes_total = 103 vote.result_ow_turnout = Decimal('10.40') vote.result_ow_yeas = 105 vote.result_ow_nays = 107 vote.result_ow_yeas_p = Decimal('10.80') vote._result_ow_accepted = 0 vote.result_sg_eligible_voters = 101 vote.result_sg_votes_valid = 102 vote.result_sg_votes_total = 103 vote.result_sg_turnout = Decimal('10.40') vote.result_sg_yeas = 105 vote.result_sg_nays = 107 vote.result_sg_yeas_p = Decimal('10.80') vote._result_sg_accepted = 0 vote.result_sh_eligible_voters = 101 vote.result_sh_votes_valid = 102 vote.result_sh_votes_total = 103 vote.result_sh_turnout = Decimal('10.40') vote.result_sh_yeas = 105 vote.result_sh_nays = 107 vote.result_sh_yeas_p = Decimal('10.80') vote._result_sh_accepted = 0 vote.result_so_eligible_voters = 101 vote.result_so_votes_valid = 102 vote.result_so_votes_total = 103 vote.result_so_turnout = Decimal('10.40') vote.result_so_yeas = 105 vote.result_so_nays = 107 vote.result_so_yeas_p = Decimal('10.80') vote._result_so_accepted = 0 vote.result_sz_eligible_voters = 101 vote.result_sz_votes_valid = 102 vote.result_sz_votes_total = 103 vote.result_sz_turnout = Decimal('10.40') vote.result_sz_yeas = 105 vote.result_sz_nays = 107 vote.result_sz_yeas_p = Decimal('10.80') vote._result_sz_accepted = 0 vote.result_tg_eligible_voters = 101 vote.result_tg_votes_valid = 102 vote.result_tg_votes_total = 103 vote.result_tg_turnout = Decimal('10.40') vote.result_tg_yeas = 105 vote.result_tg_nays = 107 vote.result_tg_yeas_p = Decimal('10.80') vote._result_tg_accepted = 0 vote.result_ti_eligible_voters = 101 vote.result_ti_votes_valid = 102 vote.result_ti_votes_total = 103 vote.result_ti_turnout = Decimal('10.40') vote.result_ti_yeas = 105 vote.result_ti_nays = 107 vote.result_ti_yeas_p = Decimal('10.80') vote._result_ti_accepted = 0 vote.result_ur_eligible_voters = 101 vote.result_ur_votes_valid = 102 vote.result_ur_votes_total = 103 vote.result_ur_turnout = Decimal('10.40') vote.result_ur_yeas = 105 vote.result_ur_nays = 107 vote.result_ur_yeas_p = Decimal('10.80') vote._result_ur_accepted = 0 vote.result_vd_eligible_voters = 101 vote.result_vd_votes_valid = 102 vote.result_vd_votes_total = 103 vote.result_vd_turnout = Decimal('10.40') vote.result_vd_yeas = 105 vote.result_vd_nays = 107 vote.result_vd_yeas_p = Decimal('10.80') vote._result_vd_accepted = 1 vote.result_vs_eligible_voters = 101 vote.result_vs_votes_valid = 102 vote.result_vs_votes_total = 103 vote.result_vs_turnout = Decimal('10.40') vote.result_vs_yeas = 105 vote.result_vs_nays = 107 vote.result_vs_yeas_p = Decimal('10.80') vote._result_vs_accepted = 1 vote.result_zg_eligible_voters = 101 vote.result_zg_votes_valid = 102 vote.result_zg_votes_total = 103 vote.result_zg_turnout = Decimal('10.40') vote.result_zg_yeas = 105 vote.result_zg_nays = 107 vote.result_zg_yeas_p = Decimal('10.80') vote._result_zg_accepted = 0 vote.result_zh_eligible_voters = 101 vote.result_zh_votes_valid = 102 vote.result_zh_votes_total = 103 vote.result_zh_turnout = Decimal('10.40') vote.result_zh_yeas = 105 vote.result_zh_nays = 107 vote.result_zh_yeas_p = Decimal('10.80') vote._department_in_charge = 1 vote.procedure_number = Decimal('24.557') vote._position_federal_council = 1 vote._position_parliament = 1 vote._position_national_council = 1 vote.position_national_council_yeas = 10 vote.position_national_council_nays = 20 vote._position_council_of_states = 1 vote.position_council_of_states_yeas = 30 vote.position_council_of_states_nays = 40 vote.duration_federal_assembly = 30 vote.duration_post_federal_assembly = 31 vote.duration_initative_collection = 32 vote.duration_initative_federal_council = 33 vote.duration_initative_total = 34 vote.duration_referendum_collection = 35 vote.duration_referendum_total = 36 vote.signatures_valid = 40 vote.signatures_invalid = 41 vote.recommendations = { 'fdp': 1, 'cvp': 1, 'sps': 1, 'svp': 1, 'lps': 2, 'ldu': 2, 'evp': 2, 'csp': 3, 'pda': 3, 'poch': 3, 'gps': 4, 'sd': 4, 'rep': 4, 'edu': 5, 'fps': 5, 'lega': 5, 'kvp': 66, 'glp': 66, 'bdp': None, 'mcg': 9999, 'sav': 1, 'eco': 2, 'sgv': 3, 'sbv-usp': 3, 'sgb': 3, 'travs': 3, 'vsa': 9999, 'vpod': 1, 'ssv': 1, 'gem': 1, 'kdk': 1, 'vdk': 1, 'endk': 1, 'fdk': 1, 'edk': 1, 'gdk': 1, 'ldk': 1, 'sodk': 1, 'kkjpd': 1, 'bpuk': 1, 'sbk': 1, 'acs': 1, 'tcs': 1, 'vcs': 1, 'voev': 1 } vote.recommendations_other_yes = "Pro Velo" vote.recommendations_other_no = None vote.recommendations_other_free = "Pro Natura, Greenpeace" vote.recommendations_divergent = { 'edu_vso': 1, 'fdp_ti': 1, 'fdp-fr_ch': 2, 'jcvp_ch': 2, } vote.national_council_election_year = 1990 vote.national_council_share_fdp = Decimal('01.10') vote.national_council_share_cvp = Decimal('02.10') vote.national_council_share_sp = Decimal('03.10') vote.national_council_share_svp = Decimal('04.10') vote.national_council_share_lps = Decimal('05.10') vote.national_council_share_ldu = Decimal('06.10') vote.national_council_share_evp = Decimal('07.10') vote.national_council_share_csp = Decimal('08.10') vote.national_council_share_pda = Decimal('09.10') vote.national_council_share_poch = Decimal('10.10') vote.national_council_share_gps = Decimal('11.10') vote.national_council_share_sd = Decimal('12.10') vote.national_council_share_rep = Decimal('13.10') vote.national_council_share_edu = Decimal('14.10') vote.national_council_share_fps = Decimal('15.10') vote.national_council_share_lega = Decimal('16.10') vote.national_council_share_kvp = Decimal('17.10') vote.national_council_share_glp = Decimal('18.10') vote.national_council_share_bdp = Decimal('19.10') vote.national_council_share_mcg = Decimal('20.20') vote.national_council_share_ubrige = Decimal('21.20') vote.national_council_share_yeas = Decimal('22.20') vote.national_council_share_nays = Decimal('23.20') vote.national_council_share_neutral = Decimal('24.20') vote.national_council_share_none = Decimal('25.20') vote.national_council_share_empty = Decimal('26.20') vote.national_council_share_free_vote = Decimal('27.20') vote.national_council_share_unknown = Decimal('28.20') vote.national_council_share_vague = Decimal('28.20') return vote
def test_column_mapper(): mapper = ColumnMapper() vote = SwissVote() mapper.set_value(vote, 'bfs_number', Decimal('100.1')) mapper.set_value(vote, 'date', date(2019, 1, 1)) mapper.set_value(vote, 'legislation_number', 10) mapper.set_value(vote, 'legislation_decade', NumericRange(1990, 1999)) mapper.set_value(vote, 'title_de', 'title de') mapper.set_value(vote, 'title_fr', 'title fr') mapper.set_value(vote, 'short_title_de', 'short title de') mapper.set_value(vote, 'short_title_fr', 'short title fr') mapper.set_value(vote, 'keyword', 'keyword') mapper.set_value(vote, '_legal_form', 4) mapper.set_value(vote, '!recommendations!fdp', 66) assert vote.bfs_number == Decimal('100.1') assert vote.date == date(2019, 1, 1) assert vote.legislation_number == 10 assert vote.legislation_decade == NumericRange(1990, 1999) assert vote.title_de == 'title de' assert vote.title_fr == 'title fr' assert vote.short_title_de == 'short title de' assert vote.short_title_fr == 'short title fr' assert vote.keyword == 'keyword' assert vote.legal_form == 'Direct counter-proposal' assert vote.get_recommendation('fdp') == 'Neutral' assert mapper.get_value(vote, 'bfs_number'), Decimal('100.1') assert mapper.get_value(vote, 'date') == date(2019, 1, 1) assert mapper.get_value(vote, 'legislation_number') == 10 assert mapper.get_value(vote, 'legislation_decade') == NumericRange(1990, 1999) assert mapper.get_value(vote, 'title_de') == 'title de' assert mapper.get_value(vote, 'title_fr') == 'title fr' assert mapper.get_value(vote, 'short_title_de') == 'short title de' assert mapper.get_value(vote, 'short_title_fr') == 'short title fr' assert mapper.get_value(vote, 'keyword') == 'keyword' assert mapper.get_value(vote, '_legal_form') == 4 assert mapper.get_value(vote, '!recommendations!fdp') == 66 assert list(mapper.get_values(vote))[:11] == [ Decimal('100.1'), date(2019, 1, 1), 10, NumericRange(1990, 1999, '[)'), 'short title de', 'short title fr', 'title de', 'title fr', 'keyword', None, 4 ] assert list(mapper.get_items(vote))[:11] == [ ('bfs_number', Decimal('100.1')), ('date', date(2019, 1, 1)), ('legislation_number', 10), ('legislation_decade', NumericRange(1990, 1999)), ('short_title_de', 'short title de'), ('short_title_fr', 'short title fr'), ('title_de', 'title de'), ('title_fr', 'title fr'), ('keyword', 'keyword'), ('votes_on_same_day', None), ('_legal_form', 4) ] assert list(mapper.items())[:11] == [ ('bfs_number', 'anr', 'NUMERIC(8, 2)', False, 8, 2), ('date', 'datum', 'DATE', False, None, None), ('legislation_number', 'legislatur', 'INTEGER', False, None, None), ('legislation_decade', 'legisjahr', 'INT4RANGE', False, None, None), ('short_title_de', 'titel_kurz_d', 'TEXT', False, None, None), ('short_title_fr', 'titel_kurz_f', 'TEXT', False, None, None), ('title_de', 'titel_off_d', 'TEXT', False, None, None), ('title_fr', 'titel_off_f', 'TEXT', False, None, None), ('keyword', 'stichwort', 'TEXT', True, None, None), ('votes_on_same_day', 'anzahl', 'INTEGER', False, None, None), ('_legal_form', 'rechtsform', 'INTEGER', False, None, None) ] assert list(mapper.items())[302] == ('!recommendations!sodk', 'p-sodk', 'INTEGER', True, None, None)
def test_vote_upload(swissvotes_app, attachments): names = attachments.keys() swissvotes_app.session().add( SwissVote( bfs_number=Decimal('100.1'), date=date(1990, 6, 2), legislation_number=4, legislation_decade=NumericRange(1990, 1994), title_de="Vote DE", title_fr="Vote FR", short_title_de="V D", short_title_fr="V F", keyword="Keyword", votes_on_same_day=2, _legal_form=3, initiator="Initiator", )) commit() client = Client(swissvotes_app) client.get('/locale/de_CH').follow() login = client.get('/auth/login') login.form['username'] = '******' login.form['password'] = '******' login.form.submit() manage = client.get('/').maybe_follow().click("Abstimmungen") manage = manage.click("Details").click("Anhänge verwalten") for name in names: manage.form[name] = Upload( f'{name}.png', # ignored attachments[name].reference.file.read(), 'image/png' # ignored ) manage = manage.form.submit().follow() assert "Anhänge aktualisiert" in manage for name in names: name = name.replace('_', '-') page = client.get(manage.pyquery(f'a.{name}')[0].attrib['href']) assert page.content_type in ( 'application/pdf', 'application/zip', 'application/vnd.ms-office', 'application/octet-stream', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) assert page.content_length assert page.body assert page.content_disposition.startswith('inline; filename=100.1') # Fallback client.get('/locale/en_US').follow() manage = client.get('/').maybe_follow().click("Votes") manage = manage.click("Details") for name in names: name = name.replace('_', '-') page = client.get(manage.pyquery(f'a.{name}')[0].attrib['href']) assert page.content_type in ( 'application/pdf', 'application/zip', 'application/vnd.ms-office', 'application/octet-stream', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) assert page.content_length assert page.body assert page.content_disposition.startswith('inline; filename=100.1')
def test_recommendation_order(): recommendations = SwissVote.codes('recommendation') assert list(recommendations.keys()) == [1, 2, 4, 5, 3, 66, 9999, None]
def test_reindex(session_manager, temporary_directory, redis_url): cfg_path = os.path.join(temporary_directory, 'onegov.yml') write_config(cfg_path, session_manager.dsn, temporary_directory, redis_url) result = run_command(cfg_path, 'govikon', ['add']) assert result.exit_code == 0 assert "Instance was created successfully" in result.output result = run_command(cfg_path, 'govikon', ['reindex']) assert result.exit_code == 0 # Add vote vote = SwissVote( id=1, bfs_number=Decimal(1), date=date(1990, 6, 2), legislation_number=4, legislation_decade=NumericRange(1990, 1994), title_de="Vote", title_fr="Vote", short_title_de="Vote", short_title_fr="Vote", votes_on_same_day=3, _legal_form=1, ) file = BytesIO() pdf = Pdf(file) pdf.init_report() pdf.p("Abstimmungstext") pdf.generate() file.seek(0) attachment = SwissVoteFile(id=random_token()) attachment.reference = as_fileintent(file, 'voting_text') vote.voting_text = attachment session_manager.ensure_schema_exists('onegov_swissvotes-govikon') session_manager.set_current_schema('onegov_swissvotes-govikon') session = session_manager.session() session.add(vote) session.flush() commit() result = run_command(cfg_path, 'govikon', ['reindex']) assert result.exit_code == 0 assert "Reindexed vote 1.00" in result.output vote = session.query(SwissVote).one() assert "abstimmungstex" in vote.searchable_text_de_CH with open(vote.voting_text.reference.file._file_path, 'wb') as file: pdf = Pdf(file) pdf.init_report() pdf.p("Realisation") pdf.generate() vote = session.query(SwissVote).one() assert "abstimmungstex" in vote.searchable_text_de_CH result = run_command(cfg_path, 'govikon', ['reindex']) assert result.exit_code == 0 assert "Reindexed vote 1.00" in result.output vote = session.query(SwissVote).one() assert "realisa" in vote.searchable_text_de_CH