from unittest.mock import Mock, patch
from celery.result import EagerResult

from smoothschedule.identity.users.tasks import get_users_count


def test_user_count():
    """Test that get_users_count Celery task returns correct count."""
    # Arrange
    batch_size = 3

    # Mock User.objects.count() to return the batch size
    with patch('smoothschedule.identity.users.tasks.User') as mock_user_model:
        mock_user_model.objects.count.return_value = batch_size

        # Mock the delay method to return an EagerResult
        with patch.object(get_users_count, 'delay') as mock_delay:
            mock_result = Mock(spec=EagerResult)
            mock_result.result = batch_size
            mock_delay.return_value = mock_result

            # Act
            task_result = get_users_count.delay()

            # Assert
            assert isinstance(task_result, EagerResult)
            assert task_result.result == batch_size
