Skip to content

Commit

Permalink
fix ! test
Browse files Browse the repository at this point in the history
  • Loading branch information
vitali-yanushchyk-valor committed May 21, 2024
1 parent 5e13860 commit f54b458
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/faces/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import patch

from const import FILENAME, FILENAMES

from hope_dedup_engine.apps.faces.celery_tasks import deduplicate
Expand All @@ -21,7 +23,7 @@ def test_deduplicate_task_already_running(


def test_deduplicate_task_success(
mock_redis_client, mock_duplication_detector, mock_task_model, celery_app, celery_worker
dd, mock_redis_client, mock_duplication_detector, mock_task_model, celery_app, celery_worker
):
mock_set, mock_delete = mock_redis_client
mock_create, mock_task_instance = mock_task_model
Expand All @@ -30,7 +32,8 @@ def test_deduplicate_task_success(
mock_set.return_value = True # Lock is acquired
mock_find.return_value = set(FILENAMES[:2]) # Assuming the first two are duplicates based on mock data

task_result = deduplicate.apply(args=[FILENAME]).get()
with patch("hope_dedup_engine.apps.faces.celery_tasks.DuplicationDetector", return_value=dd):
task_result = deduplicate.apply(args=[FILENAME]).get()
assert task_result == set(FILENAMES[:2]) # Assuming the first two are duplicates based on mock data
mock_set.assert_called_once_with(f"Deduplicate_{FILENAME}", "true", nx=True, ex=3600)
mock_delete.assert_called_once_with(f"Deduplicate_{FILENAME}") # Lock is released
Expand All @@ -43,14 +46,15 @@ def test_deduplicate_task_success(


def test_deduplicate_task_exception_handling(
mock_redis_client, mock_task_model, mock_duplication_detector, celery_app, celery_worker
dd, mock_redis_client, mock_task_model, mock_duplication_detector, celery_app, celery_worker
):
mock_set, mock_delete = mock_redis_client
mock_create, mock_task_instance = mock_task_model
mock_find = mock_duplication_detector
mock_find.side_effect = Exception("Simulated task failure")

task = deduplicate.apply(args=[FILENAME])
with patch("hope_dedup_engine.apps.faces.celery_tasks.DuplicationDetector", return_value=dd):
task = deduplicate.apply(args=[FILENAME])

assert task.result is None # Task is not executed
mock_duplication_detector.assert_called_once() # DeduplicationDetector is called
Expand Down

0 comments on commit f54b458

Please sign in to comment.