73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
import pytest
|
|
from datetime import date
|
|
from plants.models import Plant, PruningLog
|
|
from plants.utils.pruning import pruning_status, months_before
|
|
|
|
|
|
def test_months_before_same_year():
|
|
d = date(2026, 5, 27)
|
|
assert months_before(d, 1) == date(2026, 4, 1)
|
|
assert months_before(d, 4) == date(2026, 1, 1)
|
|
|
|
|
|
def test_months_before_crosses_year():
|
|
d = date(2026, 5, 27)
|
|
assert months_before(d, 5) == date(2025, 12, 1)
|
|
assert months_before(d, 12) == date(2025, 5, 1)
|
|
|
|
|
|
def test_months_before_january():
|
|
d = date(2026, 1, 15)
|
|
assert months_before(d, 1) == date(2025, 12, 1)
|
|
assert months_before(d, 2) == date(2025, 11, 1)
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_no_schedule():
|
|
plant = Plant.objects.create(name='Fern', location='Office', pruning_months=[])
|
|
assert pruning_status(plant) == 'no_schedule'
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_due_this_month():
|
|
today = date(2026, 5, 15)
|
|
plant = Plant.objects.create(name='Rose', location='Garden', pruning_months=[5])
|
|
assert pruning_status(plant, today) == 'due_this_month'
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_due_this_month_already_logged():
|
|
today = date(2026, 5, 15)
|
|
plant = Plant.objects.create(name='Rose', location='Garden', pruning_months=[5])
|
|
PruningLog.objects.create(plant=plant, pruned_on=date(2026, 5, 1))
|
|
assert pruning_status(plant, today) == 'upcoming'
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_overdue_when_past_month_not_logged():
|
|
today = date(2026, 5, 15)
|
|
plant = Plant.objects.create(name='Rose', location='Garden', pruning_months=[3])
|
|
assert pruning_status(plant, today) == 'overdue'
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_not_overdue_when_past_month_logged():
|
|
today = date(2026, 5, 15)
|
|
plant = Plant.objects.create(name='Rose', location='Garden', pruning_months=[3])
|
|
PruningLog.objects.create(plant=plant, pruned_on=date(2026, 3, 10))
|
|
assert pruning_status(plant, today) == 'upcoming'
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_upcoming_future_month():
|
|
today = date(2026, 5, 15)
|
|
plant = Plant.objects.create(name='Rose', location='Garden', pruning_months=[8])
|
|
assert pruning_status(plant, today) == 'upcoming'
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_overdue_crosses_year_boundary():
|
|
# Pruning month December, checked in January
|
|
today = date(2026, 1, 10)
|
|
plant = Plant.objects.create(name='Apple', location='Garden', pruning_months=[12])
|
|
assert pruning_status(plant, today) == 'overdue'
|