Skip to content

Commit

Permalink
Remove total of field 5 and 7 from form to be handled by quarantine t…
Browse files Browse the repository at this point in the history
…rigger
  • Loading branch information
JohnMwashuma committed Nov 14, 2024
1 parent 66f9442 commit 9139e6b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
22 changes: 0 additions & 22 deletions tally_ho/apps/tally/forms/recon_form.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from django import forms
from django.forms import ModelForm
from tally_ho.apps.tally.models import ReconciliationForm
from django.utils.translation import gettext_lazy as _


disable_copy_input = {
Expand Down Expand Up @@ -54,23 +52,3 @@ def __init__(self, *args, **kwargs):
class_str,
self.fields[field].widget.attrs.get('class'))
self.fields[field].widget.attrs['class'] = class_str
def clean(self):
"""Verify that the total of field number_cancelled_ballots and
field number_ballots_inside_box match the value of field
total_of_cancelled_ballots_and_ballots_inside_box
"""
if self.is_valid():
cleaned_data = super(ReconForm, self).clean()
number_cancelled_ballots =\
cleaned_data.get('number_cancelled_ballots')
number_ballots_inside_box =\
cleaned_data.get('number_ballots_inside_box')
total_of_cancelled_ballots_and_ballots_inside_box =\
cleaned_data.get(
'total_of_cancelled_ballots_and_ballots_inside_box')

if (number_cancelled_ballots + number_ballots_inside_box) !=\
total_of_cancelled_ballots_and_ballots_inside_box:
raise forms.ValidationError(
_('Total of fied 5 and 7 is incorrect'))
return cleaned_data
17 changes: 0 additions & 17 deletions tally_ho/apps/tally/tests/forms/test_recon_form.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from tally_ho.libs.tests.test_base import TestBase, create_result_form
from tally_ho.libs.permissions import groups
from tally_ho.apps.tally.forms.recon_form import ReconForm
from django.utils.translation import gettext_lazy as _

class ReconFormTest(TestBase):
def setUp(self):
Expand Down Expand Up @@ -47,22 +46,6 @@ def test_missing_required_fields(self):
self.assertFalse(form.is_valid())
self.assertIn('number_valid_votes', form.errors)

def test_custom_clean_validation(self):
"""Test that custom validation in clean method raises error with
incorrect totals."""
invalid_data = self.valid_data.copy()
invalid_data['total_of_cancelled_ballots_and_ballots_inside_box'] =\
999 # Invalid total
form = ReconForm(data=invalid_data)
self.assertFalse(form.is_valid())

# Convert the error messages to strings for comparison
error_messages = [str(err) for err in form.errors['__all__']]

# Check if the expected error message is in the error messages
self.assertIn(
str(_('Total of fied 5 and 7 is incorrect')), error_messages)

def test_disable_copy_paste_attributes(self):
"""Test that the copy/paste attributes are disabled on all
form fields."""
Expand Down

0 comments on commit 9139e6b

Please sign in to comment.