25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
from django.test import TestCase
|
|
from django.contrib.auth import get_user_model
|
|
from modules.task_management.tasks import create_task_from_invoice
|
|
from modules.task_management.models import Task
|
|
|
|
|
|
class TaskCeleryTests(TestCase):
|
|
def setUp(self):
|
|
User = get_user_model()
|
|
# Create an admin user to be assigned the task
|
|
self.admin = User.objects.create_user(username="admin", email="admin@example.test", password="pass", is_staff=True)
|
|
|
|
def test_create_task_from_invoice_creates_task_for_large_amount(self):
|
|
invoice_data = {"amount": 1500, "invoice_number": "INV-100"}
|
|
# run the task function synchronously via .run (no bind)
|
|
create_task_from_invoice.run(invoice_data)
|
|
task = Task.objects.filter(title__icontains="INV-100").first()
|
|
assert task is not None
|
|
assert task.assigned_to == self.admin
|
|
|
|
def test_create_task_from_invoice_does_not_create_for_small_amount(self):
|
|
invoice_data = {"amount": 100, "invoice_number": "INV-101"}
|
|
create_task_from_invoice.run(invoice_data)
|
|
task = Task.objects.filter(title__icontains="INV-101").first()
|
|
assert task is None |