28 lines
831 B
Python
28 lines
831 B
Python
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from core.tasks import get_disk_usage
|
|
|
|
|
|
def mock_notification_service():
|
|
class NotificationService:
|
|
def send(self, *args, **kwargs):
|
|
pass
|
|
return NotificationService
|
|
|
|
|
|
@pytest.mark.django_db
|
|
@pytest.mark.unit
|
|
class TestTask:
|
|
|
|
@patch('core.tasks.shutil.disk_usage', lambda _: (100, 99, 1))
|
|
@patch('core.tasks.NotificationService', mock_notification_service())
|
|
def test_get_disk_usage_no_disk_space(self, caplog):
|
|
get_disk_usage()
|
|
assert 'Send Notification "Free disk space is running out"' in caplog.text
|
|
|
|
@patch('core.tasks.shutil.disk_usage', lambda _: (100, 50, 50))
|
|
def test_get_disk_usage(self, caplog):
|
|
get_disk_usage()
|
|
assert 'Send Notification "Free disk space is running out"' not in caplog.text
|