diff --git a/tally_ho/apps/tally/tests/views/data/test_ballot_list_view.py b/tally_ho/apps/tally/tests/views/data/test_ballot_list_view.py index 6cd6f43e2..27804f2c3 100644 --- a/tally_ho/apps/tally/tests/views/data/test_ballot_list_view.py +++ b/tally_ho/apps/tally/tests/views/data/test_ballot_list_view.py @@ -1,8 +1,12 @@ +import json from django.test import RequestFactory from tally_ho.apps.tally.views.data import ballot_list_view as views from tally_ho.libs.permissions import groups -from tally_ho.libs.tests.test_base import create_tally, TestBase +from tally_ho.libs.tests.fixtures.electrol_race_data import electrol_races +from tally_ho.libs.tests.test_base import ( + create_ballot, create_electrol_race, create_tally, TestBase +) class TestBallotListView(TestBase): @@ -22,3 +26,37 @@ def test_ballot_list_view(self): response = view(request, tally_id=tally.pk) self.assertContains(response, "Ballot List") self.assertContains(response, "New Ballot") + + def test_ballot_list_data_view(self): + """ + Test that ballot list data view returns correct data + """ + tally = create_tally() + tally.users.add(self.user) + electrol_race = create_electrol_race( + tally, + **electrol_races[0] + ) + ballot = create_ballot(tally, electrol_race=electrol_race) + view = views.BallotListDataView.as_view() + request = self.factory.post('/ballot-list-data') + request.user = self.user + response = view(request, tally_id=tally.pk) + action_link =\ + str( + 'Edit' + ) + mock_json_data =\ + [ + '1', + 'True', + 'Presidential', + 'ballot_number_presidential', + ballot.modified_date.strftime('%a, %d %b %Y %H:%M:%S %Z'), + str(ballot.available_for_release), + action_link] + self.assertEqual( + mock_json_data, + json.loads(response.content.decode())['data'][0]) diff --git a/tally_ho/apps/tally/tests/views/test_get_json_results.py b/tally_ho/apps/tally/tests/views/test_get_json_results.py index 3a05cd568..2967a64fd 100644 --- a/tally_ho/apps/tally/tests/views/test_get_json_results.py +++ b/tally_ho/apps/tally/tests/views/test_get_json_results.py @@ -21,11 +21,11 @@ def setUp(self): @patch('tally_ho.apps.tally.views.reports.administrative_areas_reports.' 'results_queryset') @patch('tally_ho.apps.tally.views.reports.administrative_areas_reports.' - 'total_valid_votes_with_recon_forms_per_electrol_race') - @patch('tally_ho.apps.tally.views.reports.administrative_areas_reports.' - 'total_valid_votes_with_no_recon_forms_per_electrol_race') + 'get_total_valid_votes_per_electrol_race') def test_get_results_success( - self, mock_no_recon, mock_with_recon, mock_results_queryset): + self, + mock_get_total_valid_votes_per_electrol_race, + mock_results_queryset): mock_results_queryset.return_value = [ { 'candidate_number': 1, @@ -47,8 +47,7 @@ def test_get_results_success( 'sub_con_name': 'Sub Con A', } ] - mock_with_recon.return_value = 50 - mock_no_recon.return_value = 50 + mock_get_total_valid_votes_per_electrol_race.return_value = 100 request_data = json.dumps({'tally_id': self.tally.id}) response = self.client.get(self.url, {'data': request_data}) diff --git a/tally_ho/apps/tally/views/data/ballot_list_view.py b/tally_ho/apps/tally/views/data/ballot_list_view.py index b3fdf1989..3c2b08d05 100644 --- a/tally_ho/apps/tally/views/data/ballot_list_view.py +++ b/tally_ho/apps/tally/views/data/ballot_list_view.py @@ -38,7 +38,7 @@ def render_column(self, row, column): def filter_queryset(self, qs): tally_id = self.kwargs.get('tally_id') - keyword = self.request.GET.get('search[value]', None) + keyword = self.request.POST.get('search[value]', None) if tally_id: qs = qs.filter(tally__id=tally_id) diff --git a/tally_ho/apps/tally/views/reports/administrative_areas_reports.py b/tally_ho/apps/tally/views/reports/administrative_areas_reports.py index b893abb8e..a06916d39 100644 --- a/tally_ho/apps/tally/views/reports/administrative_areas_reports.py +++ b/tally_ho/apps/tally/views/reports/administrative_areas_reports.py @@ -539,32 +539,17 @@ def stations_and_centers_queryset( return qs -def total_valid_votes_with_recon_forms_per_electrol_race( +def get_total_valid_votes_per_electrol_race( tally_id, - electral_race_id, - ): - total_valid_votes =\ - ReconciliationForm.objects.filter( - result_form__tally__id=tally_id, - active=True, - result_form__ballot__electrol_race__id=electral_race_id, - entry_version=EntryVersion.FINAL, - ).values('result_form__ballot__electrol_race__id').aggregate( - total_valid_votes=Sum('number_valid_votes') - ).get('total_valid_votes') - return total_valid_votes or 0 - -def total_valid_votes_with_no_recon_forms_per_electrol_race( - tally_id, - electral_race_id, - ): + electral_race_id +): total_valid_votes =\ Result.objects.filter( result_form__tally__id=tally_id, active=True, - result_form__reconciliationform__isnull=True, result_form__ballot__electrol_race__id=electral_race_id, entry_version=EntryVersion.FINAL, + result_form__form_state=FormState.ARCHIVED, ).values('result_form__ballot__electrol_race__id').aggregate( total_valid_votes=Sum('votes'), ).get('total_valid_votes') @@ -1739,11 +1724,7 @@ def create_ppt_export( valid_votes_per_electrol_race_id =\ { - id: total_valid_votes_with_recon_forms_per_electrol_race( - tally_id, - id - ) + - total_valid_votes_with_no_recon_forms_per_electrol_race( + id: get_total_valid_votes_per_electrol_race( tally_id, id ) for id in electrol_race_ids @@ -2179,11 +2160,7 @@ def get_results(request): list(set([result.get('electrol_race_id') for result in qs])) valid_votes_per_electrol_race_id =\ { - id: total_valid_votes_with_recon_forms_per_electrol_race( - tally_id, - id - ) + - total_valid_votes_with_no_recon_forms_per_electrol_race( + id: get_total_valid_votes_per_electrol_race( tally_id, id ) for id in electrol_race_ids @@ -3761,16 +3738,12 @@ def get_initial_queryset(self): electrol_race_ids =\ list(set([result.get('electrol_race_id') for result in qs])) valid_votes_per_electrol_race_id =\ - { - id: total_valid_votes_with_recon_forms_per_electrol_race( - tally_id, - id - ) + - total_valid_votes_with_no_recon_forms_per_electrol_race( - tally_id, - id - ) for id in electrol_race_ids - } + { + id: get_total_valid_votes_per_electrol_race( + tally_id, + id + ) for id in electrol_race_ids + } results =\ [{ 'candidate_name': result.get('candidate_name'),