Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions helios/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3172,6 +3172,14 @@ def test_voters_email_accessible_when_no_tally(self):
self.assertStatusCode(response, 200)
self.assertContains(response, 'Email')

def test_voters_email_accessible_with_no_voters(self):
"""An election with no voters yet used to 500 building the preview (IndexError)"""
self.voter.delete()
self.setup_login()
response = self.client.get(f'/helios/elections/{self.election.uuid}/voters/email')
self.assertStatusCode(response, 200)
self.assertContains(response, 'Email')
Comment on lines +3175 to +3181

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 New test breaks required Python indentation

The new test_voters_email_accessible_with_no_voters method uses four-space indentation, contrary to the repository's required two-space Python indentation.

Learn more

The repository's indentation rule requires two spaces throughout Python files. The new test uses four spaces per indentation level, matching the surrounding tests but not that explicit rule. Changing only this method to two spaces would leave its class inconsistent.

Example: The method declaration starts with four spaces and its statements start with eight, where the stated convention calls for two and four spaces.

Recommended fix: Reconcile the mandatory indentation rule with the existing test-file convention before applying the change consistently; do not reindent only the new method if it makes the class harder to read.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helios/tests.py uses 4-space indentation throughout, so the new test matches the class it sits in. Reindenting just this method would make the class inconsistent, and reindenting the whole file is out of scope for this fix. Leaving it as is.


Generated by Claude Code


def test_voters_email_preview_is_escaped(self):
"""The plain-text preview is shown escaped, placeholders and all"""
self.election.name = 'Board <b>election</b>'
Expand Down
5 changes: 4 additions & 1 deletion helios/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,9 @@ def voters_email(request, election):
election_url = get_election_url(election)
election_vote_url = get_election_govote_url(election)

# the preview shows how a voter logs in; the election may have no voters yet
sample_voter = voter or election.voter_set.first()

default_subject = render_text_template('email/%s_subject.txt' % template, {
'custom_subject': "<SUBJECT>"
})
Expand All @@ -1818,7 +1821,7 @@ def voters_email(request, election):
'name': '<VOTER_NAME>',
'voter_login_id': '<VOTER_LOGIN_ID>',
'voter_password': '<VOTER_PASSWORD>',
'voter_type' : election.voter_set.all()[0].voter_type,
'voter_type' : sample_voter.voter_type if sample_voter else None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Empty-election preview names a None account

With no voters, sample_voter supplies None to the voting email preview. The login instructions render “Log in with your None account,” misleading admins about the message.

Learn more

The preview renders an email template with a placeholder voter. Voting and simple emails interpolate that voter's authentication type in their login instructions. On an election without voters, the new fallback passes None, which renders as None rather than a usable login method. The actual email task later uses each real voter, so only the preview is incorrect. See render_text_template and the simple login instructions.

Example: A frozen open-registration election has zero voters. Its admin opens the default voting email preview and reads “Log in with your None account,” although a future recipient will see their actual login method.

Recommended fix: Give the empty-election preview a distinct generic login instruction in both voting email templates, or pass a valid representative auth system selected from election.voter_auth_systems(). Add a preview-content assertion to the empty-voter test.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed: with no voters, the vote/simple preview's {{voter.voter_type}} renders as "None", so the preview line reads "Log in with your None account." It only affects the admin's preview; the real emails use each voter's own type. Since this is marked optional, I haven't pushed for it. If wanted, the follow-up is to guard that line in vote_body.txt/simple_body.txt with {% if voter.voter_type %} and fall back to a generic "Log in to vote." line, plus an assertion in the empty-voter test.


Generated by Claude Code

'election' : election}
})

Expand Down
Loading