Skip to content

Commit

Permalink
Remove unnecessary duplicate error class
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMwashuma committed Aug 13, 2024
1 parent fb16771 commit e9aece0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions tally_ho/apps/tally/management/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,6 @@ def check_for_missing_columns(
raise Exception(error_message)
return None

class DuplicateFoundError(Exception):
"""Custom exception to be raised when duplicates are found."""
pass

def check_duplicates(csv_file_path: str, field: str) -> None:
"""
Checks for duplicates in a CSV file based on a specified field using
Expand Down Expand Up @@ -261,4 +257,4 @@ def check_duplicates(csv_file_path: str, field: str) -> None:
""").fetchall()

if len(result) > 0:
raise DuplicateFoundError(f"Duplicates found for field '{field}'")
raise Exception(f"Duplicates found for field '{field}'")
6 changes: 3 additions & 3 deletions tally_ho/libs/tests/utils/test_check_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.test import TestCase
from tally_ho.apps.tally.management.commands.utils import (
check_duplicates, DuplicateFoundError
check_duplicates
)

class CheckDuplicatesTestCase(TestCase):
Expand Down Expand Up @@ -31,7 +31,7 @@ def tearDown(self):

def test_duplicates_exist(self):
"""Test that duplicates are correctly identified."""
with self.assertRaises(DuplicateFoundError):
with self.assertRaises(Exception):
check_duplicates(
csv_file_path=self.csv_with_duplicates, field='barcode')

Expand All @@ -40,6 +40,6 @@ def test_no_duplicates(self):
try:
check_duplicates(
csv_file_path=self.csv_without_duplicates, field='barcode')
except DuplicateFoundError:
except Exception:
self.fail(
"check_duplicates() raised DuplicatesFoundError unexpectedly!")

0 comments on commit e9aece0

Please sign in to comment.