Skip to content

Commit b27b38f

Browse files
authored
Fix issue with exporting with no spoiled ballots (#756)
1 parent be31aa2 commit b27b38f

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/electionguard_gui/models/decryption_dto.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class DecryptionDto:
4949
can_join: Optional[bool]
5050
decryption_shares: list[Any]
5151
plaintext_tally: Optional[str]
52-
plaintext_spoiled_ballots: Optional[dict[str, str]]
52+
plaintext_spoiled_ballots: dict[str, str]
5353
lagrange_coefficients: Optional[str]
5454
ciphertext_tally: Optional[str]
5555
completed_at_utc: Optional[datetime]
@@ -69,7 +69,9 @@ def __init__(self, decryption: dict[str, Any]):
6969
self.guardians_joined = _get_list(decryption, "guardians_joined")
7070
self.decryption_shares = _get_list(decryption, "decryption_shares")
7171
self.plaintext_tally = decryption.get("plaintext_tally")
72-
self.plaintext_spoiled_ballots = decryption.get("plaintext_spoiled_ballots")
72+
self.plaintext_spoiled_ballots = _get_dict(
73+
decryption, "plaintext_spoiled_ballots"
74+
)
7375
self.lagrange_coefficients = decryption.get("lagrange_coefficients")
7476
self.ciphertext_tally = decryption.get("ciphertext_tally")
7577
self.completed_at_utc = decryption.get("completed_at")
@@ -132,8 +134,6 @@ def get_plaintext_tally(self) -> PlaintextTally:
132134
return from_raw(PlaintextTally, self.plaintext_tally)
133135

134136
def get_plaintext_spoiled_ballots(self) -> list[PlaintextTally]:
135-
if not self.plaintext_spoiled_ballots:
136-
raise ValueError("No plaintext spoiled ballots found")
137137
return [
138138
from_raw(PlaintextTally, tally)
139139
for tally in self.plaintext_spoiled_ballots.values()
@@ -157,6 +157,13 @@ def _get_list(decryption: dict[str, Any], name: str) -> list:
157157
return []
158158

159159

160+
def _get_dict(decryption: dict[str, Any], name: str) -> dict:
161+
value = decryption.get(name)
162+
if value:
163+
return dict(value)
164+
return {}
165+
166+
160167
def _get_int(decryption: dict[str, Any], name: str, default: int) -> int:
161168
value = decryption.get(name)
162169
if value:

tests/unit/electionguard_gui/test_decryption_dto.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
class TestDecryptionDto(BaseTestCase):
1010
"""Test the DecryptionDto class"""
1111

12+
def test_no_spoiled_ballots(self) -> None:
13+
# ARRANGE
14+
decryption_dto = DecryptionDto({})
15+
16+
# ACT
17+
spoiled_ballots = decryption_dto.get_plaintext_spoiled_ballots()
18+
19+
# ASSERT
20+
self.assertEqual(0, len(spoiled_ballots))
21+
1222
def test_get_status_with_no_guardians(self) -> None:
1323
# ARRANGE
1424
decryption_dto = DecryptionDto(

0 commit comments

Comments
 (0)